This document outlines how you can print the assembly code generated by the JVM.
It relies on the -XX:+PrintAssembly
VM option available since java7 and requires also -XX:+UnlockDiagnosticVMOptions
.
java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly MyClassFile
In order to print assembly code you need a disassembler plugin such as FCML.
If you are running on Linux you may be able to install directly the required libraries (hsdis-amd64.so
)
via a package manager.
In Ubuntu you can type the following command:
sudo apt-get install libhsdis0-fcml
If you install the JDK your self then you may need to copy (or link) the libraries to the appropriate directory.
First you need to find where is the hsdis-amd64.so
library:
sudo find / -name hsdis-amd64.so
On my machine this outputs:
/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/hsdis-amd64.so
/usr/lib/jvm/java-9-openjdk-amd64/lib/amd64/hsdis-amd64.so
/usr/lib/jvm/java-7-openjdk-amd64/jre/lib/amd64/hsdis-amd64.so
Assuming that you installed your JDK in an alternative location (e.g., /opt/jdks/1.8.0_261
) then you need
to copy (move, link) the file to the respective location.
cp /usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/hsdis-amd64.so /opt/jdks/1.8.0_261/jre/lib/amd64/