Scrivio Interview library
ConceptFoundations6 min read · updated 12 November 2026

Explain tiered compilation in HotSpot: what the interpreter, C1 and C2 each do, and what the compilation levels 0 to 4 mean.

HotSpot runs every method first in the interpreter, level 0, which also counts invocations and loop iterations. Warm methods are compiled by C1, a fast compiler, at level 3 with full profiling (level 1 is C1 without profiling and level 2 is C1 with limited profiling), and the hottest methods are recompiled by C2 at level 4, which uses the collected profiles for aggressive, speculative optimisation. The usual path for a hot method is 0 -> 3 -> 4, trivial methods may stop at level 1, and -XX:+PrintCompilation shows each step.

Why this question is asked

Tiered compilation explains a lot of everyday Java behaviour: why a service is slow for its first minute, why benchmarks need warmup, and why the same code can get faster after a while. Interviewers ask about the levels to check whether we know how the JVM decides what to compile and when. In this answer, we will recap the interpreter and the two JIT compilers, go through the five levels, follow a method's usual journey, read PrintCompilation output, and see why the design has two compilers at all.

1A Quick Recap of the Interpreter and the JIT

Java source is compiled into bytecode, instructions for the JVM rather than for a real CPU. The JVM can run bytecode in an interpreter, which reads one instruction at a time and performs it. Interpreting is slow, but it can start immediately.

A JIT compiler (just-in-time) turns bytecode into native machine code while the program runs, but only for methods that are used enough to be worth it. HotSpot has two: C1, also called the client compiler, compiles quickly and produces decent code; C2, the server compiler, takes much longer but produces highly optimised code. Tiered compilation, the default since JDK 8, uses both in stages.

2The Five Compilation Levels

Each level describes who runs the method and how much information is collected while it runs. Profiling means recording facts about how the code actually behaves: which branches are taken, which types appear at each call site, how often loops repeat. Profiling makes code slower, but the information it gathers is what lets C2 optimise well.

Tiered compilation levels
LevelWho runs itProfilingTypical use
0interpreterinvocation and loop countersevery method starts here
1C1nonetrivial methods, e.g. getters
2C1counters onlywhen C2's queue is long
3C1full: branches, types, countersnormal step before C2
4C2none, uses level 3 profileshot code at peak speed

Notice that level 3 code is slower than level 2 code, even though both are C1, because full profiling adds work to every branch and call. That is a deliberate trade: the method runs a little slower for a short time to collect what C2 needs.

3The Usual Journey of a Hot Method

A method starts interpreted at level 0. The interpreter counts how often it is called and how many times its loops jump back. When those counters cross a threshold, the method is queued for C1 at level 3. Now it runs as compiled code, much faster than the interpreter, while still profiling. When the level 3 counters cross a higher threshold, the method is queued for C2, which reads the profile and compiles it at level 4. From then on new calls use the C2 code.

There are shortcuts. If a method is trivial, such as a getter, profiling would teach C2 nothing new, so the JVM compiles it at level 1 and stops there. If the C2 queue is long, the JVM may compile at level 2 first and move to level 3 later, so that the method is not stuck in slow profiling code while waiting. And if compiled code turns out to be based on wrong assumptions, it is thrown away and the method goes back to an earlier level, which is called deoptimisation.

Step throughThe common path through the tiers
  1. Level 0: interpretercounts calls and loop back-edges
  2. Trivial method?
    Yescompile at level 1 and stopNocompile at level 3
  3. Level 3: C1 with full profilingrecords branches and receiver types
  4. Level 4: C2optimises using the profile
  5. Deoptimisation if an assumption failsback to level 0, later recompiled

5 steps in order. Play them, or step through them one at a time.

4Watching It With PrintCompilation

The flag -XX:+PrintCompilation prints a line every time a method is compiled. The columns show a timestamp in milliseconds, a compilation id, attribute flags, the tier level, the method and its size in bytes of bytecode.

