AdamSkywalker AdamSkywalker - 2 months ago 20
Java Question

C2 CompilerThread in java

I run jstack on a java process (oracle jdk1.7_072) and found these lines

"C2 CompilerThread1" daemon prio=10 tid=0x00007f1a8415d000 nid=0x7d72 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

"C2 CompilerThread0" daemon prio=10 tid=0x00007f1a8415a000 nid=0x7d71 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE

I know that C2 is a bytecode compiler. I have three questions:

  1. Why there are exact 2 compiler threads? Can it be more or less? If so, when? Does the compilation run in parallel?

  2. What does
    parameter mean? The first one
    looks similar to java version, is it coincidence or not?

  3. Why condition address is absolute zero?

Answer Source
  1. The number of compiler threads is determined automatically basing on JVM ergonomics. It may vary depending on number of available CPUs. The exact formula can be found here. The number of compiler threads can be manually overridden with -XX:CICompilerCount=N JVM option.
  2. nid (Native ID) is a unique ID of a thread given by OS. On Linux it is a number returned by gettid(). In your case TID = 0x7d72 = 32114.
  3. [0x0000000000000000] here is not related to waiting on condition. What is printed in brackets is a stack pointer of the last known Java stack frame aligned to a page size. Since compiler thread is not a real Java thread, it does not have last Java SP, hence zero is printed.