On this page
  1. JVM ClassLoading, Bytecode & HotSpot JIT
  2. Overview
  3. Class Loading Lifecycle
  4. Stack-Based Bytecode
  5. HotSpot Tiered Compilation (Interpreter + C1 + C2)
  6. Key C2 Optimizations
  7. Startup & Memory Regions

JVM ClassLoading, Bytecode & HotSpot JIT

Prev: OpenJDK Distributions & Toolchain | Up: JVM & OpenJDK | Next: Garbage Collection (G1 & ZGC)
Rel: Compilation, Interpretation & JIT, Diagnostics, JFR & jcmd, Generics & Type Erasure
Ref: Java Virtual Machine Specification (SE 21) , OpenJDK HotSpot Group
Tags: #public #java #jvm #openjdk #jit #bytecode #tier/standard


Overview

Java achieves portability and high steady-state throughput through a two-stage execution model: javac compiles source code into platform-independent JVM bytecode (.class files), and OpenJDK's HotSpot JVM dynamically loads, verifies, interprets, profiles, and just-in-time (JIT) compiles hot paths into native machine code.

Class Loading Lifecycle

Classes are loaded lazily on first active use through three phases:

  1. Loading: A ClassLoader locates the .class binary stream and creates a java.lang.Class object in Metaspace. Built-in hierarchy uses parent delegation:
    • Bootstrap ClassLoader (native, loads java.base and core JDK modules)
    • Platform ClassLoader (loads standard non-base JDK modules)
    • Application (System) ClassLoader (loads your classpath / module path)
  2. Linking:
    • Verification: Ensures bytecode obeys stack-depth, type-safety, and control-flow rules.
    • Preparation: Allocates static fields with default zero/null values.
    • Resolution: Resolves symbolic constant-pool references to direct memory references.
  3. Initialization: Executes static field initializers and static { ... } blocks once, thread-safely, on first active use.

Stack-Based Bytecode

The JVM is a stack-based virtual machine. Each method frame holds a local variable array and an operand stack. You can inspect generated bytecode with javap -c:

static int addOne(int x) {
    return x + 1;
}
0: iload_0        // push local int slot 0 (x) onto operand stack
1: iconst_1       // push int constant 1
2: iadd           // pop two ints, push sum
3: ireturn        // return top int

HotSpot Tiered Compilation (Interpreter + C1 + C2)

HotSpot balances fast startup with peak native speed using tiered compilation:

Tier Engine Behavior
Tier 0 Interpreter Executes bytecode immediately; collects basic call/loop counters
Tier 1–3 C1 (Client compiler) Compiles quickly with light optimizations and rich profiling counters (branch frequencies, receiver types)
Tier 4 C2 (Server compiler) Aggressively compiles hot methods using live profile data

Key C2 Optimizations

Startup & Memory Regions

Linked from

Related notes