Daily sentence

In your most struggling years, you should love someone who inspires you, not someone who enervates you.

The JIT just-in-time compiler specifies the use of C1 and C2

Parameter Settings

The HotSpot JVM has two JIT compilers built into it, the Client (C1) Compiler and the Server (C2) Compiler, which can be explicitly specified with the following instructions

-client Specifies that the Java VM runs in client mode and uses the C1 compiler.

Features: The C1 compiler heaps bytecode for simple and reliable optimizations that take less time. For faster compilation.

-server Specifies that the Java VM runs in server mode and uses the C2 compiler

Features: C2 for long time optimization, as well as radical optimization. But optimized code execution is more efficient.

C1 and C2 compilers have different optimization strategies

C1 mainly has methods of inlining, de-virtualization, and redundancy elimination

  • Method inlining: The reference function code is compiled to the reference point, which reduces stack frame generation, parameter passing, and jump process.

  • De-virtualization: Inline unique implementation classes

  • Redundancy elimination: During runtime, some code that will not run is folded out

The optimization of C2 is mainly at the global level, and escape analysis is the basis of optimization. There are several optimizations on C2 based on escape analysis –

  • Scalar substitution: Replaces an aggregate object’s property value with a scalar value

  • Stack allocation: For unescaped objects, allocate objects on the stack instead of the heap

  • Synchronization elimination: To clear a synchronization operation, usually synchronized

Hierarchical compilation strategy:

Program interpretation execution (without performance monitoring turned on) can trigger C1 compilation, which compiles bytecode to machine code, either for simple optimizations or with performance monitoring, and C2 compilation optimizes aggressively based on performance monitoring information.

When -server is explicitly specified, the hierarchical compilation strategy is enabled by default and the C1 and C2 compilers work together to perform compilation tasks.

In addition

After JDK10 Hotspot and joined a new instant compiler: Graal compiler, is currently in practice, can pass – XX: + UnlockExperimentalVMOptions, – XX: + UseJVMCICompiler to activate, just can use

AOT compiler jAOTC, which uses Graal compiler to convert the input Java class files into machine code and store them in the generation of dynamic shared libraries. AOT compilation As opposed to just-in-time compilation, which converts bytecode into machine code that can be run directly on hardware and deployed to a managed environment while a program is running, AOT compilation refers to the process of converting bytecode into machine code before the program is run.

benefits

Java virtual machine loads have been compiled into binary libraries that can be run directly. You don’t have to wait for the compiler to warm up, reducing the experience of a Java application running slowly for the first time

disadvantages

Breaking the Java “run everywhere compile once”, having to compile the distribution for each different hardware and OS, reducing the dynamic of the Java linking process, and loading code that is all known to the compiler; There are still optimizations to be made, and initially only Linux X64 Java Base is supported

How Java sets up how a program executes (compile execution and interpret execution)

Java program execution can be divided into interpreted execution and JIT just-in-time execution. By default, the two execution modes coexist, and the Java virtual machine can be explicitly specified to run with either the interpreter or the just-in-time compiler.

Parameter Settings:

  • -Xint executes programs in interpreter mode.

  • -Xcomp executes programs completely in just-in-time compiler mode. If just-in-time compilation fails, the parser steps in;

  • -Xmixed uses interpreter + just-in-time compiler mode to execute programs together.