What is Z Garbage Collector (ZGC)?
The Z Garbage Collector (ZGC) is a Java garbage collector designed for low-latency and high-scalability memory management. It helps to minimize the application pause times by efficiently reclaiming memory, making it suitable for real-time and responsive Java applications.
ZGC was introduced as an experimental feature in JDK 11 and became a production-ready feature in JDK 15 version.
The time-line of Z Garbage Collector (ZGC)
Java Version | ZGC JEP | JEP Details |
---|---|---|
JDK 11 | JEP 333 | ZGC: A Scalable Low-Latency Garbage Collector (Experimental) |
JDK 13 | JEP 351 | ZGC: Uncommit Unused Memory |
JDK 14 | JEP 364 | ZGC on macOS |
JDK 14 | JEP 365 | ZGC on Windows |
JDK 15 | JEP 377 | ZGC: A Scalable Low-Latency Garbage Collector |
JDK 16 | JEP 376 | ZGC: Concurrent Thread-Stack Processing |
JDK 21 | JEP 439 | Generational ZGC |
What's new in JDK 21 - Z Garbage Collector (ZGC)?
JEP 439 introduces the Generational ZGC, which maintains separate generations for young and old objects.
This separation between generations enables for more frequent collection of young objects, improving application performance and thus reducing allocation stalls, heap memory overhead, and garbage collection CPU overhead, all while maintaining low pause times and minimal manual configuration.
The ultimate objective is to make Generational ZGC the default option and replace the non-generational version to reduce long-term maintenance costs.
Key Design Concepts:
- Generational ZGC splits the heap into young and old generations, collecting them independently to focus on young objects.
- Colored pointers, load barriers, and store barriers manage object references and ensure consistent object graph views.
- SATB (Snapshot at the Beginning) marking tracks references between objects during marking phases.
- Optimized barriers include fast paths, minimizing load barrier responsibilities, remembered-set barriers, and fused store barrier checks.
- Store barrier buffers and barrier patching reduce overhead in barrier code.
- Double-buffered remembered sets and dense heap regions optimize the handling of inter-generational pointers.
- Large objects can be allocated to the young generation and promoted if necessary.
- Full garbage collections involve young-generation collections alongside old-generation marking phases.
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- Installing Java JDK 21 Final Release Candidate
- Steps to Install Java 21 (LTS JDK) on Windows 11
- How to install and Use Java JDK 21 Initial Release Candidate
- How to Enable Java JDK 21 Preview Features on IntelliJ
- Setting Up VS Code with Java JDK 21
- Java JDK 21 LTS Version Release Date (General Availability)
- [JEP 430] Java JDK 21 New Feature - String Templates (Preview)
- How to use Java JDK 21 with IntelliJ
- Java JDK 21: JEP 439 - An Improved Generational Z Garbage Collector (ZGC)
- [JEP 431] Java JDK 21 New Feature - Sequenced Collections
- Java JDK 21 - The Latest LTS Version
- Java JDK 21 - JEP 440 - Record Patterns
- Fix - Unsupported major.minor version 65.0 (Java JDK 21)
- How to Make Your Own Cross Platform Custom Notepad Application [Windows/Mac/Linux] - Python
- macOS Mail Fix: Authorization Error 400: invalid request - MacOS
- [Java] NoClassDefFoundError Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory - Java
- How to add to PATH in macOS Big Sur - MacOS
- How to Install Microsoft Teams App on M1 or M2 Mac - Teams
- [Java Program] Get Dates between Dates using Java 8 Predicate Functional Interface - Java
- Open PowerShell Terminal in Visual Studio Code (VSCode) - Powershell
- Fix: TypeError: set object is not subscriptable - Python