PrintCompilation is a Java flag that gives us details on the compiling of the VirtualMachine as the application runs.

The first column is the timer in ms, that it took to run. In the screenshot above it took 62 ms to complete this application process.

The second column is the order that the line item was run.

The third column has a value from 0 to 4. This corresponds as an ENUM to what type of compilation has taken place.

  • 0: no compilation took place (code was interpreted)
  • 1 through 4: is a range of compilation complexity (4 being greatest)

The fourth and final column is the line item that was run.

Special Values

  • Some rows have an “n” value. This “n” value means “native.”
  • Sometimes a row will have an “s” value, which means it is a synchronized value.
  • An ! would mean that some exception handling was going on.
  • % would mean that the code has been natively compiled and is running in memory under the code cache.

Compilers C1 & C2

There are two compilers in Java. C1 handles Native compilation levels 1-3, while C2 handles native level 4 only (which stores native compiles into the code cache.)

The JVM determines the compilation level based on how often it is being run and how complex or time consuming it is – through profiling.

As there is a tradeoff in optimizing more complex code (higher native tier/levels), it only will do this with methods that are called more often, or have greater complexity.

In the example above, the same method call isPrime was first listed as a tier 3 method, but then was optimized as a tier 4 due to the JVM deciding it is being called more often and should therefore be more optimized.

In this case Tier 4 is natively compiled (as in Tier 3) but also put into the code cache, for even more optimal performance.

Outputting to a File

java -XX:+UnlockDiagnosticVMOptions -XX:+LogCompilation Main 5000

By passing in the UnlockDiagnosticVMOptions flag, we can then use the LogCompilation flag (which saves the compilation data to a file in the folder.)

Example output:

<nmethod compile_id='23' compiler='C1' level='3' entry='0x000000010856a120' size='1888' address='0x0000000108569f90' relocation_offset='296' insts_offset='400' stub_offset='1424' scopes_data_offset='1592' scopes_pcs_offset='1712' dependencies_offset='1856' nul_chk_table_offset='1864' oops_offset='1568' method='PrimeNumbers isPrime (Ljava/lang/Integer;)Ljava/lang/Boolean;' bytes='35' count='281' backedge_count='7927' iicount='281' stamp='0.063'/>


No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *