JEP 544: Ahead-of-Time Code Compilation
JEP 544 introduces an Ahead-of-Time (AOT) code compilation feature for the HotSpot Java Virtual Machine. This feature enhances startup and warmup times by compiling application code to native code during a training run, and storing the native code in an AOT cache for use in subsequent production runs. If the workload changes in production, the native code can be regenerated dynamically, allowing the application to maintain peak performance even as workloads change.
Importantly, this feature does not require any modifications to the application's code, libraries, or frameworks, nor does it necessitate any HotSpot configuration changes beyond enabling the use of the AOT cache. The HotSpot JVM processes Java applications through three phases: startup, warmup, and peak performance. During startup, the JVM loads, links, and initializes classes on demand, initially running the application and JDK library code via the bytecode interpreter, which is slow.
HotSpot profiles the application's behavior during startup, selecting frequently-invoked methods to compile to native code via the C1 compiler, resulting in modestly optimized native code. During warmup, the application settles into its workload, and HotSpot continues profiling the application, collecting richer profile information to compile the hottest methods to native code via the C2 compiler, which is much faster and highly optimized.
Gradually, JIT compilation catches up to the application's hot spots, and the application runs at peak performance as long as the hot spots remain unchanged. However, if the application's hot spots change, HotSpot can dynamically deoptimize and reoptimize the code as needed, transitioning between AOT-compiled and JIT-compiled code seamlessly.
This AOT feature aims to provide the best of both worlds, combining the speed of AOT compilation with the flexibility of JIT compilation.
Written by urgent.news from Lobsters's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.