反汇编命令:

-XX:+UnlockDiagnosticVMOptions
-XX:+PrintAssembly -Xcomp
-XX:CompileCommand=print,*AtomicInteger.incrementAndGet

把这些参数设置到jvm启动参数,但个别首次执行会报错:

Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output

这是因为短少hsdis-amd64.dylib导致的,把hsdis-amd64.dylib放到$JAVA_PATH/jre/lib/server/目录下即可:

再次运行代码,即能够看到汇编代码输入:

对于CompileCommand参数,其格局是这样的:

-XX:CompileCommand=command,method[,option]

该参数用于定制编译需要,比方过滤某个办法不做JIT编译,或者打印某个办法汇编代码等。

command选项有如下:

exclude,跳过编译指定的办法

compileonly,只编译指定的办法

inline/dontinline,设置是否内联指定办法

print,打印生成的汇编代码

break,JVM以debug模式运行时,在办法编译开始处设置断点

quiet,不打印在此命令之后、通过-XX:CompileCommand指定的编译选项

log,记录指定办法的编译日志,若未指定,则记录所有办法的编译日志

其余命令,option,help

如上文截图中,-XX:CompileCommand=print,*AtomicInteger.incrementAndGet 即示意把AtomicInteger.incrementAndGet办法生成的汇编代码打印进去。


【我是tin,来自@看点代码再下班,如果感觉文章有用,欢送关注我呀!】