Phase 1 of 20 · Topic 1.3

JVM HotSpot Architecture: JIT Compiler Tiers & Method Inlining

1Concept

HotSpot JVM utilizes Tiered Compilation: C1 (Client Compiler) compiles fast for quick startup, while C2 (Server Compiler) performs deep optimizations (Method Inlining, Loop Unrolling, Escape Analysis, Dead Code Elimination) on hot methods.

2Architecture Diagram

Bytecode Invocation
       |
       v
 [ Interpreter ] ---> Fast startup, zero compilation delay
       |
       v (Invocation Counter Threshold Exceeded)
 [ C1 Compiler (Tier 1-3) ] ---> Basic optimizations & profiling
       |
       v (Hot Method Threshold Exceeded)
 [ C2 Compiler (Tier 4) ] ---> Deep optimization, Native Assembly

3Code Example

Core Java
public class JitOptimizationDemo {
    public static void main(String[] args) {
        long start = System.nanoTime();
        long result = 0;
        for (int i = 0; i < 100_000_000; i++) {
            result += addNumbers(i, 5);
        }
        long elapsed = System.nanoTime() - start;
        System.out.println("Result: " + result + " (Execution Time: " + (elapsed / 1_000_000) + " ms)");
    }

    private static long addNumbers(long a, long b) {
        return a + b;
    }
}

4Expected Output

Result: 5000000495000000 (Execution Time: 45 ms)

5Key Takeaways

  • HotSpot JIT compiles code lazily based on execution profiling counters.
  • Method inlining removes sub-routine call overhead for small frequently called methods.
  • Escape analysis determines if an object can be allocated on the stack instead of heap.