Shell
java -XX:+PrintCompilation -jar app.jar
// time id attrs level method size
// 112 41 3 com.shop.Price::total (38 bytes)
// 115 44 1 com.shop.Item::getPrice (5 bytes)
// 890 612 4 com.shop.Price::total (38 bytes)
// 893 41 3 com.shop.Price::total (38 bytes) made not entrant

Reading the example: total() was compiled at level 3 at 112 ms; the getter went straight to level 1. At 890 ms C2 compiled total() at level 4, and immediately afterwards the old level 3 version was made not entrant, meaning new calls no longer use it. Other markers in the attribute column are % for an on-stack replacement compilation, s for a synchronized method, n for a native wrapper and ! for a method with exception handlers. The exact layout can differ between JDK versions, so check your version.

5Why Two Compilers Instead of One

With only C2, a method would be interpreted until it was very hot, so startup and warmup would be slow, and C2 would have only the interpreter's limited profile. With only C1, startup would be good but peak performance would be lower, because C1 does not perform the speculative optimisations C2 does. Tiered compilation gets fast compiled code early from C1 and peak performance later from C2, using the time spent in C1 to gather a rich profile. The cost is more compilation work overall and more code cache space, which is why the code cache is larger with tiered compilation enabled.

6Follow-up questions

Why does C2 need profiles collected at level 3?

C2's best optimisations are speculative: it assumes what the profile says, that a branch is never taken, that a call site only ever sees one or two receiver types, or that a value is never null, and compiles fast code for that case with a cheap check that deoptimises if the assumption fails. Without a profile it would have to compile every branch and use full virtual calls, losing inlining and the optimisations that follow it. Level 3 collects exactly those facts in compiled code, so it gathers them quickly.

What does -XX:TieredStopAtLevel=1 do?

It stops compilation at C1 without profiling, so no C2 compilation happens. Startup is faster and compiler CPU use is lower, which suits short-lived tools and tests, but long-running services lose their peak performance.

How many compiler threads does the JVM use?

By default the JVM chooses the count from the number of CPUs, split between C1 and C2 threads, with about a third for C1. CICompilerCount overrides it. With very few CPUs there are only a couple of compiler threads, which is one reason warmup is slower in small containers.

7Conclusion

In this answer, we saw that HotSpot starts every method in the interpreter at level 0, compiles warm methods with C1 at level 3 to collect a full profile, and recompiles hot methods with C2 at level 4 for peak speed. Levels 1 and 2 are C1 variants without or with limited profiling, used for trivial methods or when C2 is busy. PrintCompilation shows each compilation and its level, and the two-compiler design gives both fast warmup and high peak performance.

What to say in the interviewAbout 80 seconds aloud

Open with

HotSpot uses tiered compilation, which combines the interpreter with two JIT compilers. Level 0 is the interpreter: every method starts there, and it counts how often a method is called and how often its loops jump back.

Then, if they want more

When a method gets warm, C1 compiles it, normally at level 3, which is C1 with full profiling: it records branch frequencies, receiver types at call sites and so on. Level 1 is C1 with no profiling, used for trivial methods like getters where profiling would not help, so they stop there.

Level 2 is C1 with only counters, used for example when the C2 queue is long. When the method is really hot, C2 compiles it at level 4, using the level 3 profile to make speculative optimisations like inlining the one type it has seen or removing branches that were never taken, with guards that deoptimise if the assumption breaks.

So the normal path is 0, 3, 4. With PrintCompilation I can see each compilation with its level, and markers like percent for OSR and made not entrant when an old version is replaced. The point of two compilers is fast compiled code early and peak code later.

About this answer

Last updated
12 November 2026
Versions it names
Java 8
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 "Explain tiered compilation in HotSpot: what the interpreter, C1 and C2 each do, and what...": https://scrivio-interview-library.netlify.app/java/jit-compilation/e85f0f50f3/