如果只在jvm参数中加入-XX:+PrintAssembly参数,运行报错:
Improperly specified VM option 'PrintAssembly'
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
同时加上-XX:+UnlockDiagnosticVMOptions则可以打印编译信息,并且这个参数必须放在PrintAssembly前面才行。不过MacOSX上加了之后又遇到了新的错误:
VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Could not load hsdis-amd64.dylib; library not loadable; PrintAssembly is disabled
按照这里去下载hsdis-am64.dylib,放到你自己的目录下,如/xxx/yyy/zzz/,并chmod 设置当前用户可执行,然后在~/.bash_profile加上一行:
#这里只能设置到目录一级,不能设置到dylib文件
export LD_LIBRARY_PATH=/xxx/yyy/zzz/
注销重新登陆,重新运行程序,汇编信息就打印出来了。
enjoy it!