General usage
As explained by other answers, you can run with the following JVM options:
-XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly
Filter on a specific method
You can also filter on a specific method with the following syntax:
-XX:+UnlockDiagnosticVMOptions -XX:CompileCommand=print,*MyClass.myMethod
Notes:
- you might need to put the second argument within quotes depending on OS etc.
- if the method gets inlined, you could miss some optimisations
How to: Install the required libraries on Windows
If you are running Windows, this page has instructions on how to build and install hsdis-amd64.dll and hsdis-i386.dll which are required to make it work. We copy below and extend the content of that page* for reference:
Where to get prebuilt binaries
You can download prebuilt binaries for Windows from the fcml project
- hsdis-amd64.dll
- hsdis-i386.dll
How to build hsdis-amd64.dll and hsdis-i386.dll on Windows
This version of the guide was prepared on Windows 8.1 64bit using 64-bit Cygwin and producing hsdis-amd64.dll
-
Install Cygwin. At the
Select Packagesscreen, add the following packages (by expanding theDevelcategory, then clicking once on theSkiplabel next to each package name):makemingw64-x86_64-gcc-core(only needed forhsdis-amd64.dll)mingw64-i686-gcc-core(only needed forhsdis-i386.dll)diffutils(inUtilscategory)
-
Run the Cygwin Terminal. This can be done using the Desktop or Start Menu icon created by the installer, and will create your Cygwin home directory (
C:\cygwin\home\<username>\orC:\cygwin64\home\<username>\by default). - Download the latest GNU binutils source package and extract its contents to your Cygwin home directory. At the time of writing, the latest package is
binutils-2.25.tar.bz2. This should result in a directory namedbinutils-2.25(or whatever the latest version is) in your Cygwin home directory. - Download the OpenJDK source by going to the JDK 8 Updates repository, selecting the tag corresponding to your installed JRE version, and clicking bz2. Extract the hsdis directory (found in
src\share\tools) to your Cygwin home directory. - In the Cygwin Terminal, enter
cd ~/hsdis. -
To build
hsdis-amd64.dll, entermake OS=Linux MINGW=x86_64-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.25To build
hsdis-i386.dll, entermake OS=Linux MINGW=i686-w64-mingw32 'AR=$(MINGW)-ar' BINUTILS=~/binutils-2.25In either case, replace
2.25with the binutils version you downloaded.OS=Linuxis necessary because, although Cygwin is a Linux-like environment, the hsdis makefile fails to recognize it as such. - The build will fail with messages
./chew: No such file or directoryandgcc: command not found. Edit<Cygwin home directory>\hsdis\build\Linux-amd64\bfd\Makefilein a text editor like Wordpad or Notepad++ to changeSUBDIRS = doc po(line 342, if using binutils 2.25) toSUBDIRS = po. Re-run the previous command.
The DLL can now be installed by copying it from hsdis\build\Linux-amd64 or hsdis\build\Linux-i586 to your JRE’s bin\server or bin\client directory. You can find all such directories on your system by searching for java.dll.
Bonus tip: if you prefer Intel ASM syntax to AT&T, specify -XX:PrintAssemblyOptions=intel alongside any other PrintAssembly options you use.
*page license is Creative Commons