Quick revision
The short answer
A JIT compiles at run time with real profiles, so it can speculate aggressively and supports dynamic class loading, which gives high peak performance but slow startup and warmup. Full AOT compilation, as in native image, gives instant startup but needs a closed world, so it loses some dynamic behaviour and profile-driven optimisation. Project Leyden keeps the JIT and full Java semantics and instead shifts work earlier through a training run, storing it in an AOT cache: classes loaded and linked in JDK 24, method profiles and simpler cache creation in JDK 25. Because each step works with existing applications, organisations can adopt it gradually, and the strategy is to invest in training runs and image pipelines now.
What to remember
In this answer, we saw that a JIT gives high peak performance from run-time profiles and full dynamic Java, at the cost of slow startup and warmup, while full AOT compilation gives fast startup but needs a closed world and loses profile-driven optimisation. Project Leyden keeps the JIT and moves work earlier through a training run stored in an AOT cache, loaded and linked classes in JDK 24 and method profiles in JDK 25, compatible with existing applications. The strategy is to invest in training runs and image pipelines now, since later steps build on the same workflow.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
A JIT compiles at run time with real profiles, so it can speculate aggressively and supports dynamic class loading, which gives high peak performance but slow startup and warmup. Full AOT compilation, as in native image, gives instant startup but needs a closed world, so it loses some dynamic behaviour and profile-driven optimisation. Project Leyden keeps the JIT and full Java semantics and instead shifts work earlier through a training run, storing it in an AOT cache: classes loaded and linked in JDK 24, method profiles and simpler cache creation in JDK 25. Because each step works with existing applications, organisations can adopt it gradually, and the strategy is to invest in training runs and image pipelines now.
Why this question is asked
For most of Java's history, every JVM process started from nothing and rediscovered, in its first minutes, everything the previous process had already learned. In the age of autoscaling and serverless, that cost became a strategic problem, and competing answers appeared. Interviewers ask this at a senior level to see whether we understand the fundamental trade-off well enough to judge where the platform is heading and what to invest in. In this answer, we will compare JIT and AOT compilation, look at what the closed world costs, follow Leyden's approach step by step, and turn that into an investment strategy.
1A Quick Recap: JIT and AOT Compilation
A JIT compiler, just-in-time, compiles code while the program runs. HotSpot starts in the interpreter, profiles the code, and compiles hot methods with C1 and then C2 using those profiles. Ahead-of-time compilation, AOT, compiles the program to machine code before it runs, as C and Go compilers do, and as GraalVM native image does for Java.
Both produce machine code; they differ in when they compile and therefore in what they know. The JIT knows what the program actually does in this run. The AOT compiler knows only what it can prove from the code before it runs.
2What the JIT Buys and What It Costs
Because the JIT sees real behaviour, it can speculate. It inlines the receiver types that actually appear, drops branches that are never taken, and relies on the classes currently loaded, with deoptimisation as a safety net when a guess turns out wrong. Java's dynamic features, loading classes at runtime, reflection, proxies, bytecode generated by frameworks, all fit naturally, because compilation happens after they have done their work. The result is very high peak performance.
The cost is paid at every start: class loading and linking, interpreting, profiling and compiling, all repeated per process. For a long-running server that is a few minutes out of days. For a function that runs for seconds, or a fleet that scales up and down every hour, it dominates.
3What Full AOT Buys and What It Costs
Native image compiles the application and the parts of the JDK it uses into a standalone executable. To do that, it performs a closed-world analysis: it assumes that all code that will ever run is known at build time. Startup becomes very fast, often tens of milliseconds, and memory use is low, because there is nothing left to load, profile or compile.
The closed world has a price. Dynamic class loading is not supported, and reflection, proxies and resources must be declared in configuration or discovered by the build; frameworks such as Spring Boot provide AOT processing to generate this, but some libraries and patterns do not fit. Without run-time profiles, the compiled code cannot speculate on actual behaviour, so peak throughput is often lower than C2's, unless a profile-guided build is used. Builds are slower, and debugging and monitoring tools differ from the standard JVM's.
| Aspect | JIT only | Native image | Leyden AOT cache |
|---|---|---|---|
| Startup and warmup | slow | very fast | faster, improving per release |
| Peak performance | high, profile-driven | often lower without PGO | high, JIT kept |
| Java semantics | full, dynamic | closed world | full, dynamic |
| Adoption effort | none | build changes, config | training run, cache file |
4Leyden's Choice: Shift and Store the Work
Project Leyden asked a different question: instead of removing the JIT, which work done at startup could be done once, ahead of time, and stored? The mechanism is a training run. We run the application with representative work, and the JVM records what it did into an AOT cache. Later runs start from that cache.
The work moves in steps. JDK 24 added ahead-of-time class loading and linking (JEP 483): the cache stores classes already parsed, loaded and linked, so production runs skip that work. JDK 25 added method profiling to the cache (JEP 515), so the JIT starts with profiles from the training run and can compile hot methods sooner, and it simplified cache creation to a single option (JEP 514). Later steps under discussion include storing compiled code itself; check the current OpenJDK status before planning around specific releases.
Notice what stays the same. The JVM still has a JIT, still deoptimises when behaviour changes, and still supports dynamic class loading: if the program does something the training run did not, it simply does it the normal way. That is why Leyden calls this shifting computation rather than changing the language's rules.
5Why Gradual Adoption Matters
Each Leyden step is compatible with existing applications: no code changes, no closed-world configuration, and a mismatch simply means the cache is not used. That changes the economics for a large organisation. Instead of a migration project per service, as native image often requires, the platform team can add the training run to the image pipeline once and every service benefits, with each new JDK release adding more stored work through the same mechanism.
- Representative warmup workload per servicerecorded, sanitised traffic
- Image pipeline runs the training runwrites the AOT cache
- Cache shipped in the imagesame JDK and JARs as production
- Measure startup and time to steady statecompare with no cache
- Each new JDK releasemore work stored by the same pipeline
5 steps in order. Play them, or step through them one at a time.
6The Strategy Implication
The practical conclusion is to invest now in the parts that every later step reuses: representative training workloads per service, image pipelines that run them and package the cache, and metrics for startup and time to steady state. These pay off immediately on JDK 25 and grow in value with each release. Native image remains a tool for specific workloads, not the default direction for the fleet.
7Follow-up questions
Which workloads would still justify native image instead?
Workloads where startup in milliseconds and a small memory footprint matter more than peak throughput, and that fit a closed world: command-line tools, short-lived serverless functions, scale-to-zero services that must answer the first request instantly, and small sidecars packed densely. For long-running, throughput-heavy services, the JIT's peak performance and the AOT cache's compatibility usually win.
What happens if the training run is not representative?
The cache still helps with class loading for whatever the training run touched, and the JVM handles anything else normally. But stored profiles that do not match production can lead the JIT to optimise for the wrong behaviour at first, causing deoptimisation later. So the training workload deserves the same care as a warmup workload.
Is Leyden the same as the old CDS?
It builds on CDS. CDS, Class Data Sharing, stored parsed class metadata in an archive and has existed for many years. The AOT cache extends that archive to store more of the startup work, loaded and linked classes and profiles, and is created from a training run of the application.
8Conclusion
In this answer, we saw that a JIT gives high peak performance from run-time profiles and full dynamic Java, at the cost of slow startup and warmup, while full AOT compilation gives fast startup but needs a closed world and loses profile-driven optimisation. Project Leyden keeps the JIT and moves work earlier through a training run stored in an AOT cache, loaded and linked classes in JDK 24 and method profiles in JDK 25, compatible with existing applications. The strategy is to invest in training runs and image pipelines now, since later steps build on the same workflow.
Open with
The trade-off is about when we compile and what we know at that moment. A JIT compiles at run time, so it uses real profiles: it inlines the types it actually sees, drops branches that are never taken, and relies on deoptimisation if it guessed wrong, and it supports all of Java's dynamic behaviour like runtime class loading and reflection.
Then, if they want more
That gives very high peak performance, but every process pays for startup and warmup again. Full AOT, like native image, compiles before running, so startup is very fast, but it needs a closed world: dynamic class loading is out, reflection has to be configured, and without run-time profiles peak throughput is often lower.
Leyden chose a third way: keep the JIT and full Java semantics, but shift work earlier through a training run and store it in an AOT cache. JDK 24 stores classes already loaded and linked; JDK 25 adds method profiles and makes creating the cache a single option.
If production does something the training run did not, the JVM just handles it normally. Because each step is compatible with existing applications, a company can adopt it gradually without migrating each service.
So my strategy would be to invest now in representative training workloads and image pipelines that produce the cache, because later Leyden steps build on exactly that workflow, and keep native image for specific cases like CLIs and scale-to-zero functions.
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 "For 25 years HotSpot started every process from scratch and relied on the JIT to reach...": https://scrivio-interview-library.netlify.app/java/jit-compilation/e87a761961/