Skip to content

Instantly share code, notes, and snippets.

@zabetak
Created July 21, 2020 11:31
Show Gist options
  • Save zabetak/7b0a588a733012ada59011f10758c858 to your computer and use it in GitHub Desktop.
Save zabetak/7b0a588a733012ada59011f10758c858 to your computer and use it in GitHub Desktop.
Show assembly code generated by the JVM

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/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment