Java / JVM Architecture (Java21) Interview questions
How does tiered compilation work in HotSpot JVM?
Tiered compilation, the default since Java 8, runs a method through up to five execution levels instead of jumping straight from interpreted to fully optimized code.
| Level | What runs |
| 0 | Interpreter |
| 1-3 | C1, with increasing amounts of profiling instrumentation |
| 4 | C2, fully optimized using data gathered at levels 1-3 |
A method starts at level 0, and as its invocation counter rises, it is promoted to a fast C1 compile that also collects profiling data such as branch frequencies and type information, and eventually to a C2 compile that uses that profile to make aggressive, speculative optimizations.
This staged approach means simple, rarely-run methods never pay C2's heavier compile cost, while genuinely hot methods still end up fully optimized once the JVM has real evidence that the investment is worth it.
More Related questions...