# Printing Generated Assembly Code From The Hotspot JIT Compiler

DevFeed: [Printing Generated Assembly Code From The Hotspot JIT Compiler](<https://devfeed.tech/articles/printing-generated-assembly-code-from-the-hotspot-jit-compiler-13632.md>)

Original publisher: [Read original article](<https://mechanical-sympathy.blogspot.com/2013/06/printing-generated-assembly-code-from.html>)

Author: Martin Thompson (noreply@blogger.com)

Published: 2013-06-27T19:24:00Z

Content type: tutorial

Language: en

Sources: [Mechanical Sympathy](<https://devfeed.tech/sources/mechanical-sympathy.md>)

Topics: [Java](<https://devfeed.tech/topics/java.md>), [JIT](<https://devfeed.tech/topics/jit.md>), [Compiler](<https://devfeed.tech/topics/compiler.md>), [Assembly](<https://devfeed.tech/topics/assembly.md>), [Command-line interface](<https://devfeed.tech/topics/cli.md>), [Linux](<https://devfeed.tech/topics/linux.md>), [Concurrency](<https://devfeed.tech/topics/concurrency.md>)

Tags: [asm](<https://devfeed.tech/tags/asm.md>), [assembly](<https://devfeed.tech/tags/assembly.md>), [command-line](<https://devfeed.tech/tags/command-line.md>), [compiler](<https://devfeed.tech/tags/compiler.md>), [concurrent](<https://devfeed.tech/tags/concurrent.md>), [debugging](<https://devfeed.tech/tags/debugging.md>), [hotspot](<https://devfeed.tech/tags/hotspot.md>), [java](<https://devfeed.tech/tags/java.md>), [jit](<https://devfeed.tech/tags/jit.md>), [latency](<https://devfeed.tech/tags/latency.md>), [linux](<https://devfeed.tech/tags/linux.md>)

## AI overview

A tutorial on installing the Hotspot Disassembler Plugin and using Java command-line options to print generated assembly code for a targeted method. It uses a concurrent two-thread latency test involving volatile fields and explains how to inspect JIT-generated output.

## Source excerpt

Sometimes when profiling a Java application it is necessary to understand the assembly code generated by the Hotspot JIT compiler. This can be useful in determining what optimisation decisions have been made and how our code changes can affect the generated assembly code. It is also useful at times knowing what instructions are emitted when debugging a concurrent algorithm to ensure visibility rules have been applied as expected. I have found quite a few bugs in various JVMs this way. This blog illustrates how to install a Disassembler Plugin and provides command line options for targeting a particular method. Installation Previously it was necessary to obtain a debug build for printing the assembly code generated by the Hotspot JIT for the Oracle/SUN JVM. Since Java 7, it has been possible to print the generated assembly code if a Disassembler Plugin is installed in a standard Oracle Hotspot JVM. To install the plugin for 64-bit Linux follow the steps below: Download the appropriate binary, or build from source, from https://kenai.com/projects/base-hsdis/downloads On Linux rename linux-hsdis-amd64.so to libhsdis-amd64.so Copy the shared library to $JAVA_HOME/jre/lib/amd64/server You now have the plugin installed! Test Program To test the plugin we need some code that is both interesting to a programmer and executes sufficiently hot to be optimised by the JIT. Some details of when the JIT will optimise can be found here. The code below can be used to measure the average latency between two threads by reading and writing volatile fields. These volatile fields are interesting because they require associated hardware fences to honour the Java Memory Model. import static java.lang.System.out; public class InterThreadLatency { private static final int REPETITIONS = 100 * 1000 * 1000; private static volatile int ping = -1; private static volatile int pong = -1; public static void main(final String[] args) throws Exception { for (int i = 0; i < 5; i++) { final long duratio