Puzzled by a performance glitch? You might have to look at the generated code.

Examining generated code

The following HotSpot options (with an -XX: prefix on the command line) require OpenJDK 7 and an externally loadable disassembler plugin:

These flags are "diagnostic", meaning that they must be preceded by -XX:+UnlockDiagnosticVMOptions. On the command line, they must all be preceded by -XX:. They may also be placed in a flags file, .hotspotrc by default, or configurable as -XX:Flags=myhotspotrc.txt.

Plugin Implementations

The plugin is defined in the OpenJDK sources here:
http://hg.openjdk.java.net/jdk7/hotspot/hotspot/file/tip/src/share/tools/hsdis/

This version of the plugin requires the Gnu disassembler, which is available separately as part of the binutils project.

Look at the README for instructions on building. Pre-built binaries do not seem to be available (help... anyone?).

Independently of the OpenJDK sources, there is an implementation of the plugin in the base-hsdis project at Kenai. This is a from-scratch implementation which uses code from the Bastard project at SourceForge. The copyrights on this code are non-restrictive.

The Kenai project offers binary downloads.

Installing the Plugin

Once you succeed in building or downloading the hsdis DLL, you have to install it next to your libjvm.so, in the same folder. (Alternatively, you can put it anywhere on your LD_LIBRARY_PATH.) The DLL must be given the name that the JVM will be looking for. The core of the name will be hsdis-i386 for 32-bit Intel JVMs. Other names in use are hsdis-amd64, hsdis-sparc, and hsdis-sparcv9. A prefix and/or suffix will be required, according to system-dependent rules for naming DLLs.

$ JDK7=my/copy/of/jre1.7.0
$ cp -p hsdis/.libs/hsdis.so $JDK7/lib/i386/client/libhsdis-i386.so
$ cp -p hsdis/.libs/hsdis.so $JDK7/lib/i386/server/libhsdis-i386.so
$ XJAVA="$JDK7/bin/java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly"
$ $XJAVA -Xcomp -cp ~/Classes hello
$ $XJAVA -Xcomp -cp ~/Classes -XX:PrintAssemblyOptions=hsdis-print-bytes hello
$ $XJAVA -XX:-PrintAssembly -XX:+PrintStubCode
$ $XJAVA -XX:-PrintAssembly -XX:+PrintInterpreter
$ $XJAVA -XX:-PrintAssembly -XX:+PrintSignatureHandlers

Filtering Output

Individual methods may be printed:

Reading the compiler's mind

The -XX:+LogCompilation flag produces a low-level XML file about compiler and runtime decisions, which may be interesting to some. The -XX:+UnlockDiagnosticVMOptions must come first. The dump is to hotspot.log in the current directory; use -XX:LogFile=foo.log to change this.