DEV Community

Cover image for πŸŽ™οΈInside the JVM: A Live Walkthrough
AK
AK

Posted on

πŸŽ™οΈInside the JVM: A Live Walkthrough

A technical story for a kid who speaks Java fluently

Narrator (you): The terminal blinks. You type:

java -Xms256m -Xmx2g -server MyGame

And press Enter.

Kid: That’s it? That’s when the magic starts?

You: πŸ”₯ That’s when the JVM is born.


πŸŒ… Phase 1: Birth β€” JVM Startup

The OS loads the JVM executable (java β†’ libjli.dylib/jli.dll β†’ libjvm.so) into memory.

βœ… JVM Initialization begins:

  • Allocates process memory (heap, metaspace, thread stacks, native memory).
  • Parses VM flags:
    • -Xms256m: "Reserve 256 MB right now for the heap."
    • -Xmx2g: "But you *may grow up to 2 GB β€” ask the OS nicely."*
    • -server: "Use the Server VM β€” C2 JIT, parallel GC, biased locking… we’re in for the long haul."

➑️ HotSpot VM (Oracle’s implementation) boots its internal subsystems:

  • Threads: Creates the main thread, compiler threads (C1, C2), GC threads (e.g., G1 concurrent mark), service threads.
  • Memory Managers: Sets up heap regions (for G1: 2048 regions, ~1 MB each), metaspace (native memory for class metadata), code cache (for JIT’d native code).
  • Runtime: Initializes java.lang.System, java.lang.Thread, signal handlers.

Kid: Wait β€” no classes yet?

You: None! Just the machine is ready. Now… it needs its first instruction.


πŸ“œ Phase 2: The Quest Begins β€” Loading MyGame

The JVM now must run MyGame.main(String[]).

But MyGame.class is just a file β€” a binary container in the *class file format* (per JVM Spec Β§4).

πŸ” Class Loading: Delegation in Action

  1. Application Class Loader says:

    β€œI’m in charge of MyGame. But first β€” ask my parent.”

    β†’ Delegates to Extension Class Loader.

  2. Extension CL says:

    β€œNot in jre/lib/ext? Then ask *my parent.”*

    β†’ Delegates to Bootstrap Class Loader.

  3. Bootstrap CL (native, written in C):

    β†’ Scans jre/lib (e.g., rt.jar, now modules in JDK 9+).

    β†’ Loads core: java/lang/Object.class, java/lang/Class.class, java/lang/String.class, …

    β†’ Builds their in-memory representations:

    • Klass* structures (C++ objects inside HotSpot)
    • Method tables, vtables, constant pools
    • Links Object β†’ Class β†’ ClassLoader
  4. Now back down:

    • Extension CL loads any JCE providers, etc.
    • Application CL finally loads MyGame.class from the classpath.

πŸ” Deep Dive Moment:

The .class file is parsed into:

  • magic: 0xCAFEBABE βœ…
  • minor/major version (e.g., 61.0 = Java 17)
  • constant_pool[]: 50 entries β€” #1 = Methodref: java/lang/Object."<init>":()V, #15 = Utf8: "Hello", etc.
  • fields[], methods[], attributes[] (like Code, LineNumberTable)

πŸ§ͺ Phase 3: Linking β€” Making Sense of the Scroll

Now MyGame is loaded β€” but not yet trusted.

Step 1: Verification (Bytecode Verifier β€” Type 2)

The JVM checks:

  • No jumps into the middle of instructions.
  • Stack maps: β€œAt instruction 12, stack must be [I, Ljava/lang/String;]”
  • No getfield on null. No type mismatches. β†’ If fails? java.lang.VerifyError β€” β€œThis scroll is cursed!”

Step 2: Preparation

  • Allocates memory for static fields:
  static int score = 0;     // ← set to 0 (default)
  static String name;       // ← set to null
Enter fullscreen mode Exit fullscreen mode

