Ahead of time compilation proposed for the JVM

An OpenJDK plan would improve Java Virtual Machine startup times with the ability to load Java applications and libraries already compiled to native code.

speed fast race car shutterstock 1168856884
Jamesboy Nuchaikong / Shutterstock

The Java Virtual Machine, renowned for the “write once, run anywhere” portability of Java programs, is being considered for ahead-of-time (AOT) compilation, which would enable faster startup and baseline execution of Java programs.

A recent OpenJDK draft proposal would enhance the JVM with the ability to load Java applications and libraries already compiled to native code. The proposal addresses performance issues that result from Java’s customizable, three-stage execution model, which involves many iterations of optimization and de-optimization. This dynamic process also means that code warmup can take a long time, causing performance issues in applications. These performance issues are sometimes critical and therefore unacceptable, the proposal states.

The Graal compiler, which was an available replacement for Java’s C2 compiler thread before Java 17, serves as a good example. Bootstrapping Graal impacted application performance negatively, because Graal had to be compiled itself before it could begin delivering its performance benefits.

Also impacting Java performance is the deoptimization that occurs when C2-compiled code hits an incorrect assumption, which can be costly. A solution to these issues would be to have a permanent AOT C1-compiled variant of the method replace the interpreter and C1 runtime compilation, so that on startup, execution begins with precompiled C1 code and then progresses to C2 compilation, bypassing some warmup steps as well as the interpreter.

With the Galahad project reintroducing potential AOT compilation for the JIT compiler that would be integrated into the JDK, it would be advantageous to consider AOT compilation for the JVM as well, the proposal states. This would give Galahad a ready platform for loading a precompiled compiler into the JVM.

Elaborating on success metrics, the proposal states that Java applications and libraries and pluggable JVM components written in Java such as JVMCI compilers should be able to be compiled ahead of time to native code, in either profiling or optimizing modes. These would be loaded in a matching JVM with high baseline performance, bypassing the interpreter. It is not a goal of the proposal to support AOT compilation for code that violates constraints placed by the Leyden project, which addresses slow startup, peak performance, and footprint issues in Java.

Copyright © 2023 IDG Communications, Inc.