JVM c1, c2 compiler thread - high CPU consumption?

5:39 am
July 14, 2022
cogent infotech
IT Training
Dallas, TX
Cogent University

JVM c1, c2 compiler thread � high CPU consumption?

Also known as a tiered compilation in Java Virtual Machines, the Java-platform development kit developers call their clients and servers internally with the name C1 and C2.  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. Here is a post to help prevent such a situation from arising.

Hot Code

Though a single application may be flooded with lines of code, only a few of these codes get implemented repeatedly. Marked as a hotspot, they are liable for your app's performance. When the app runs, the JVM uses the JIT compiler to streamline these hot codes. Very often, the code developed is not efficient, and this is why the JIT compiler chooses C1 and C2 compiler threads to optimise the code's performance.

Memory space used by the compiler for C1 and C2 compilation is known as Code Cache. 

C1 and C2 compiler threads

JIT compilers have two types: client and server.

Depending on the JIT compiler chosen, you should download and install a suitable JDK. For instance, if you have developed a desktop app, you need a client JIT compiler JDK. If you want to build a server app, choose Server JIT compiler JDK. 

Once the application begins, the client JIT compiler begins code compilation. However, the server JIT compiler observes the implementation process for some time. Depending on the knowledge it has, the compilation will start. Though the overall server JIT compilation takes time, it offers better results than the client JIT compiler.

The Java Development Kit works with client and server JIT compilers to streamline the app code. In the beginning, the client JIT compilers compile the code, and once sufficient data is acquired, the server JIT compiler starts functioning. The process is known as tiered compiling in Java Virtual Machines. The client and server JIT compiler are called C1 and C2 compiler threads, respectively. 

The size of the compiler thread depends on the CPUs available

For 1 CPU, you need one C1 and C2 thread each; for 32 CPUs, you need three C1 and seven C2 threads. And the number further rises with 64 CPUs; the count of C1 and C2 threads are four and eight, respectively.

Solution for big CPU consumption for C1 and C2 compiler thread

Often C1 and C2 use too much CPU. However, you don't need to worry about it as the solutions are available here.

  • Do not be alarmed if the C2 compiler is erratically great and not consistently high; it doesn't affect your app performance.
  • Run this command to your app '-XX:-TieredCompilation' to deactivate the JIT hotspot compiling. It will lower the CPU consumption but may impact the app performance too.
  • If the CPU consumption is significant because of the C2 compiler thread, switch it off. Run this argument '-XX: TieredStopAtLevel=3' to disable the C2 compiler, and only C1 will work.
  • Using the print argument, users can print the compilation process details. It can help them change the compilation procedure accordingly- '-XX:+PrintCompilation'.
  • The hotspot compiler or streamlined code is stockpiled in the memory of the JVM code buffer with a 240 MB default size. The argument XX:ReservedCodeCacheSize=N' can enhance the size. Add 512 in place of N to increase the cache size of the code and lower the compiler thread CPU consumption.
  • Use argument '-XX:CICompilerCount' to boost the C2 compiler count threads. Check out the count of C2 compiler threads; if you notice a lower number, you can add more. 


These solutions can help you reduce the high CPU consumption and boost the performance of your application. Use any of them that you find feasible for your problem to get the best results.

For more such information, check out Cogent Infotech.


This is some text inside of a div block.

What’s a Rich Text element?

The rich text element allows you to create and format headings, paragraphs, blockquotes, images, and video all in one place instead of having to add and format them individually. Just double-click and easily create content.

Static and dynamic content editing

A rich text element can be used with static or dynamic content. For static content, just drop it into any page and begin editing. For dynamic content, add a rich text field to any collection and then connect a rich text element to that field in the settings panel. Voila!

How to customize formatting for each rich text

Headings, paragraphs, blockquotes, figures, images, and figure captions can all be styled after a class is added to the rich text element using the "When inside of" nested selector system.

Related Resources