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.

Native Ahead-of-Time Compilation in Java

About The Author
- Mite Mitreski works on custom enterprise application development and consultancy with primary focus on Java and JVM-based solutions. Currently he works as an engineer in Klarna on simplifying the buying experience. In the past he was involved in activities surrounding development groups in Macedonia where he was JUG Leader. Mite has a great passion for free and open source software, open data formats, and the open web. He is involved in the JCP and various other open source initiatives. At the moment he i is a community editor at Voxxed where he helps bring awesome content.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>