Sub topic 3
From Class Data Sharing to the AOT cache
This chapter assumes you know that the JVM loads classes from the classpath at startup and that you can run java and jar from a shell. It shows where the AOT cache comes from. The cache is an extension of Class Data Sharing (CDS), a feature the JDK has had for years.
The problem CDS was built to solve
Before a class can run, the JVM reads its .class bytes, parses them into internal metadata, verifies the bytecode, and links it. Every JVM process repeats this work for the same JDK classes. Class Data Sharing moves that work out of startup. The JVM parses classes once, writes the result to an archive file, and maps that file into memory on later runs. Mapped memory is also shared between JVM processes on the same machine, which is where the name comes from.
CDS has grown in steps. Each step archived more classes or made the archive easier to create.
What AppCDS added
The default archive that ships with the JDK covers only JDK classes. Your own classes and your libraries still went through the full load path. Application Class Data Sharing (AppCDS) fixed that by letting you archive application classes too.
JDK 13 made this simpler with dynamic archiving. You run the application once, and the JVM writes an archive of every class it loaded when it exits:
# Run once and dump the loaded classes at exit
java -XX:ArchiveClassesAtExit=app.jsa -cp app.jar Hello
# Later runs map the archive
java -XX:SharedArchiveFile=app.jsa -cp app.jar HelloThis already works well. The archive holds classes in parsed form, so the JVM skips reading and parsing class files. Two costs remain, though. The classes still have to be verified and linked at runtime. The JVM also still has to build certain objects, such as those behind lambdas and string concatenation, on every start.
What the AOT cache changes
The AOT cache (JEP 483, part of Project Leyden) keeps the CDS idea and goes further. It is built from a recorded training run, so it knows which classes the application actually used. It stores those classes already loaded and linked. It can also store some objects from the heap, so the JVM does not have to rebuild them.
The comparison below shows the difference in what each approach saves at startup.
| Work at startup | Without archive | CDS / AppCDS | AOT cache |
|---|---|---|---|
| Read and parse class files | Every run | Skipped | Skipped |
| Verify bytecode | Every run | Mostly skipped for archived classes | Done at build time |
| Link classes | Every run | Every run | Done at build time |
| Rebuild some startup objects | Every run | Every run | Can be loaded from the cache |
| JIT compile hot methods | Every run | Every run | Every run |
The last row matters. The AOT cache does not store compiled machine code. The JIT compiler still runs and still needs time to warm up. A later chapter covers method profiles, which help with that part.
The name can mislead you. This cache is not ahead-of-time compilation in the sense of GraalVM native image. The application still runs on a normal JVM, and your code is not restricted the way it is in a closed-world native build. The "AOT" refers to class loading and linking being done ahead of time.
How it relates to the CDS flags you may know
The AOT cache reuses the CDS machinery and replaces the workflow around it. In JDK 24 and later you use -XX:AOTMode, -XX:AOTConfiguration and -XX:AOTCache instead of -XX:ArchiveClassesAtExit and -XX:SharedArchiveFile. The older flags still work, so existing setups do not break. The next chapters cover the AOT flags in detail.
The main practical change is the training run. A dynamic CDS archive records what one run happened to load. The AOT workflow separates recording from creation, so the JVM can analyze the whole recorded run before it builds the cache.
Exercise
A team already uses a dynamic AppCDS archive on JDK 21. Name two startup costs that remain with that archive and that the AOT cache can remove, and one cost that the AOT cache does not remove.
Show answer
Remaining costs that the AOT cache removes: linking classes at runtime (and, mostly, verification), and rebuilding some startup objects on the heap. The AOT cache does not remove JIT compilation, because it does not store compiled code, so the application still warms up.