As covered in the article “What the JIT!? Anatomy of the OpenJDK HotSpot VM”, HotSpot’s execution engine has a Just-in-Time (JIT) compiler. In order to improve startup times, the tiered compilation starts interpreting the code and then quickly moves to tiers 1, 2, or 3 where the methods are compiled at the client compilation level (but with different profiling information) and then finally moves to the server compilation level (for more information on this please refer the above article). But even with the improvements in the compilation levels, HotSpot still starts interpreting its bytecode and then moves on to JIT-ting it.
This September, a proposal was submitted to add Ahead-of-Time (AOT) compilation to HotSpot. AOT helps with improving the startup time by loading pre-compiled classes. This helps avoid running those classes in the interpretated mode or at a sub-optimized compilation level.
AOT compilation is not new to dynamic compilers; IBM’s J9 VM supports AOT, so does Excelsior JET and others. AOT has helped many dynamic compilers achieve better startup/warmup times by using (shared) libraries that have already been compiled to native code.
Similar to the JIT compiler, the AOT compilation proposed in the JEP will have a tiered and a non-tiered mode, the difference being in the collection of profiling information and JIT recompilation. As mentioned in the article, with tiered compilation, simple profiling information is gathered at tier 2 – the same goes for tiered AOT compiled code. And when the AOT invocation thresholds are crossed, those methods get recompiled by the client compiler at tier 3, so that full profiling information can be captured for the server recompilation that will happen at tier 4.
The proposal as laid by Valdimir Kozlov, lead of the HotSpot compiler team, mentions that for the first release, only java.base
module will be supported as tiered AOT, since the base module is well known and can help with thorough internal testing.
AOT brings about a new tool called ‘jaotc'
which uses Graal as the backend (to generate code). The Graal dynamic compiler integrates with the HotSpot VM and depends on the JVM Compiler Interface (JVMCI), hence the JDK (that supports Graal or AOT) should also support JVMCI. There are some JVMCI enabled builds available on the Oracle technetwork site.
According to the proposal, the jaotc
tool supports various flags:
--module <name> Module to compile
--output <file> Output file name
--compile-commands <file> Name of file with compile commands
--compile-for-tiered Generated profiling code for tiered compilation
--classpath <path> Specify where to find user class files
--threads <number> Number of compilation threads to be used
--ignore-errors Ignores all exceptions thrown during class loading
--exit-on-error Exit on compilation errors
--info Print information during compilation
--verbose Print verbose information
--debug Print debug information
--help Print this usage message
--version Version information
-J<flag> Pass <flag> directly to the runtime system
Also, the JVM product will have the following flags:
+/-UseAOT - Use AOT-compiled files
+/-PrintAOT - Print used AOT klasses and methods
AOTLibrary=<file> - Specify the AOT library file
A few notproduct/develop flags will also be made available for users:
PrintAOTStatistics - Print AOT statistics
UseAOTStrictLoading - Exit the VM if any of the AOT libraries has invalid config
The proposal also states that the logging of AOT runtime events will be integrated with the unified GC logging and the following tags will be supported:
aotclassfingerprint
aotclassload
aotclassresolve
No proposal is complete without listing the risks and assumptions made, and the risk with the AOT proposal is highlighted as follows:
It’s possible that the use of pre-compiled code could result in less-than-optimal code being used, resulting in a loss of performance. Performance testing shows that some applications benefit from AOT-compiled code while others clearly show regressions. Since the AOT feature is an opt-in feature, possible performance regressions with user applications are avoidable. If a user finds that an application starts up more slowly, or doesn't reach the expected peak performance, they can just rebuild a new JDK without AOT libraries.