Scrivio Interview library
InternalsIntermediate7 min read · updated 12 November 2026

What does the AOT cache introduced in JDK 24 (JEP 483) store beyond classic CDS, and how do you create and use it on JDK 24 and JDK 25?

Classic CDS stores parsed class metadata, so the JVM can skip reading and parsing class files. The AOT cache from JEP 483 goes further: it stores the classes a training run actually used in an already loaded and linked state, so at startup they simply appear in their class loaders. On JDK 24 we record a configuration, create the cache from it, and run with -XX:AOTCache; on JDK 25, -XX:AOTCacheOutput does the first two steps at once, and the cache can also hold method profiles that help the JIT warm up sooner.

Why this question is asked

A Spring Boot service often spends seconds at startup loading and linking thousands of classes, and the work is the same on every start. Interviewers ask about the AOT cache because it is the newest, cheapest startup improvement in the JDK itself, and because using it well depends on knowing what is inside it and when the JVM refuses it. In this answer, we will recap what classic CDS already does, see what the AOT cache adds, create and use one on JDK 24 and JDK 25, look at the method profiles added in JDK 25, and finish with the rules that decide whether a cache is accepted.

1A Quick Recap of Class Loading and Classic CDS

When the JVM needs a class, it goes through several steps. It reads the bytes of the class file from a jar, parses them into internal metadata, loads the class into a class loader (so the class loader now owns it), verifies the bytecode, and links it, which means connecting its references to other classes, methods and fields. A typical Spring Boot application does this for 10,000 or more classes before it serves traffic.

Class Data Sharing, CDS for short, has been in the JDK for years. A CDS archive is a file that holds parsed and pre-verified class metadata. At startup the JVM maps the file into memory instead of reading and parsing the class files again. That saves real time, but notice what it does not save: the JVM still has to load each class into its class loader and link it, on every start, one class at a time as the program asks for them.

2What the AOT Cache Adds Beyond CDS

JEP 483, Ahead-of-Time Class Loading and Linking, shipped in JDK 24 as the first feature of Project Leyden. Its cache builds on the CDS file format but stores more: the classes that a training run actually used, in the state they reached during that run, already loaded by their class loaders and already linked. In production those classes are available immediately.

The training run tells the JVM which classes were loaded, by which loader, and how they were linked, so it can restore that state rather than replay it. The JEP reports startup improvements of around 40 percent for a Spring sample application, but the real gain for our services is something we measure, not assume.

Classic CDS compared with the AOT cache
Work at startupClassic CDSAOT cache (JDK 24+)
Read and parse class filesSkipped, metadata mapped from the archiveSkipped
Verify bytecodeMostly done ahead of timeDone ahead of time
Load into class loadersStill done at run timeRestored from the training run
Link classesStill done at run timeRestored from the training run
Method profiles for the JITNot storedStored on JDK 25 (JEP 515)
Each row is work the JVM repeats on every start unless an archive or cache already holds the result.

Everything else stays the same: the application still runs on the normal JVM with the normal JIT, garbage collectors and tools.

3Creating and Using the Cache on JDK 24

On JDK 24 the cache takes three steps. First a training run, where the application runs normally and the JVM records what it loads and links into a configuration file. Second an assembly step, where the JVM reads that configuration and writes the cache; the application does not run in this step. Third the production run, which points at the cache.

Java
# 1. Training run: the app runs and the JVM records what it loads and links
java -XX:AOTMode=record -XX:AOTConfiguration=app.aotconf \
-cp app.jar com.example.App # app.aotconf written when the JVM exits
# 2. Assembly: build the cache from the recording (the app does not run)
java -XX:AOTMode=create -XX:AOTConfiguration=app.aotconf \
-XX:AOTCache=app.aot -cp app.jar # app.aot written
# 3. Production: start with the cache
java -XX:AOTCache=app.aot -cp app.jar com.example.App # same JDK, same class path
Step throughBuilding an AOT cache on JDK 24
  1. Training runAOTMode=record writes app.aotconf
  2. AssemblyAOTMode=create reads app.aotconf, writes app.aot
  3. Production runAOTCache=app.aot
  4. Does the cache match this JVM and class path?
    YesClasses appear loaded and linkedNoCache ignored, normal startup

4 steps in order. Play them, or step through them one at a time.

On JDK 25 the first two steps can be one command.

Notice that the training run has to end, because the configuration is written when the JVM exits. For a server, we stop it after a warmup or use Spring Boot's -Dspring.context.exit=onRefresh, which starts the context and then exits. Notice also that the class path is the same in all three commands; the JVM checks that before it uses the cache.

4One Step on JDK 25 With AOTCacheOutput

