A new official proposal to add ahead of time compilation for the JVM has been submitted as JEP 295. As the name suggest the idea is to add compilation to native code prior to launching the virtual machine.
The main goal of the proposal is to improve the start-up time of Java applications, with as little as possible impact on overall performance.
How would this work in practice ?
This would bring a new tool called
jaotc that will execute AOT compilation, for example :
jaotc --output libHelloWorld.so HelloWorld.class
and when running
java -XX:AOTLibrary=./libHelloWorld.so HelloWorld
This means that
jaotc will be a java static compiler which will produce native code for compiled java methods. The idea is to use Graal as the code-generating backend and libelf for generating .so AOT library.
While this is a huge deal it’s worth mentioning the limitations as well:
- Only 64bit Linux on AMD64 is supported meaning no ARM or Android
- Files must be run on identical hardware which is a downside of compilation anyway
- Still needs GC, only G1 and Parallel GC are supported
- For the initial release in JDK 9 the only supported module for AOT compilation will be java.base.
While you could be able to do this on the code written by yourself that will be experimental for now, but this is a big step in the performance direction. Beeing involved into various optimizations of customer project where we would “warm up” the JVM by using fake production like data this definitely sounds refreshing.
Worth noting is that this will also be an opt-in feature, meaning
-XX:-UseAOT can turn in on/off it there is an actual penalty by having an AOT.
There is a related video from 2015 discussing a similar commercial function in the JVM from The JVM Language Summit:
See also Gluon VM: Ahead of Time.