The OpenJDK community has introduced JEP 544, a new enhancement to the HotSpot Java Virtual Machine that improves application startup and warmup times through ahead-of-time (AOT) compilation. This feature compiles Java application code into optimized native code during a training run and stores it in an AOT cache. Subsequent production runs can then load this precompiled code instantly, reducing the time needed to reach peak performance.
Traditionally, HotSpot uses just-in-time (JIT) compilation, which involves interpreting bytecode and compiling frequently used methods dynamically as the application runs. While this approach adapts to changing workloads and hardware, it incurs overhead during startup and warmup phases. JEP 544 addresses this by shifting some compilation work earlier, leveraging a training run to generate native code ahead of time.
The AOT cache created includes not only pre-linked classes and profiling data but also highly optimized native code for hot methods. During production, if the workload matches the training run, HotSpot can load this AOT code immediately. If workloads differ, HotSpot seamlessly falls back to JIT compilation, maintaining adaptability and peak performance.
This approach preserves the dynamic features of Java, such as dynamic class loading and reflection, which static compilation struggles to support. It also avoids requiring any changes to application code, libraries, or JVM configuration beyond enabling the AOT cache.
Initial benchmarks demonstrate significant improvements: startup times for several Java framework-based applications decreased by up to 80% with AOT code, and warmup times showed marked acceleration, reaching steady-state performance faster than with JIT alone.
The feature currently supports x64 and AArch64 architectures and integrates with existing HotSpot garbage collectors. It requires that training and production runs use compatible CPU architectures and garbage collectors to ensure correctness.
Developers can generate AOT caches using existing JVM options during training runs and deploy them in production without additional configuration. Diagnostic options allow monitoring AOT code usage and controlling its generation.
JEP 544 represents a balance between static and dynamic compilation benefits, improving Java application responsiveness while retaining runtime adaptability and portability. Future work includes refining compiler options, exploring broader architecture support, and optimizing cache size and loading times.