A Look Inside JDK 24: How Ahead-of-Time Class Loading & Linking Works
Ahead-of-Time Class Loading & Linking is among the JEPs arriving in JDK 24. Its main aim is to speed up the startup of JVM applications.
Ahead-of-Time Class Loading & Linking is among the JEPs arriving in JDK 24. Its main aim is to speed up the startup of JVM applications as transparently as possible. Using this feature requires no code changes and no additional tools – you just turn it on by supplying a single option when launching the application. At its core, it builds on the groundwork established by Class Data Sharing and carries that feature further.
How the JVM starts up
To better see how AOT (Ahead-Of-Time) Class Loading & Linking operates, we first need to understand what happens when a JVM (Java Virtual Machine) application starts:

Once the JNI_CreateJavaVM function is called (which happens automatically when you run a simple command such as java -jar myapp.jar), the JVM starts by allocating memory for a range of internal structures, such as the heap, the method area, etc.. After that, it sets up components like the Garbage Collector and the JIT (Just-In-Time) compiler.
The JVM then starts loading classes with the Bootstrap Class Loader. This loader takes care of the classes essential to the Java environment, such as:
- Object,
- String,
- ClassLoader (the Bootstrap Class Loader is a special kind of class loader built into the core JVM and implemented in native code),
- Thread,
- and plenty more.
Once loaded, these classes are verified and prepared by the JVM. Depending on its strategy (lazy or eager), the JVM may also resolve symbolic references at this point. After verification and preparation, the classes get initialized and can be used.
Ahead-of-Time Class Loading & Linking at work
All in all, quite a lot has to happen before execution reaches our main method. That’s why applications on the JVM usually start considerably slower than ones written in languages such as C++ or Rust. To alleviate part of this problem, Class Data Sharing (CDS) was introduced a while ago. CDS, turned on by default since JDK 12, deals with the steps needed for subsequent class loading. It relies on an archive file that acts as a cache of parsed class bytecode, so on later startups the JVM can use classes from this archive without parsing them once more. The cache is shared across different applications and contains only core JDK classes. A variant called Application Class Data Sharing also exists, which extends the archive by caching classes specific to the application.
Class loading, however, is only one piece of JVM startup. JEP 483 goes further with AOT Class Loading & Linking. CDS does tackle some class loading problems, but in a different way: it stores classes in parsed form in its cache, so they can be loaded into memory quickly one by one, yet the linking step still has to happen afterward.
The new improvement, by contrast, collects all classes during a training run (explained below) and makes sure they are verified, prepared, and have their symbolic links resolved. In short, these classes are already linked and usable. As a result, the AOT cache holds considerably more data, all of which is loaded into memory in one go. This is because initializing any class requires resolving its whole class sub-graph – every superclass and interface has to be linked before a given class can be used.
The training run
The underlying assumption is that the data kept in the AOT cache stays the same between the training run and the production run. So what is a “training run”, and what form could it take? That depends on what we need. A production run itself could be a good training run, but integration tests may be an even better choice. This way, the AOT cache can be built as part of your project build. You do have to be careful, though, not to load classes that production won’t use – classes loaded purely for testing being the obvious example. The JEP documentation mentions that later updates may add extra filtering options to help with this.
The key thing to understand is that the closer the training run is to the production run, the bigger the payoff. That said, it’s no problem if some classes don’t make it into the AOT cache – the JVM will simply load them the usual way. In my view, this flexibility is one of the feature’s biggest advantages: it can bring substantial gains while preserving the JVM’s dynamic nature. It’s also simple to use, since the process requires no extra tools. To benefit from what this JEP provides, you go through the following three steps:
Step 1: Training run
java -XX:AOTMode=record -XX:AOTConfiguration=app.aotconf -jar my-app.jar
Step 2: Creating the cache
java -XX:AOTMode=create -XX:AOTConfiguration=app.aotconf -XX:AOTCache=app.aot -jar my-app.jar
Step 3: Running the application with the cache
java -XX:AOTCache=app.aot -jar my-app.jar
I won’t show concrete measurements of the gains this JEP brings, but more details are available on the official JEP 483 page. Keep in mind that how much you gain from this new feature depends heavily on the particular characteristics of your application.
Although this JEP has the Closed/Delivered status, some possible improvements remain for the future:
- a way to exclude classes that shouldn’t end up in the AOT cache,
- support for user-defined class loaders, since at present only classes loaded by the built-in class loaders can be included in the AOT cache.
Conclusion
JEP 483 is one more move towards solving the problem of slow JVM startup. I didn’t bring it up before, but this effort belongs to the broader Project Leyden, and it is the first of its JEPs to be completed. Two further JEPs are expected:
Moreover, as the JEP web page notes, class loading and linking may still see further improvements down the road.