Java application startup times would be improved by making classes of an application instantly available, under a proposal being floated in the OpenJDK community.
The JEP (JDK Enhancement Proposal) at openjdk.org, titled “Ahead-of-Time Class Loading & Linking,” would boost application startup speed by having these classes made available in a loaded and linked state when the HotSpot JVM starts. This would be achieved by monitoring the application during one run and storing loaded and linked forms of all classes in a cache for use in subsequent runs. This in turn would lay a foundation for future improvements to both startup and warmup times, the proposal states.
Created early last September, the proposal was updated August 4. The proposal currently does not list a specific time for the capability to arrive in Java.
Motivating the proposal is the desire to preserve the dynamism of the Java platform while reducing the cost of that dynamism, which must be paid every time an application starts, the proposal says. The highly dynamic Java platform has features such as dynamic class loading, dynamic linkage, and dynamic reflection, which give expressive power to developers. Java developers can, for example, write libraries that dynamically load and then link to plug-in components at run time, or assemble applications by composing libraries that dynamically link to other libraries. However, all that dynamism comes at a price, meaning the JVM does a lot of work during the startup of a typical server application, such as scanning JAR files on disk and loading parsed data into class objects. And it does this work on demand, lazily, just in time. As a result, a large server application may require seconds or even minutes to start up.
The key to improving startup time is to do some of this work ahead of time, rather than just in time. A specific goal of the proposal is improving startup time by exploiting the fact that most applications start up in roughly the same way every time they run. Other goals include:
- Not requiring any changes to the code applications, libraries or frameworks.
- Not requiring any change to how applications are started from the command line with the Java launcher, beyond the command-line options related directly to this feature.
- Not requiring the use of the
jlink
orjpackage
tools. - Laying a foundation for continued improvements to startup time and also to warmup time, i.e., the time needed for the HotSpot JVM to optimize an application’s code for peak performance.
The ahead-of-time proposal for class-loading and linking follows a previous proposal for ahead-of-time compilation for the JVM. That proposal is listed as being in draft status.