Bhupesh, Can you attach the thread report link to make it easy to understand the problem?
in my threadstack , when observing higher CPU utilization issue , i am seeing C2 CompilerThread0 is most CPU consuming thread but not able to relate it with application . how can i find which thread is in this application .
Hello Bhupesh!
Greetings.
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. This compilation/optimization is done by the C2 compilation threads.
Here are potential solutions to address the CPU spike caused by C2 compiler threads:
1. In your case, if your C2 compiler thread's CPU consumption is only intermittently high and not continuously high, and it doesn't hurt your application's performance, you can consider ignoring the problem.
2. -XX:-TieredCompilation: Pass this '-XX:-TieredCompilation' JVM argument to your application. This argument will disable the JIT hotspot compilation. Thus CPU consumption will go down. However as side-effect your application's performance can degrade
3. -XX:ReservedCodeCacheSize=N: Code that Hotspot JIT compiler compiles/optimizes are stored in the code cache area of the JVM memory. Default size of this code cache area is 240MB. You can increase it by passing '-XX:ReservedCodeCacheSize=N' to your application. Say if you want to make it as 512 MB, you can specify it like this: '-XX:ReservedCodeCacheSize=512m'. Increasing the code cache size has a potential to reduce the CPU consumption of the compiler threads.
4.-XX:CICompilerCount: You can consider increasing the C2 compiler threads by using the argument '-XX:CICompilerCount'. You can capture the thread dump and upload it to tools like https://fastthread.io, there you can see number of C2 compiler threads. If you see less number of C2 compiler threads and you have more CPU processors/cores, you can increase the C2 compiler thread count by specifying '-XX:CICompilerCount=8' argument.
5. -XX:+PrintCompilation: You can pass '-XX:+PrintCompilation' JVM argument to your application. It will print details about your application's compilation process. It will facilitate you to tune the compilation process further.
Here are two good articles related to JIT c2 compiler threads. You may consider reading further:
Working with the JIT Compiler - Java Performance, 2nd Edition [Book] (oreilly.com)
Analyzing a stuck HotSpot C2 compilation | by Vladimir Sitnikov | netcracker | Medium
Edit your Comment