HotSpot JVM Non-Generational Garbage Collectors - ZGC (Z Garbage Collector)

Modern garbage collectors like G1, Shenandoah, and ZGC are designed to address the challenges of large heaps, low-latency requirements, and scalability. Unlike traditional generational collectors, these collectors do not strictly separate the heap into young and old generations, but rather operate on region-based memory layouts for more flexibility and performance.

Note: While G1 is still technically generational, its region-based and incremental nature blurs the line. Shenandoah and ZGC, however, are truly non-generational.

Overview

Key Innovations

Features

Compared to Shenandoah

Aspect ZGC Shenandoah
Core Technique Colored Pointers + Load Barriers Brooks Pointers + Read Barriers
Pause Time < 10ms Low (but typically longer)
Max Heap Size 16 TB+ 4 TB
Barrier Overhead Lower Slightly higher
Ideal Use Case Ultra-large heap + low-latency Responsive UI and backends

Colored Pointer

A Colored Pointer is a technique used in some garbage collectors—most notably ZGC—to embed metadata directly into the object reference (pointer) itself.

This metadata encodes information about the GC state of the object, such as,

Modern 64-bit systems do not use all 64 bits of memory addresses. For example, on most systems,

ZGC leverages these spare bits to store GC-related metadata—these are the “colors” in the pointer.