C2 Compilation

All

Just-In-Time Java compilers: Client and Server

As described to the Hotspot Glossary

Highly optimizing bytecode compiler, also known as ‘opto’. Uses a “sea of nodes” SSA “ideal” IR, which lowers to a machine-specific IR of the same kind. Has a graph-coloring register allocator; colors all machine state, including local, global, and argument registers and stack. Optimizations include global value numbering, conditional constant type propagation, constant folding, global code motion, algebraic identities, method inlining (aggressive, optimistic, and/or multi-morphic), intrinsic replacement, loop transformations (unswitching, unrolling), array range check elimination.

With two compilers, plus interpreter.

To disable the C2 Compiler, you can use:

   -XX:TieredStopAtLevel=1.

(BTW, some people use TieredStopAtLevel=1 to limit the total time of optimization during compilation process, therefore reducing the overhead of the compiler and gain some speed) See [3]

Basically, this flag, disables intermediate compilation tiers (1, 2, 3), so that a method is either interpreted or compiled at the maximum optimization level (C2).

# $JAVA_HOME/bin/java -XX:+PrintFlagsFinal -version | grep CompileThreshold
intx CompileThreshold = 10000 {pd product}
uintx IncreaseFirstTierCompileThresholdAt = 50 {product}
intx Tier2CompileThreshold = 0 {product}
intx Tier3CompileThreshold = 2000 {product}
intx Tier4CompileThreshold = 15000 {product}
java version “1.8.0_191”
Java(TM) SE Runtime Environment (build 1.8.0_191-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.191-b12, mixed mode)

Issues

There are several issues that can happen, for example:

  1. A method get stuck on the C2 compilation

On this case, you will need to see which method is, using htop/top -H, then jstack -m or (pstack) and then see the line with C2Compiler::compile_method, so then you can use exclude the method of C2 using -XX:CompileCommand flag.

      2.CodeCache Full

On this case, the Code Cache is full, so you will need to increase the initial reserved space for code cache, and use codecache flushing, as below:

-XX:ReservedCodeCacheSize=384m
-XX:+UseCodeCacheFlushing

References

[1] https://phauer.com/2017/increase-jvm-development-productivity/

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s