First, let me explain my own test environment:
Ubuntu 12.04 x86-64,openjdk 7 64-bit Server VM (mixed mode)
MacOS 10.11,hotspot 7 64-bit Server VM (mixed mode)
1. How do I turn off JIT?
In general, JIT is turned on by default, so there is only one problem with how to turn it off.
When starting the JVM, simply increase the-xint or-Djava.compiler=NONE选项即可:
Java-xint Your_main_class_file_name
Java-Djava. Compiler Your_main_class_file_name
If you are booting from eclipse, you need to specify the above parameters in run configurations.
2. How do I view the JIT-generated assembly code?
Sometimes, we need to look at the JIT-generated assembly code to see how the JIT affects the execution of the code.
To complete this task, you need to install a support library, Hsdis, steps below.
Linux systems:
Download linux-hsdis-amd64.so or linux-hsdis-i386.so
Rename to hsdis-amd64.so or hsdis-i386.so
Copy to $java_home/jre/lib/amd64/directory
It's/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/on my machine.
OS x System:
Download Gnu-bsd-libhsdis-amd64.dylib or Gnu-bsd-libhsdis-i386.dylib
Rename to Hsdis-amd64.dylib or Hsdis-i386.dylib
Copy to $java_home/jre/lib/directory
It's/library/java/javavirtualmachines/jdk1.7.0_79.jdk/contents/home/jre/lib/hsdis-amd64.dylib on my machine.
After installing the support library, you only need to add the following two options when starting the JVM:
java-xx:+unlockdiagnosticvmoptions-xx:+printassembly Your_main_class_file_name
Here is a link to the detailed description, you can refer to:
https://wiki.openjdk.java.net/display/HotSpot/PrintAssembly
In addition, if you do not install a support library, you will get the following error when you specify the options above and start the JVM:
Java HotSpot (TM) 64-bit Server VM warning:printassembly is enabled; Turning on debugnonsafepoints to gain additional output
Could not load hsdis-amd64.dylib; Library not loadable; Printassembly is disabled
How do I control JIT behavior in the JVM?