Three commands and an extra configuration file were a common complaint, so JDK 25 added JEP 514, Ahead-of-Time Command-Line Ergonomics. The new option -XX:AOTCacheOutput tells the JVM to train and then create the cache in one invocation.

Text
# Train and create in one go (JDK 25)
java -XX:AOTCacheOutput=app.aot -cp app.jar com.example.App # app.aot written at exit
# Production, exactly as before
java -XX:AOTCache=app.aot -cp app.jar com.example.App

Behind the scenes the JVM still does two phases: when the training run exits, it starts a second JVM to assemble the cache. The three-step form still works on JDK 25, which is useful when we want to keep the recorded configuration for inspection.

5Method Profiles in the Cache on JDK 25

After startup, a JVM still runs slowly at first, because the JIT compiler, the part that turns hot bytecode into optimised machine code, waits until it has collected profiles: which methods are called often, which branches are taken, which types appear at a call site. That is the warmup period.

JEP 515, Ahead-of-Time Method Profiling, also in JDK 25, lets the training run store those method profiles in the AOT cache. In production the JIT starts with profiles already in hand, so it can compile hot methods earlier and the service reaches its peak speed sooner. The JIT still keeps profiling in production. This is why the training run should exercise the real code paths, ideally with a few hundred representative requests, rather than only starting and stopping the context.

6When the JVM Refuses the Cache

The cache describes one exact situation, so the JVM checks that the situation is the same before using it. It must be the same JDK build that created it, the class path must match the one used in training (the production class path may add entries at the end, but the trained part must be the same and the jar files unchanged), and some options that change how classes are laid out must be compatible. Some option combinations are restricted in early versions; check your version.

By default the JVM runs in a mode called auto: if the cache does not match, it starts normally without it, which is safe but quiet. Starting with -XX:AOTMode=on changes this: the JVM exits with an error if it cannot use the cache, which is what we want in a test or a smoke check. Logging with -Xlog:cds on JDK 24, and the aot log tag on newer releases (check your version), shows whether the cache was mapped.

Shell
java -XX:AOTCache=app.aot -XX:AOTMode=on -cp app.jar com.example.App
# fine when the cache matches; the JVM exits with an error if it does not
java -XX:AOTCache=app.aot -cp other.jar com.example.App
# auto mode: a warning in the log, then a normal (slower) startup

So a cache is a build artifact tied to one JDK and one set of jars, recreated whenever either changes.

7Follow-up questions

Can we use the AOT cache with a Spring Boot fat jar started with java -jar?

Not directly with the nested jars, because CDS and the AOT cache work with plain jar files on the class path, not jars inside a jar. Spring Boot has a tools mode for this: java -Djarmode=tools -jar app.jar extract writes the application jar and its libraries into a folder, and we train and run from that extracted layout. Spring Boot documents this flow for CDS and, in newer versions, for the AOT cache.

Is the AOT cache the same as GraalVM native image?

No. Native image compiles the whole application into a standalone executable under a closed-world assumption, so it starts in milliseconds but loses some dynamic behaviour. The AOT cache keeps the normal JVM, with full reflection, class loading, JIT and tooling, and only removes repeated startup work. Its gains are moderate, but it needs no code changes and no reachability metadata.

8Conclusion

In this answer, we saw that classic CDS saves the parsing of class files, while the AOT cache from JEP 483 also restores classes in the loaded and linked state recorded during training. JDK 24 needs record, create and run steps; JDK 25 merges the first two with AOTCacheOutput and stores method profiles so the JIT warms up sooner. The cache must match the JDK and class path it was trained with, so it belongs in the build.

What to say in the interviewAbout 80 seconds aloud

Open with

Classic CDS stores parsed and pre-verified class metadata, so the JVM skips reading and parsing class files, but it still loads and links every class at run time.

Then, if they want more

The AOT cache from JEP 483 in JDK 24 goes further: during a training run the JVM records which classes were actually loaded and how they were linked, and the cache stores them in that loaded and linked state, so at startup they just appear in their class loaders.

On JDK 24 it is three steps: run with AOTMode=record and an AOTConfiguration file, then AOTMode=create with that configuration and an AOTCache file, then run production with AOTCache.

JDK 25 adds AOTCacheOutput through JEP 514, which trains and creates the cache in one command, and JEP 515 stores method profiles from training so the JIT compiles hot methods earlier and warmup is shorter.

The cache is only used if the JDK build and the class path match the training run, and by default a mismatch silently falls back to a normal start, so in CI I would run with AOTMode=on to fail loudly. For Spring Boot I would extract the jar first and rebuild the cache with every build.

About this answer

Last updated
12 November 2026
Versions it names
Java 25, Java 24
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "What does the AOT cache introduced in JDK 24 (JEP 483) store beyond classic CDS, and how...": https://scrivio-interview-library.netlify.app/java/startup-and-footprint/5b259f4879/