I ‘m trying to use -XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,*MyClass.myMethod command lines as described in this post.
It seems thats it’s available with open-jdk (https://wikis.oracle.com/display/HotSpotInternals/PrintAssembly).
How can I use those options (or similar equivalents) with oracle JDK7 and the JVM HotSpot?
These instructions apply to Linux (Ubuntu 10.04.4 LTS), but should be applicable for your OS. After downloading Oracle JDK 7u3 and appropriately setting your
JAVA_HOMEandPATHenvironment variables, execute the following to check available options:You should see the
UnlockDiagnosticVMOptions,CompileCommandandPrintAssemblyoptions are available. Using theCompileCommandoption will also enable thePrintAssemblyoption. However, you will need the HotSpot disassembler plugin forPrintAssemblyto work; without it, you might see something like the following:To get the HotSpot disassembler plugin, you will need to build it. Looking at the OpenJDK 7u2 source, the hsdis plugin readme says:
We have confirmed above that Oracle JDK 7u3 supports
PrintAssembly. I followed the hsdis plugin readme instructions, downloaded GNU binutils 2.22, placed it in the hsdisbuild/binutilsdirectory and ranmake. This eventually produced the following error:To correct this, I changed hsdis.c using the following patch:
Running
makewas then successful. Now just copy thehsdis-i386.soplugin in the hsdisbuilddirectory to the Oracle JDK 7u3jre/lib/i386directory.Now you can see the disassembled compiled code:
The test class I’ve used is: