emitrax
emitrax

Reputation: 394

What is C2Compiler::compile_method compiling?

I collected the Flamegraph of the execution of a Unit Test I've written in Java and 90% of the time is being spent in compiling the code C2Compiler::compile_method.

Is there a way to figure out what exactly is compiling? Which Methods?

Upvotes: 1

Views: 370

Answers (1)

Jorn Vernee
Jorn Vernee

Reputation: 33865

Yes, you can for instance use the -Xlog:jit+compilation=debug:file=comp_log_%p.txt VM flag to log compilations. This will write the log to the comp_log_[pid].txt file.

The output looks something like this:

[0.032s][debug][jit,compilation]    1       3       java.lang.String::charAt (25 bytes)
[0.032s][debug][jit,compilation]    2       3       java.lang.StringLatin1::charAt (15 bytes)
[0.033s][debug][jit,compilation]    7       3       java.lang.StringLatin1::hashCode (42 bytes)
[0.033s][debug][jit,compilation]    5       3       java.lang.Object::<init> (1 bytes)
[0.033s][debug][jit,compilation]   10       3       java.util.ImmutableCollections$SetN::probe (56 bytes)
[0.033s][debug][jit,compilation]    6       3       java.lang.String::hashCode (60 bytes)
[0.033s][debug][jit,compilation]   12       3       java.lang.StringLatin1::equals (36 bytes)
[0.034s][debug][jit,compilation]    9       3       java.lang.Math::floorMod (20 bytes)

The first number is the compilation id, the second number is the compilation level. Any compilation with a level of 4 is a C2 compilation, so that's the ones you want to look for.

Other symbols in this log mean the following:

  • % = an OSR (on stack replacement) compilation
  • s = a synchronized method
  • ! = compiled code has an exception handler
  • b = compilation task is blocking (for instance as a result of using -Xbatch)
  • n = a native method

Upvotes: 1

Related Questions