Subroutine Logo
Subroutine
← Back to Articles Systems Advanced 6 min read

Sub-Millisecond Pauseless GC: ZGC & Shenandoah Architecture

How modern JVM garbage collectors use 64-bit colored pointers and load barriers to eliminate stop-the-world pauses.

Published: 2026-08-09
#Java#JVM#Garbage Collection#Systems#ZGC#Performance

In traditional tracing garbage collectors (such as Parallel GC or G1GC), compacting live objects to defragment the heap requires freezing all application worker threads during a Stop-The-World (STW) pause. On multi-gigabyte or terabyte heaps, STW pauses can last hundreds of milliseconds or even seconds, causing severe SLA breaches in financial trading engines and web services.

Modern production garbage collectors - specifically ZGC (JEP 377 / JEP 439) and Shenandoah (JEP 379) - achieve sub-millisecond maximum STW pause times regardless of heap size (from 16MB up to 16TB).


1. Summary & Key Architectural Takeaways

  • Colored Pointers: Metadata bits stored directly inside 64-bit reference pointers (Marked0, Marked1, Remapped).
  • Load Barriers: JIT-injected micro-checks that self-heal stale object pointers during field reads without stopping application threads.
  • Concurrent Compaction: Object relocation happens concurrently while worker threads execute.

2. Interactive ZGC Pauseless Collector Simulator

Test how ZGC advances concurrent marking and load-barrier object relocation below:

ZGC & Shenandoah Pauseless Garbage Collection

64-bit Colored Pointers & Load Barriers for Sub-Millisecond Pauses

Max Pause SLA:< 1.0 ms STW
Colored Pointer State: 42..45 Reference Bit Flags
JVM Heap Regions (Colored Pointer Tags)Concurrent Load-Barrier Relocation
Region #164 MB
Color: Marked0
Region #2128 MB
Color: Marked1
Region #332 MB
Color: Remapped
Region #4256 MB
Color: Marked0
ZGC Engine Active: Terabyte heap colored pointers active. Max pause time < 1ms.

3. ZGC Concurrent Execution & Colored Pointer Pipeline

graph TD
    subgraph Pipeline["ZGC Pauseless Concurrent Execution Pipeline"]
    M1["1. Pause Mark Start (< 1ms STW)"] --> CM["2. Concurrent Mark (Color Pointers: Marked0 / Marked1)"]
    CM --> M2["3. Pause Mark End (< 1ms STW)"]
    M2 --> CR["4. Concurrent Prepare for Relocate"]
    CR --> M3["5. Pause Relocate Start (< 1ms STW)"]
    M3 --> CREL["6. Concurrent Relocate & Self-Healing Load Barriers"]
    CREL --> DONE["7. Defragmented Heap Remapped"]
    end

4. Multi-Language Configuration & Load Barrier Code

ZGC Execution Configuration & Load Barrier
zgc_config.sh
Java (ZGC Flags)
# Launch JVM with Generational ZGC & Sub-Millisecond Pause SLA
java -XX:+UseZGC \
     -XX:+ZGenerational \
     -Xms16g -Xmx64g \
     -XX:ZAllocationSpikeTolerance=5 \
     -jar high_frequency_trading.jar

5. Engineering Guidance

  1. Max Pause SLA: ZGC guarantees max STW pauses <1ms<1\text{ms} on JDK 21+.
  2. Generational ZGC: JDK 21 introduced generational collection, separating young and old objects to achieve up to 4×4\times higher throughput!