β†’ Stored in the static field section of the InstanceKlass.

Step 3: Resolution

For every symbolic reference in the constant pool:

  • #23 = Class: GameEngine β†’ resolve to actual Klass* (triggers loading GameEngine! β€” recursive!)
  • #25 = Methodref: GameEngine.start:()V β†’ resolve to method holder + vtable index.

πŸ” This may cascade: loading GameEngine β†’ loads Player β†’ loads java/util/ArrayList β†’ … until the entire dependency tree is linked.

Kid: So linking can load more classes?

You: Yes! Like pulling one thread β€” the whole sweater unfolds.


✨ Phase 4: Initialization β€” The First Spark

Now the JVM calls:

MyGame.<clinit>()   // class initializer
Enter fullscreen mode Exit fullscreen mode
  • Executes static initializers in textual order:
  static {
      score = 100;
      name = "Hero";
      engine = new GameEngine();   // ← triggers *GameEngine.<clinit>* and *GameEngine.<init>*
  }
Enter fullscreen mode Exit fullscreen mode

➑️ Objects are born in the heap:

  • new GameEngine() β†’
    1. Allocates raw memory (TLAB β€” Thread-Local Allocation Buffer, fast path!)
    2. Zeroes fields
    3. Sets klass pointer (metadata)
    4. Runs <init> (constructor)

Heap layout (simplified HotSpot):

[ Mark Word (64b) | Klass Pointer (compressed oop) | fields… ]
Enter fullscreen mode Exit fullscreen mode

πŸ” Fun Fact:

If heap is full and no GC can recover space during allocation?

β†’ OutOfMemoryError: Java heap space β€” even before main() starts!


πŸƒ Phase 5: Running main() β€” The Engine Ignites

Finally β€” the JVM invokes:

MyGame.main({})  // String[] args = empty
Enter fullscreen mode Exit fullscreen mode

➑️ A new frame is pushed onto the main thread’s Java Stack.

Frame layout:

[ Local Variables (0: args ref) ]
[ Operand Stack (empty) ]
[ Frame Data (return PC, previous frame pointer) ]
Enter fullscreen mode Exit fullscreen mode

Now the Execution Engine takes over.

First, the Interpreter runs bytecode:

0: getstatic     #2          // Field java/lang/System.out:Ljava/io/PrintStream;
3: ldc           #3          // String "Game starting..."
5: invokevirtual #4         // Method java/io/PrintStream.println:(Ljava/lang/String;)V
...
Enter fullscreen mode Exit fullscreen mode

Each instruction:

  • Pops values from operand stack
  • Does work (e.g., resolve field, call method)
  • Pushes results back

It’s safe. It’s portable. It’s… slow.

But the JVM is watching.


πŸš€ Phase 6: JIT Compilation β€” The Speed Awakening

The HotSpot (profiling data) notices:

  • Method GameLoop.update() called >10,000 times (default -XX:CompileThreshold=10000)
  • Backedge count (loop iterations) in render() exceeds 15,000

➑️ The C1 Compiler (Client, fast compile) kicks in:

  • Compiles update() to optimized native x86-64/ARM64
  • Inserts safepoints (polling points for GC/stopping threads)
  • Stores result in Code Cache

Later, if update() is still hot β€” C2 Compiler (Server, slow but ultra-optimized) recompiles it:

  • Inlines Player.move() β†’ Vector.add()
  • Eliminates bounds checks (if proven safe)
  • Reorders memory ops
  • Uses CPU registers aggressively

Now, future calls to update() jump directly into native code β€” no interpretation.

πŸ“Š Code Cache fills up?

β†’ If -XX:+ReservedCodeCacheSize is too small? CodeCache is full. Compiler has been disabled. ⚠️

Performance drops β€” interpreted again.


πŸ—‘οΈ Phase 7: Garbage Collection β€” The Silent Guardian

While the game runs, objects pile up in the Eden (young gen):

  • new Particle(), new TemporaryBuffer(), etc.

