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


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

 

 

 

你可能感兴趣的:(JVM,源码分析,JVM,源码分析)