0Pricing
Java Academy · Lesson

JIT Compilation and Tiered Compilation

Learn how the JVM interprets then JIT-compiles hot methods and how to trigger and observe compilation.

JIT Compilation and Tiered Compilation is a free Java Academy lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Java Academy learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Interpreter vs JIT

The JVM initially interprets bytecode. When a method is called frequently ("hot"), the JIT compiler compiles it to native machine code for much faster execution.

Tiered Compilation (Default Since Java 8)

Tiered compilation uses five tiers: T0 (interpreter), T1 (C1 simple), T2 (C1 limited profiling), T3 (C1 full profiling), T4 (C2 fully optimized). Methods move up tiers as they get hotter.

// Enable/disable tiered compilation:
// -XX:+TieredCompilation   (default ON in Java 8+)
// -XX:-TieredCompilation   (disables — only C2 used)

C1 Compiler (Client Compiler)

C1 compiles quickly with moderate optimization. It adds profiling instrumentation to measure calling frequencies and branch outcomes for C2.

C2 Compiler (Server Compiler)

C2 (Opto) performs deep optimization: inlining, escape analysis, loop unrolling, vectorization, and dead code elimination. It produces the fastest native code but takes longer to compile.

// Force server JIT only:
java -server MyApp
// Or explicitly:
java -XX:-TieredCompilation MyApp   // uses C2 only (warm-up is slower)

Hotspot Threshold

A method is JIT-compiled after crossing an invocation counter threshold. Default: 10,000 calls (C2). Tune with -XX:CompileThreshold=N.

// Lower threshold for faster warm-up (at cost of less optimization):
java -XX:CompileThreshold=1000 MyApp

Inlining

Inlining is C2's most impactful optimization: small methods called from hot code are "copy-pasted" at the call site, eliminating method dispatch overhead and enabling further optimizations.

// Check inlining decisions:
java -XX:+PrintInlining -XX:+UnlockDiagnosticVMOptions MyApp
// Output:
// @ 5  com.example.User::getName (5 bytes)   inlined

Escape Analysis

If C2 determines an object never escapes the current method (or thread), it can allocate it on the stack instead of the heap — eliminating GC pressure entirely.

// Objects that don't escape are stack-allocated:
String result = new StringBuilder().append("Hello ").append(name).toString();
// The StringBuilder may be eliminated by escape analysis

JIT Compilation Logs

Use -XX:+PrintCompilation to log each method as it is compiled. The output shows method name, tier, and compilation flags.

// java -XX:+PrintCompilation MyApp
// Output:
//    1   n    java.lang.String::hashCode (0 bytes)
//   25   3    com.example.UserService::findById (42 bytes)
//   31   4    com.example.UserService::findById (42 bytes) made not entrant

Deoptimization

If a JIT assumption is violated (e.g., a class is loaded that changes a call site's receiver type), C2 "deoptimizes" — reverts to interpreter or C1. This is normal and usually transparent.

Warm-Up Time

JIT compilation takes time. In short-lived processes, methods may never get JIT-compiled. Use ahead-of-time compilation (GraalVM Native Image) or cache JIT results with Class Data Sharing (CDS) for faster startup.

// Enable AppCDS to cache JIT-compilable classes:
java -XX:ArchiveClassesAtExit=app.jsa -cp app.jar MyApp   # generate archive
java -XX:SharedArchiveFile=app.jsa -cp app.jar MyApp       # use archive

GraalVM JIT

GraalVM replaces C2 with a JIT written in Java. It enables better optimizations, the ability to use JIT for non-Java languages, and is the base for Native Image (ahead-of-time compilation).

Quick Check

What is the JIT compilation technique that eliminates method call overhead by merging small methods into the caller?

Recap

Tiered compilation moves methods through C1 (fast compile, profile) to C2 (deep optimize). Key optimizations: inlining, escape analysis, loop unrolling. Use -XX:+PrintCompilation to observe JIT decisions. Warm up before benchmarking.

Frequently asked questions

Is the “JIT Compilation and Tiered Compilation” lesson free?

Yes — the full text of “JIT Compilation and Tiered Compilation” is free to read here on the web, and the Java Academy course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Java Academy course, upgrade to CoddyKit PRO.

What will I learn in “JIT Compilation and Tiered Compilation”?

Learn how the JVM interprets then JIT-compiles hot methods and how to trigger and observe compilation. You practise Java Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Java Academy?

No prior experience is required. Java Academy on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “JIT Compilation and Tiered Compilation” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Java Academy lesson?

Yes. Every Java Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Class Loading Phases: Load, Link, Initialize
  2. ClassLoader Hierarchy and Custom Loaders
  3. Inspecting Bytecode with javap
  4. JIT Compilation and Tiered Compilation
← Back to Java Academy