JVM源码系列:使用PrintAssembly打印java运行过程中的汇编

PrintAssembly是HotSpot JVM的一个诊断标志,允许我们获取JIT编译器/或者在解释过程中生成的汇编指令,通常可以通过分析执行的汇编指令可以帮助我们查找一些问题,也可以帮助我们分析和理解JVM 是如何解释和编译的。

如何安装

这些并不是JVM直接提供的,在JVM里需要使用插件的方式,Kenai项目则提供了这个插件
下载:https://kenai.com/projects/base-hsdis/downloads
找到对应的指令集,操作系统所对应的so文件下载,好像不支持windows

 

安装目录:你的libjvm.so同目录
$JAVA_PATH/jre/lib/cpu指令集/server/
例如: 
$JAVA_PATH/jre/lib/amd64/server/
文件名命名规则
1. 不同的指令集使用hsdis-指令集
hsdis-amd64, hsdis-sparc, hsdis-sparcv9
2. so文件改名为以lib为前缀的文件名, 这好像是JVM的bug(http://mail.openjdk.java.net/pipermail/hotspot-dev/2011-July/004284.html)
例如libhdis-amd64.so

 

常见的使用参数

 

 

 

+PrintAssembly print assembly code for bytecoded and native methods
+PrintNMethods print nmethods as they are generated
+PrintNativeNMethods print native method wrappers as they are generated
+PrintSignatureHandlers print native method signature handlers
+PrintAdapterHandlers print adapters (i2c, c2i) as they are generated
+PrintStubCode print stubs: deopt, uncommon trap, exception, safepoint, runtime support
+PrintInterpreter print interpreter code

 

使用这些参数需要首先打开参数
-XX:+UnlockDiagnosticVMOptions


常见的用法

 

-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly

 

 

PrintAssembly 打印JIT编译后的汇编
PrintInterpreter 打印解释的汇编

 

如何过滤输出

 

-XX:CompileCommand=print,*MyClass.myMethod prints assembly for just one method
-XX:CompileCommand=option,*MyClass.myMethod,PrintOptoAssembly (debug build only) produces the old print command output
-XX:CompileCommand=option,*MyClass.myMethod,PrintNMethods produces method dumps


你可以通过设置过滤,输出自己想要的方法的汇编

 

 

 

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值