4 Compilation Optimization
This topic describes the various compiler options available in Oracle JRockit and HotSpot to optimize compilation.
Compiler Considerations
Unlike Oracle JRockit, HotSpot features a Java byte code interpreter in addition to two different Just In Time (JIT) compilers, client (also known as C1) and sever (also known as C2).
This section provides details about the complier that you can use.
HotSpot VM defaults to interpreting Java byte code. It compiles (JIT compilation) methods that are executed for a predetermined number of times. JIT compliers are either client or server compilers.
-
Client compiler: It compiles methods quickly but emits machine code that is less optimized than the server compiler. This complier is used for quick startup. Also, in this compiler, the smaller memory footprint is more important than steady-state performance.
-
Server compiler: The compiler often takes more time (and memory) to compile the same methods. However, it generates better optimized machine code than the code generated by the client compiler. It provides better runtime performance after the application reaches the steady state.
The tiered compilation enhances the server VM startup speed by using client compiler as the first tier. A server VM uses the interpreter to collect the profiling information about the methods that is fed into the compiler. In the tiered scheme, in addition to the interpreter, the client compiler generates compiled versions of methods that collect profiling information about themselves. As the compiled code is substantially faster than the interpreter, the program executes with greater performance during this profiling phase. Often, even a startup is faster because the final code produced by the server compiler is available during the early stages of application initialization. The tiered scheme can also achieve better peak performance than a regular server VM. This is because the faster profiling phase allows a longer period of profiling, which yields better optimization.
Tiered compilation is the default mode for the server VM. The 64-bit mode is supported. To enable tiered compilation manually, use the -XX:+TieredCompilation
flag. You can disable tiered compilation by using the -XX:-TieredCompilation
flag.
Oracle JRockit JVM compiles a Java method and generates the machine code for the first time it is invoked. This compiled code of frequently invoked methods is optimized in the background by an Optimizer thread. This code is different from the HotSpot where methods are interpreted first and compiled later, either by the client (fewer optimizations) or the server (more optimizations) compiler.
Compiler Control
Compiler Control provides an improved way to control the JVM compilers. The JVM compilation is done through compiler directive options. These options are method-specific and can be changed at run time. See Compiler Control.
Important HotSpot JIT Compiler Options
The following table lists some important Oracle JRockit and HotSpot compiler options:
Table 4-1 JIT Compiler Options
Oracle JRockit | HotSpot | Notes |
---|---|---|
|
As JIT compilation in HotSpot is considered analogous to optimization in Oracle JRockit (that is, both techniques are only used on methods that are determined by profiling to be hot), the HotSpot equivalent to Oracle JRockit's Like Oracle JRockit, HotSpot also offers ways to exclude methods from compilation or to disable specific optimizations on them. If there are any problems while optimizing the methods, then use The same compilation or optimization problems observed with the Oracle JRockit JVM for any specific methods are unlikely to happen with the HotSpot JVM. So, to begin with, it is best to remove these options while migrating to the HotSpot JVM. Equivalent HotSpot JVM options are:
|
Options |
|
There are no optimization threads in HotSpot JVM. The count of compiler threads that perform both the compilation and the optimizations can be set using:
|
Sets the number of compiler threads to use for compilation. By default, the number of threads is set to 2 for the server JVM and it scales to number of cores if tiered compilation is used. |
|
|
Sets the maximum code cache size (in bytes) for JIT-compiled code. This option is equivalent to |
None |
|
Enables the use of tiered compilation. This option is enabled by default from JDK 8 and later versions. Only the Java HotSpot Server VM supports this option. |