Master the fundamental concepts of jvm internals through this focused micro-challenge.
The JVM starts in the interpreter, then promotes hot methods through C1 (fast, lightly optimized) to C2 (aggressive optimizing). Tiered compilation balances startup time against peak throughput.
Typical progression:
Method invocation counters and back-edge counters trigger compilation. OSR (on-stack replacement) compiles loops inside long-running methods without waiting for the next entry.
For example, a server loop may run interpreted for thousands of iterations, hit C1, then C2 with inlined callees and escape analysis.
Flags like \`-XX:+TieredCompilation\` control the policy on modern JDKs.
Compile thresholds exist because compiling everything at startup would slow launch unbearably. Server workloads benefit from higher thresholds; interactive apps sometimes lower them for snappier first interactions.
This exercise asks you to document the interpret-to-C1-to-C2 pipeline. You will explain what triggers each tier and why cold code stays interpreted while hot paths get native code.
You will use the same mental model here when reading production interpreter source later in the track. Sketch one concrete input on paper, predict the outcome, then confirm with code. That discipline catches logic errors early and makes debugging far faster when you extend the implementation in follow-on tasks.
Write a C program that documents JVM tiered compilation.
Requirements:
Three hints are available for this task, revealed one at a time inside the code workspace so you can struggle productively before seeing them.
All starter code and reference implementations are available for your local setup.
View on Github