environment
1. Machine model: MacBook Pro (Retina, 15-inch, Mid 2015)
2. CPU model: 2.5 GHz Intel Core i7
3. Operating system: macOS 10.12.5 (16F73)
4. Kernel version: Darwin 16.6.0
5.JDK version: java version "1.8.0_101" (important, the hsdis library may have to be recompiled for different jdk versions)
Related source code
1.jdk8 address: http://hg.openjdk.java.net/jdk8/jdk8
2. JITWatch source code: https://github.com/AdoptOpenJDK/jitwatch
Preliminary knowledge
1.hsdis: View JIT compiled assembly code, directory location: jdk8/hotspot/src/share/tools/hsdis
2. JVM related parameters:
-server indicates that the jvm is compiled with the C2 compiler
-Xcomp run in compiled mode, default is mix
-XX:+TraceClassLoading print class loading log
-XX:+PrintAssembly print assembly code, need hsdis support
-XX:LogFile=path/jit.log Input the jvm output log into jit.log
3. JITWatch open source analysis jvm assembly command tool
Install
1. Compile and install hsdis
1.cd hotspot/src/share/tools/hsdis #jdk8 in the source code
2. Download the binutils source code: (required to compile hsdis, jdk8 requires version 2.26 / jdk7 requires version 2.24)
wget http://ftp.heanet.ie/mirrors/gnu/binutils/binutils-2.26.tar.gz
tar -xvf ./binutils-2.26.tar.gz
3. All operations in this step are in the hsdis directory:
export CPP=/usr/bin/cpp #The environment variable CPP needs to be set first, otherwise an error will be reported when make
make BINUTILS=binutils-2.26 ARCH=amd64 #编译hsdis
There may be the following error under mac:
fatal error: sys/types.h: No such file or directory
solve:
xcode-select --install #Install according to the pop-up box prompts, note that you need to install xcode first here
After the installation is complete, execute make BINUTILS=binutils-2.26 ARCH=amd64 again
4. hsdis compilation is complete:
The corresponding lib directory is ./build/macosx-amd64/hsdis-amd64.dylib
Set environment variables:
sudo vi /etc/profile
LD_LIBRARY_PATH="/Volumes/home/Users/preideas/work/jit"
5. Verify that the hsdis library is in effect:
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -version > 1.txt
illustrate:
Here because the above command outputs too much, it is redirected to 1.txt
If you see the following output, the hsdis installation is successful:
2. JITWatch installation:
1. Download the source code:
git clone https://github.com/AdoptOpenJDK/jitwatch.git
2. Compile:
cd jitwatch
ant clean compile test run #If the maven environment is installed, you can also execute mvn clean compile test exec:java
3. Start: (still in the jitwatch directory)
sh launchUI.sh
Eclipse parameter configuration
1. On the java class to be run: Right click -->run as -->run configurations-->Arguments, fill in the following parameters;
-server -Xcomp -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:+LogCompilation -XX:+TraceClassLoading -XX:LogFile=/Volumes/home/Users/work/jit/jit.log
illustrate:
The path in the -XX:LogFile parameter is set according to your own machine
JITWatch usage
1. Import the jit.log generated in eclipse into jitwatch, the effect is as follows:
2. Click on the TriView in Figure 1, and the effect is as follows:
illustrate:
As can be seen from the above figure, the volatile key uses the lock instruction of the cpu
appendix
1. The mac has compiled the hsdis-amd64 library (see attachment)
2. The mac has compiled the hsdis-i386 library (see attachment)