The full picture
- Tiered pipeline: interpreter → C1 with profiling → C2 (or Graal). Hot methods get recompiled; cold code may never be compiled at all.
- Speculative optimization: C2 inlines the observed implementation of a virtual call (monomorphic dispatch). If a new class shows up later, the JVM deoptimizes back to the interpreter and recompiles — correctness is preserved via 'uncommon traps'.
- Why benchmarks lie: dead-code elimination and on-stack replacement wreck naive
System.nanoTime()loops — use JMH, which handles warm-up, forks and blackholes.
| Startup option | What it does | Cost |
|---|---|---|
| CDS / AppCDS | Pre-parsed class metadata shared across JVMs | Nearly free — enable it |
| AOT cache (Leyden) | Reuses training-run compilation state | Requires representative training run |
| CRaC | Snapshot a warmed JVM, restore in ms | Framework + resource-lifecycle support needed |
| GraalVM native image | Full AOT, ms startup, low RSS | Closed-world: reflection config, no C2 peak, longer builds |