Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C2 CompilerThread in java

Tags:

java

jvm

jit

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 nid parameter mean? The first one nid=0x7d72 looks similar to java version, is it coincidence or not?
  3. Why condition address is absolute zero?
like image 907
AdamSkywalker Avatar asked Dec 29 '15 17:12

AdamSkywalker


People also ask

What is C2 Compilerthread?

The threads that the client Just-in-Time compiler uses are known as C1 compiler threads. And those that the server Just-in-Time compiler uses are called C2 Compiler threads. The C1 and C2 compiler threads streamline your application's performance. Often, these threads can consume a high CPU, creating problems.

What is Java compiler thread?

What is a Thread in Java? A thread in Java is the path followed when executing a program. All Java programs have at least one thread, known as the main thread, which is created by the Java Virtual Machine (JVM) at the program's start, when the main() method is invoked.

What are compiler threads?

C2 compiler threads are daemon threads (i.e. JVM threads). Code that your developers write are not the actual code that gets executed at run time. JIT (Just in Time) hotspot compiler in JVM, compiles (i.e. optimizes) the code that your developers have written for better performance.

What is tiered compilation?

Tiered compilation, introduced in Java SE 7, brings client startup speeds to the server VM. A server VM uses the interpreter to collect profiling information about methods that is fed into the compiler.


1 Answers

  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.
like image 77
apangin Avatar answered Nov 02 '22 18:11

apangin