1. 下载配置 Hsdis
之前是在网站 https://kenai.com/projects/base-hsdis/downloads 可以下载到,但是该网站现已关闭, 在github 上找到一个仓库提供
git clone https://github.com/liuzhengyang/hsdis
cd hsdis
tar -zxvf binutils-2.26.tar.gz
make BINUTILS=binutils-2.26 ARCH=amd64
复制 hsdis-amd64.so 文件到 {java_home}/jre/lib/amd64/server
sudo cp build/linux-amd64/hsdis-amd64.so /usr/lib/jvm/java-8-oracle/jre/lib/amd64/server
输入一下命令验证是否配置成功
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -version
输出如下所示,则表明配置成功
Java HotSpot(TM) 64-Bit Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
Loaded disassembler from /usr/lib/jvm/java-8-oracle/jre/lib/amd64/server/hsdis-amd64.so
Decoding compiled method 0x00007f3a7110a010:
Code:
[Disassembling for mach='i386:x86-64']
[Entry Point]
[Constants]
...
使用 Hsdis 执行代码,输出反汇编内容
javac A.java
java -server -XX:+UnlockDiagnosticVMOptions -XX:+TraceClassLoading -XX:+PrintAssembly -XX:+LogCompilation -XX:LogFile=live.log A # A是java文件类名, live.log 是输出的 log 文件
2. JITWatch
- 下载启动
git clone https://github.com/AdoptOpenJDK/jitwatch
cd jitwatch
./launchUI.sh
-
选择 open log,点击 start
图片.png -
点击 sanbox ,选择open,选择要分析的 java 文件,点击 run
图片.png
网友评论