JIT Compilation and Tiered Compilation in HotSpot
Fast recall
Quick revision
Core answer
Understanding of why Java performance improves with warmup and how JIT affects production behavior
Not knowing that JIT has a warmup period — benchmarking without warmup produces misleading results
Explain deoptimization (when JIT reverts to interpreted mode) and speculative optimizations like inlining
Interview-ready guide
Interview answer
HotSpot starts every method in the interpreter and profiles execution — JIT compilation to native code happens only for methods that become hot.
Tiered compilation:
- Method crosses invocation threshold (~10,000 calls) → queued for JIT compilation
- C1: lightly optimized native code quickly — gets hot methods out of the slow interpreter
- C2: aggressive optimizations using C1's profiling data — inlining, escape analysis, speculative devirtualization
Warmup:
- A freshly started Java service runs significantly slower — hot paths haven't been compiled yet
- In Kubernetes: routing full traffic to a new pod immediately means users hit unoptimized code
- Fix: configure readiness probes with startup delays; use gradual traffic shifting or startup warmup calls
Deoptimization:
- C2 makes speculative bets — e.g. inlining assuming a virtual method has only one implementation
- If a new class invalidates the assumption: JVM discards optimized code, falls back to interpreter briefly
- Causes latency spikes visible in p99 metrics; visible via
-XX:+PrintCompilationand JFR
I recommend watching for deoptimization events when diagnosing intermittent latency — JFR reveals exactly which methods are being compiled, deoptimized, and recompiled.
JIT Compilation and Tiered Compilation in HotSpot
Direct Answer
HotSpot JIT compiles hot bytecode to native code. Tiered compilation runs C1 (fast compile) then promotes to C2 (aggressive optimize) after an invocation threshold. Cold code stays interpreted; hot paths get inlined.
Common Mistakes & Pitfalls
Not knowing that JIT has a warmup period — benchmarking without warmup produces misleading results
Check your understanding
Answer these without looking back at the article.
- What is On-Stack Replacement (OSR) in the JVM?
- What is GraalVM native image and what are its trade-offs?
- How does JIT method inlining affect performance?
Related interview prep categories
2Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.