When Eden fills β†’ Minor GC (Young Collection):

  1. Stop-The-World (briefly!)
  2. Mark: Find all live objects (roots: stack frames, statics, JNI refs)
  3. Copy: Survivors β†’ Survivor Space (S0/S1, from/to toggling)
  4. Promote: Old enough? β†’ Old Gen (Tenured)

After many cycles β€” Old Gen fills β†’ Major GC / Mixed GC (G1):

  • Concurrent marking phase (runs while app runs!)
  • Then Mixed GC: cleans young + some old regions (chosen by β€œgarbage %” heuristic)
  • Compacts memory to avoid fragmentation

πŸ•°οΈ Pause times?

  • G1 aims for -XX:MaxGCPauseMillis=200 (default)
  • ZGC/Shenandoah? Sub-millisecond β€” no stop-the-world! (but newer, not default)

🧩 Phase 8: Native Calls β€” Opening the Door

At some point:

static { System.loadLibrary("sound"); }
native void playExplosion();
Enter fullscreen mode Exit fullscreen mode

➑️ JVM uses JNI:

  1. Looks for libsound.so (Linux), sound.dll (Windows)
  2. Resolves Java_MyGame_playExplosion symbol
  3. On call:
    • Transitions thread to _thread_in_native state
    • Jumps to native code (via call stub)
    • Native code runs β€” full OS access!
    • On return: checks for pending exceptions, safepoint requests

⚠️ If native code crashes? JVM process dies. No try/catch saves you.


πŸŒ™ Phase 9: Shutdown β€” The Final Frame

When main() returns β€” or System.exit(0) is called:

  1. Runs shutdown hooks (Runtime.addShutdownHook())
  2. Stops all non-daemon threads
  3. Flushes I/O buffers
  4. Unloads classes (if possible β€” rarely done in practice)
  5. Frees heap, metaspace, code cache
  6. JVM process exits β†’ OS reclaims all memory.

The castle dims.

The robot chef bows.

The magic β€” complete.


🎁 Final Recap Map (For the Kid’s Wall)

[Shell] 
   ↓ `java MyGame`
[JVM Process Born]
   β”œβ”€ Memory: Heap (Eden/Survivor/Old), Metaspace, Code Cache
   β”œβ”€ Threads: main, GC, Compiler, Service
   └─ Subsystems Initialized

[Class Loading Chain]
   Bootstrap β†’ Extension β†’ Application β†’ MyGame

[Linking]
   Verify β†’ Prepare β†’ Resolve (cascading!)

[Initialization]
   <clinit> β†’ static blocks β†’ new objects (Heap!)

[Execution]
   Interpreter β†’ (HotSpot) β†’ C1 JIT β†’ C2 JIT

[Memory Management]
   TLAB alloc β†’ Minor GC β†’ Promotion β†’ Mixed GC β†’ Compaction

[Native World]
   JNI β†’ libsound.so β†’ _thread_in_native β†’ return

[Shutdown]
   Hooks β†’ Cleanup β†’ Exit
Enter fullscreen mode Exit fullscreen mode

