Java applications will get faster startup times thanks to a formal proposal to include ahead-of-time compilation in the platform.
The draft Java Development Kit proposal, authored by Vladimir Kozlov, principal technical staff member at Oracle, is targeted for inclusion in Java 9, which is expected to be available next summer.
"We would love to see this make it into JDK 9, but that will of course depend on the outcome of the OpenJDK process for this JEP (JDK Enhancement Proposal)," said Georges Saab, vice president of software development in the Java platform group at Oracle, on Thursday. Ahead-of-time compilation has been a stated goal for Java 9 to address the issue of slow startup.
"JIT compilers are fast, but Java programs can become so large that it takes a long time for the JIT to warm up completely," Kozlov's proposal states. "Infrequently used Java methods might never be compiled at all, potentially incurring a performance penalty due to repeated interpreted invocations."
The proposal summary notes that Java classes would be compiled to native code prior to launching the virtual machine. The ultimate goal is to improve the startup time of small or large Java applications while having "at most" a limited impact on peak performance and minimizing changes to the user workflow.
Ahead-of-time compilation would be accomplished via a new tool, jaotc, while Graal technology, which make it feasible to write a dynamic compiler and language runtime interpreter in Java, is used as a code-generating back end. Usage of AOT-compiled code is transparent to users, but JVM options to control access to and storage of the code are provided, according to the proposal.
The plan, however, carries performance risks. "It is possible that the use of precompiled code could result in less-than-optimal code being used, resulting in a loss of performance," the proposal states. "Performance testing shows that some applications benefit from AOT-compiled code while others clearly show regressions." With AOT as an 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."
The project depends on the Java-Level JVM Compiler Interface, which enables a compiler written in Java to be used by the JVM as a dynamic Java compiler. It also depends on Graal-core to be part of the JDK. Java 9 had been slated to arrive next March, but a four-month delay has been proposed.