Fundamentals 11 min read

Understanding ZGC: A Low‑Latency Garbage Collector for Java

The article explains ZGC, Oracle's low‑latency Java garbage collector introduced in JDK 11, covering its dynamic region layout, colored pointer technique, tri‑color marking, memory multi‑mapping, read barriers, operation phases, performance characteristics, and its main drawback of floating garbage.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Understanding ZGC: A Low‑Latency Garbage Collector for Java

Overview

ZGC (Z Garbage Collector) is an Oracle‑developed low‑latency collector introduced experimentally in JDK 11, capable of handling up to 4 TB heap with pause times under 10 ms.

Dynamic Regions

ZGC divides the heap into Small (2 MB), Medium (32 MB) and Large (multiple of 2 MB) Regions, each serving objects of different size ranges.

Colored Pointer Technique

Instead of separate mark structures, ZGC stores mark bits directly in the high bits of 64‑bit pointers, using four flag bits for finalizable, remapped, and two color bits, leaving 42 bits for a 4 TB address space.

Tri‑color Marking

Objects are colored white, gray, or black during concurrent reachability analysis; object‑disappearance problems are avoided by incremental update or snapshot‑at‑the‑beginning (SATB) techniques.

Memory Multi‑Mapping

ZGC maps several virtual addresses to the same physical memory, allowing the colored pointer to address a larger virtual space than the actual heap.

Read Barrier

Load barriers check the colored pointer’s mark bits; if an object has moved, a one‑time “self‑healing” access redirects to the new location.

ZGC Operation Phases

The collector proceeds through concurrent mark, prepare for relocate (building the relocation set), concurrent relocate (copying live objects and building forward tables), and concurrent remap (updating references, merged into the next mark phase).

Issues and Solutions

The main drawback is “floating garbage” caused by the non‑generational design, which can be mitigated by increasing heap size or adding a generational layer.

Performance

Benchmarks show sub‑10 ms pauses and throughput comparable to Parallel Scavenge, surpassing G1, while using modest extra memory.

Pros & Cons

Pros: low pause, high throughput, low extra memory. Cons: floating garbage.

Reference

Source: “深入理解JAVA虚拟机”.

JavaMemory ManagementGarbage CollectionZGCLow LatencyConcurrent Marking
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.