Understanding JVM Garbage Collectors: Memory Models, Generational and Region-Based Designs, and Low‑Latency Collectors
This article examines the evolution and classification of HotSpot JVM garbage collectors, explaining the performance triangle of heap usage, throughput and pause time, and detailing generational, region‑based, and low‑latency collectors such as G1, Shenandoah, and ZGC with their design principles and benchmark results.
The author, a Qunar engineer, reflects on the renewed interest in JVM garbage collection (GC) and introduces the modern GC landscape in OpenJDK 11, including Epsilon, ZGC, and Shenandoah, which correspond to JEP 333 and JEP 189. He questions how to compare GC performance across dimensions of heap memory usage, throughput without GC, and pause‑time latency.
Following the description in Zhou Zhiming’s Deep Understanding of the Java Virtual Machine , the three key metrics—heap memory consumption (including off‑heap auxiliary space), throughput without GC (impact of read/write barriers), and stop‑the‑world (STW) pause time—form an “impossible triangle” similar to CAP, forcing trade‑offs among them.
The article then classifies JVM heap memory into five regions and outlines four heap memory models: generational, partitioned, hybrid (generational + partitioned), and layered partitioned models, focusing primarily on the generational perspective.
Generational Model : Describes classic collectors (Serial, ParNew, Parallel Scavenge, Serial Old, Parallel Old, CMS) that separate young and old generations. It explains the three hypotheses—weak generational, strong generational, and cross‑generation reference—that justify generational collection, and discusses remembered sets (card tables) and write barriers.
Hybrid Generational‑Partitioned Model (G1) : Explains that G1 divides the heap into equal‑sized regions (Eden, Survivor, Old, Humongous), enabling predictable pause times by prioritizing regions with most garbage. G1 became the default collector in JDK 11, balancing throughput and latency.
Partitioned Model (Shenandoah) : Introduces Shenandoah as a low‑latency collector that also uses region‑based layout but eliminates generational separation. It employs a Connection Matrix instead of remembered sets to track cross‑region references, reducing memory overhead.
Layered Partitioned Model (ZGC) : Describes ZGC as a concurrent compacting collector using colored object pointers, load barriers, and multi‑mapping to achieve sub‑10 ms pauses regardless of heap size. It highlights ZGC’s reliance on colored pointers rather than object‑level metadata, and notes its similarity to the C4 collector.
The article presents benchmark data from SPECjbb® 2015 and other studies, showing ZGC’s superior throughput and latency compared to G1 and Shenandoah, while acknowledging that hardware constraints prevent simultaneously maximizing heap utilization, throughput, and low pause time.
In conclusion, the author summarizes the trade‑offs among the three performance dimensions and provides a reference table of the discussed collectors, emphasizing that the choice of GC depends on workload characteristics and hardware.
References include the JVM book by Zhou Zhiming, JEP 333 and JEP 189 specifications, and seminal papers on C4, Shenandoah, and generational scavenging.
Qunar Tech Salon
Qunar Tech Salon is a learning and exchange platform for Qunar engineers and industry peers. We share cutting-edge technology trends and topics, providing a free platform for mid-to-senior technical professionals to exchange and learn.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.