Ascii Map

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ USER SHELL                                                                                                                                                                                                     β”‚
β”‚ $ java -Xms512m -Xmx4g -server -XX:+UseG1GC -XX:MaxGCPauseMillis=100 -XX:+PrintGCDetails -XX:+PrintCompilation MyGame                                                                                          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                                                                                                                                                                                β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ JVM PROCESS (HotSpot) β€” BORN                                                                                                                                                                                                                                                                                                                       β”‚       
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                                                                                                     β”‚
β”‚ β”‚ Native OS Layer (C/C++)                                                                                                                                                                                    β”‚                                                                                                                                     β”‚
β”‚ β”‚ β€’ libjvm.so (Linux), jvm.dll (Win), libjvm.dylib (macOS) loaded by OS loader                                                                                                                               β”‚                                                                                                                                     β”‚
β”‚ β”‚ β€’ Threads created at startup:                                                                                                                                                                              β”‚                                                                                                                                     β”‚
β”‚ β”‚     - main (JavaThread)                                                                                                                                                                                    β”‚                                                                                                                                     β”‚
β”‚ β”‚     - VM threads: VMThread (safepoint coordinator), ConcurrentGCThread (G1ConcMark), CompilerThreads (C1, C2), ServiceThread, WatcherThread                                                                β”‚                                                                                                                                     β”‚
β”‚ β”‚ β€’ Memory layout initialized:                                                                                                                                                                               β”‚                                                                                                                                     β”‚
β”‚ β”‚     - Java Heap: 512 MB reserved (G1: divided into ~2048 regions, ~2 MB each)                                                                                                                              β”‚                                                                                                                                     β”‚
β”‚ β”‚     - Metaspace: native memory (non-heap) for Klass*, method metadata, annotations                                                                                                                         β”‚                                                                                                                                     β”‚
β”‚ β”‚     - CodeCache: segmented (non-nmethod, profiled nmethod, non-profiled nmethod); stores JIT-compiled native code                                                                                          β”‚                                                                                                                                     β”‚
β”‚ β”‚     - Thread stacks: 1 MB default (adjustable via -Xss)                                                                                                                                                    β”‚                                                                                                                                     β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                                                                                                     β”‚
β”‚                                                                                                                                                                                             β–Ό                                                                                                                                                      |
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                                                   β”‚
β”‚ β”‚ Class Loading Subsystem (Delegation Model)                                                                                                                                                                                                                   |                                                                                   β”‚ 
β”‚ β”‚                                                                                                                                                                                                                                                              |                                                                                   β”‚ 
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚                                                                                   β”‚ 
β”‚ β”‚ β”‚ Bootstrap ClassLoader (native, no Java object, parent = null)            β”‚   β”‚ Extension ClassLoader (sun.misc.Launcher$ExtClassLoader)                 β”‚   β”‚ Application ClassLoader (sun.misc.Launcher$AppClassLoader)                            β”‚      β”‚                                                                                   β”‚ 
β”‚ β”‚ β”‚ - Implemented in C inside JVM                                            β”‚   β”‚ - Parent: Bootstrap                                                      β”‚   β”‚ - Parent: Extension                                                                   β”‚      β”‚                                                                                   β”‚ 
β”‚ β”‚ β”‚ - Loads core platform classes:                                           β”‚   β”‚ - Loads extensions from jre/lib/ext (or java.ext.dirs)                   β”‚   β”‚ - Loads application classes from CLASSPATH (dirs, JARs, ZIPs)                         β”‚      β”‚                                                                                   β”‚ 
β”‚ β”‚ β”‚   β€’ java.lang.Object, String, System, Thread...                          β”‚   β”‚   β€’ e.g., sun.security.provider, javax.* (legacy)                        β”‚   β”‚   β€’ MyGame.class, com.mygame.Engine.class, lib/game.jar                               β”‚      β”‚                                                                                   β”‚ 
β”‚ β”‚ β”‚ - Sources: jrt:/ (JDK 9+ module system), jre/lib/modules                 β”‚   β”‚ - Now largely deprecated (replaced by module path)                       |   β”‚                                                                                       β”‚      β”‚                                                                                   β”‚ 
β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚                                                                                   β”‚ 
β”‚ β”‚                                                                                                                                                                                                                                                              β”‚                                                                                   β”‚ 
β”‚ β”‚ Delegation Flow: AppCL β†’ asks ExtensionCL β†’ asks BootstrapCL β†’ if not found, AppCL tries its own URLs (parent-first, but can be bypassed via custom CL)                                                                                                      β”‚                                                                                   β”‚ 
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                                                   β”‚ 
β”‚                                                                                                                                                                                                             β–Ό                                                                                                                                      β”‚ 
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                                                                                                     β”‚ 
β”‚ β”‚ Linking & Initialization (JVM Spec Β§5)                                                                                                                                                                     β”‚                                                                                                                                     β”‚ 
β”‚ β”‚                                                                                                                                                                                                            β”‚                                                                                                                                     β”‚ 
β”‚ β”‚ 1. Verification (Type 2 β€” at link time)                                                                                                                                                                    β”‚                                                                                                                                     β”‚ 
β”‚ β”‚    β€’ Data-flow analysis verifies:                                                                                                                                                                          β”‚                                                                                                                                     β”‚
β”‚ β”‚        - Operand stack consistency (no under/overflow)                                                                                                                                                     β”‚                                                                                                                                     β”‚
β”‚ β”‚        - Type correctness (no putfield on non-ref, no array store exception at runtime)                                                                                                                    β”‚                                                                                                                                     β”‚
β”‚ β”‚        - No illegal control flow (e.g., jump into middle of instruction)                                                                                                                                   β”‚                                                                                                                                     β”‚
β”‚ β”‚    β€’ Failure β†’ java.lang.VerifyError                                                                                                                                                                       β”‚                                                                                                                                     β”‚
β”‚ β”‚                                                                                                                                                                                                            β”‚                                                                                                                                     β”‚
β”‚ β”‚ 2. Preparation                                                                                                                                                                                             β”‚                                                                                                                                     β”‚
β”‚ β”‚    β€’ Allocate memory for static fields in InstanceKlass                                                                                                                                                    β”‚                                                                                                                                     β”‚
β”‚ β”‚    β€’ Initialize to *default* values:                                                                                                                                                                       β”‚                                                                                                                                     β”‚
β”‚ β”‚        int x; β†’ 0, boolean flag; β†’ false, Object ref; β†’ null                                                                                                                                               β”‚                                                                                                                                     β”‚
β”‚ β”‚                                                                                                                                                                                                            β”‚                                                                                                                                     β”‚
β”‚ β”‚ 3. Resolution                                                                                                                                                                                              β”‚                                                                                                                                     β”‚
β”‚ β”‚    β€’ Convert symbolic references in Constant Pool to direct references:                                                                                                                                    β”‚                                                                                                                                     β”‚
β”‚ β”‚        #3 = Class java/lang/System        β†’ Klass* for java.lang.System                                                                                                                                    β”‚                                                                                                                                     β”‚
β”‚ β”‚        #10 = Field System.out:PrintStream β†’ field offset in Klass                                                                                                                                          β”‚                                                                                                                                     β”‚
β”‚ β”‚        #22 = Method Game.update:()V       β†’ Method* + vtable index                                                                                                                                         β”‚                                                                                                                                     β”‚
β”‚ β”‚    β€’ May recursively trigger loading/linking of referenced classes                                                                                                                                         β”‚                                                                                                                                     β”‚
β”‚ β”‚                                                                                                                                                                                                            β”‚                                                                                                                                     β”‚
β”‚ β”‚ 4. Initialization (<clinit>)                                                                                                                                                                               β”‚                                                                                                                                     β”‚
β”‚ β”‚    β€’ Execute static initializers and static blocks *in source order*                                                                                                                                       β”‚                                                                                                                                     β”‚
β”‚ β”‚        static { score = 100; engine = new GameEngine(); }                                                                                                                                                  β”‚                                                                                                                                     β”‚
β”‚ β”‚    β€’ Object creation:                                                                                                                                                                                      β”‚                                                                                                                                     β”‚
β”‚ β”‚        - TLAB allocation (fast-path, thread-local) in Eden                                                                                                                                                 β”‚                                                                                                                                     β”‚
β”‚ β”‚        - Header: [Mark Word (64b) | Klass Word (32b compressed oop)]                                                                                                                                       β”‚                                                                                                                                     β”‚
β”‚ β”‚        - Fields zeroed, then constructor (<init>) executed                                                                                                                                                 β”‚                                                                                                                                     β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                                                                                                     β”‚
β”‚                                                                                                                                                                                             β–Ό                                                                                                                                                      |
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚
β”‚ β”‚ Runtime Data Areas (JVM Spec Β§2.5)                                                                                                                                                                                                                                                                                                         β”‚     β”‚
β”‚ β”‚                                                                                                                                                                                                                                                                                                                                            β”‚     β”‚
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”              β”‚     β”‚
β”‚ β”‚ β”‚ PC Register (per thread)              β”‚   β”‚ Java Stack (per thread)                                                                                                              β”‚   β”‚ Heap (shared, GC-managed)                                                                                                          β”‚              β”‚     β”‚
β”‚ β”‚ β”‚ β€’ Holds address of current bytecode   β”‚   β”‚ β€’ Grows downward                                                                                                                     β”‚   β”‚                                                                                                                                    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚ β€’ Undefined for native methods        β”‚   β”‚ β€’ Frame created on method entry:                                                                                                     β”‚   β”‚       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚   β”‚     [Local Variable Table] + [Operand Stack] + [Frame Data (return PC, prev frame ptr)]                                              β”‚   β”‚       β”‚ Young Generation                                                                                                      β”‚    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚       β”‚     β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                                                                              β–Ό               β”‚       β”‚     β”‚ Eden (object allocation)             │───▢│ Survivor Space (S0 ↔ S1, copying collection)                 β”‚      β”‚    β”‚             β”‚      β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚       β”‚     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”‚ Method Area (shared, created at JVM start)       β”‚            β”‚       β”‚                         β”‚                                             β–²                                               β”‚    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”‚ β€’ Stores per-class structures:                   β”‚            β”‚       β”‚                         β–Ό (promotion after ~15 GC cycles)             β”‚                                                β”‚    β”‚             β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”‚     - Runtime Constant Pool(per-class symbol tbl)β”‚            β”‚       β”‚       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”‚     - Field/method metadata                      β”‚            β”‚       β”‚       β”‚ Old Generation (Tenured)                                                                                  β”‚   β”‚    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”‚     - Static field storage                       β”‚            β”‚       β”‚       β”‚ β€’ Region-based (G1): ~2048 regions, 1–32 MB each                                                          β”‚   β”‚    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”‚     - JIT-compiled code? No β€” that’s CodeCache!  β”‚            β”‚       β”‚       β”‚ β€’ Mixed GC: collects Eden + selected Old regions (highest garbage ratio)                                  β”‚   β”‚    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚       β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                                                                                              β”‚       |                                                                                                                       β”‚    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”‚ Native Method Stacks (per thread)                β”‚            β”‚                                                                                                                                    β”‚              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”‚ β€’ Used when thread is in _thread_in_native state β”‚            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜              β”‚     β”‚
β”‚ β”‚ β”‚                                       β”‚                                                                              β”‚ β€’ No JVM-enforced limits β€” OS controls size      β”‚                                                                                                                                                                β”‚     β”‚
β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                                              β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                                                                                                                                β”‚     β”‚
| |                                                                                                                                                                                                                                                                                                                                            |     |
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚
β”‚                                                                                                                                                                                                             β–²                                                                                                                                      |
β”‚                                                                                                                                                                                                             β”‚                                                                                                                                      |
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                                                                                                 β”‚
β”‚ β”‚ Execution Engine                                                                                                                                                                                               β”‚                                                                                                                                 β”‚
β”‚ β”‚                                                                                                                                                                                                                β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚                                                                                                                                 |
β”‚ β”‚ β”‚ Interpreter                                                                                                                                                                                        β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚ β€’ Bytecode interpreter loop: fetch β†’ decode β†’ execute                                                                                                                                              β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚ β€’ Template-based (C++ templates emit assembly for each bytecode)                                                                                                                                   β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚ β€’ Slow for hot code, but fast startup, low memory                                                                                                                                                  β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚                                                                                                                                 β”‚
β”‚ β”‚                                                                                                                                                                                         β”‚                      β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚ JIT Compiler β€” HotSpot Adaptive Optimization                                                                                                                                                               β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚ β€’ Profiling: method invocation counters, backedge counters (loops)                                                                                                                                         β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚ β€’ Tiered Compilation (default since JDK 8):                                                                                                                                                                β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚                                                                                                                                                                                                            β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚   β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”      β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚   β”‚ C1 Compiler (Client)                                         │───▢ |  C2 Compiler (Server)                                                                                                      β”‚     β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚   β”‚ β€’ Fast compile (~100–300 ms)                                 β”‚      β”‚ β€’ Slow compile (~1–5 sec), high optimization                                                                               β”‚     β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚   β”‚ β€’ Enables profiling (e.g., branch counts)                    β”‚      β”‚ β€’ Inlining (up to 9 levels), escape analysis, lock elision, vectorization (SIMD), loop unrolling                           β”‚     β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚   β”‚ β€’ Output: profiled nmethods in CodeCache                     β”‚      β”‚ β€’ Uses Ideal Graph (Sea of Nodes) for global optimization                                                                  β”‚     β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚   β”‚ β€’ Good for client apps, short-lived processes                β”‚      β”‚ β€’ Stored in non-profiled CodeCache segment                                                                                 β”‚     β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜      β”‚ β”‚                                                                                                                                 β”‚
β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚                                                                                                                                 β”‚
β”‚ β”‚                                                                                                                                                                                                                β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚ Garbage Collection (G1 Example)                                                                                                                                                                    β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚ β€’ Concurrent Marking Cycle:                                                                                                                                                                        β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚     1. Initial Mark (STW, piggybacks on Young GC)                                                                                                                                                  β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚     2. Concurrent Mark (app threads run)                                                                                                                                                           β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚     3. Remark (STW, finishes marking)                                                                                                                                                              β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚     4. Cleanup (STW, calculates live bytes per region)                                                                                                                                             β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚ β€’ Mixed GC Phase:                                                                                                                                                                                  β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚     - After Cleanup, scheduler triggers Mixed GCs                                                                                                                                                  β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚     - Each pause collects: Eden + *N* Old regions (selected by garbage % heuristic)                                                                                                                β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚     - Goal: meet -XX:MaxGCPauseMillis (e.g., 100 ms)                                                                                                                                               β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β”‚ β€’ Humongous Objects (>50% region size) β†’ allocated in Old directly; cleaned in Remark/Cleanup                                                                                                      β”‚         β”‚                                                                                                                                 β”‚
β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚                                                                                                                                 β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                                                                                                 β”‚
β”‚                                                                                                                                                                                                             β–²                                                                                                                                      |
β”‚                                                                                                                                                                                                             β”‚                                                                                                                                      |
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                                                                                                     |
β”‚ β”‚ Java Native Interface (JNI)                                                                                                                                                                                β”‚                                                                                                                                     |
β”‚ β”‚                                                                                                                                                                                                            β”‚                                                                                                                                     |
β”‚ β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”     β”‚                                                                                                                                     β”‚
β”‚ β”‚ β”‚ Native Method Libraries                                                                                                                                                                            β”‚     β”‚                                                                                                                                     β”‚
β”‚ β”‚ β”‚ β€’ Loaded via System.loadLibrary("sound") β†’ dlopen()/LoadLibrary() β†’ finds libsound.so/dll/dylib                                                                                                    β”‚     β”‚                                                                                                                                     β”‚
β”‚ β”‚ β”‚ β€’ Symbol resolution: Java_MyGame_playExplosion β†’ native void JNICALL Java_MyGame_playExplosion(JNIEnv*, jobject)                                                                                   β”‚     β”‚                                                                                                                                     β”‚
β”‚ β”‚ β”‚ β€’ Call sequence:                                                                                                                                                                                   β”‚     β”‚                                                                                                                                     β”‚
β”‚ β”‚ β”‚     1. Transition thread state: _thread_in_Java β†’ _thread_in_native                                                                                                                                β”‚     β”‚                                                                                                                                     β”‚
β”‚ β”‚ β”‚     2. Call stub jumps to native code                                                                                                                                                              β”‚     β”‚                                                                                                                                     β”‚
β”‚ β”‚ β”‚     3. Native code runs β€” full OS access, no GC safepoints                                                                                                                                         β”‚     β”‚                                                                                                                                     β”‚
β”‚ β”‚ β”‚     4. On return: check for pending async exceptions, safepoint requests, GC needs                                                                                                                 β”‚     β”‚                                                                                                                                     β”‚
β”‚ β”‚ β”‚ β€’ Critical: native code must NOT hold JVM locks across calls; must call JNI functions to access Java objects                                                                                       β”‚     β”‚                                                                                                                                     β”‚
β”‚ β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β”‚                                                                                                                                     β”‚
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                                                                                                     β”‚
β”‚                                                                                                                                                                                                             β–²                                                                                                                                      |β”‚                                                                                                                                                                                                             β”‚                                                                                                                                      |
β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”                                                                                                                                     β”‚
β”‚ β”‚ Shutdown Sequence (JVM Spec Β§12.8)                                                                                                                                                                         β”‚                                                                                                                                     β”‚
β”‚ β”‚ 1. Trigger: main() returns OR System.exit(status) OR fatal error (e.g., OutOfMemoryError: Metaspace)                                                                                                       β”‚                                                                                                                                     β”‚
β”‚ β”‚ 2. Run shutdown hooks (in reverse registration order) β€” e.g., flush logs, save state                                                                                                                       β”‚                                                                                                                                     β”‚
β”‚ β”‚ 3. Run finalizers (if -XX:+ExplicitGCInvokesFinalization; discouraged)                                                                                                                                     β”‚                                                                                                                                     β”‚
β”‚ β”‚ 4. Stop all non-daemon threads (interrupt + join)                                                                                                                                                          β”‚                                                                                                                                     β”‚
β”‚ β”‚ 5. Close system resources: stdin/stdout, file descriptors, network sockets                                                                                                                                 β”‚                                                                                                                                     β”‚
β”‚ β”‚ 6. Deallocate:                                                                                                                                                                                             β”‚                                                                                                                                     β”‚
β”‚ β”‚     - Heap β†’ return to OS (mmap/munmap)                                                                                                                                                                    β”‚                                                                                                                                     β”‚
β”‚ β”‚     - Metaspace β†’ free virtual memory ranges                                                                                                                                                               β”‚                                                                                                                                     β”‚
β”‚ β”‚     - CodeCache β†’ purge native code                                                                                                                                                                        β”‚                                                                                                                                     β”‚
β”‚ β”‚     - Unload shared classes (if class data sharing used)                                                                                                                                                   β”‚                                                                                                                                     β”‚
β”‚ β”‚ 7. JVM process terminates (exit(status)); OS reclaims full process memory space                                                                                                                            β”‚                                                                                                                                     | β”‚ |                                                                                                                                                                                                            |                                                                                                                                     |
β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜                                                                                                                                     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
Enter fullscreen mode Exit fullscreen mode

πŸ”‘ Key Legend (Embedded in Diagram)

  • STW = Stop-The-World (all app threads paused)
  • CP = Constant Pool
  • LVs = Local Variables
  • OS = Operand Stack
  • TLAB = Thread-Local Allocation Buffer (fast-path heap alloc β€” not shown, but implied in "Heap β†’ Eden")
  • G1 Regions = Heap divided into fixed-size regions (default ~1–32 MB); GC selects β€œgarbage-rich” ones
  • HotSpot = Oracle’s JVM implementation (adaptive optimization engine)

Top comments (0)