Search code examples
javajvmjvm-hotspot

PrintAssembly option on JVM Hotspot is enabled but not showing any assembly trace


I am working on intel i386, Ubuntu 14. The OpenJDK version info shown by $java -version is

java version "1.7.0_65"
OpenJDK Runtime Environment (IcedTea 2.5.2) (7u65-2.5.2-3~14.04)
OpenJDK Server VM (build 24.65-b04, mixed mode)

As mentioned here I have copied the required binary hsdis-i386.so to the following locations

/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/server

and

/usr/lib/jvm/java-7-openjdk-i386/jre/lib/i386/client

Then I followed this blog to workaround and try to get an assembly code of a java program. I used below command to test a sample java program MyClass.java

java -XX:+UnlockDiagnosticVMOptions -XX:+PrintAssembly -XX:PrintAssemblyOptions=hsdis-print-bytes -XX:CompileCommand=print,MyClass MyClass

The message I got on the console is

OpenJDK Server VM warning: PrintAssembly is enabled; turning on DebugNonSafepoints to gain additional output
CompilerOracle: unrecognized line "print Test"
c = 50

Where MyClass.java is

public class MyClass{
  public static void main(String [] args){
    int a = 10;
    int b = 40;
    int c = a + b;
    System.out.println("c = "+c);
  }
}

As per my understanding and looking at above message, jvm is able to locate hsdis-i386.so and so its saying PrintAssembly is enabled, however it is not showing any assembly code out there. Please help me point out the mistake I am doing.


Solution

  • In the JVM, hot methods are compiled after they have been run many times. e.g. with a -XX:CompileThreshold=10000 which is the default, a method will be compiled to native code in the background some time after it has been called 10000 times.

    Your code is not run enough to get compiled. I suggest you use -XX:+PrintCompilation to see which methods are being compiled.

    When I run the following, the output is

    $ java -version
    java version "1.8.0_25"
    Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
    Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)
    

    but when I add -XX:+PrintCompliation I see the one method which gets compiled.

    $ java -XX:+PrintCompilation -version
    java version "1.8.0_25"
    Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
         43    1       3       java.lang.String::equals (81 bytes)
    Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)