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.
![Java JDK 21 JEP-439 Generational ZGC Java JDK 21 JEP-439 Generational ZGC](https://code2care.org/java-jdk-21/jdk-21-jep-439-an-improved-generational-z-garbage-collector-zgc/images/Java JDK 21 JEP-439 Generational ZGC.jpg)
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 backup a file in Linux/Unix - Linux
- Create React App using npm command with TypeScript - JavaScript
- How to Copy Entire Directory to another Directory in Linux - Linux
- How to know the current shell you are logged in? - Bash
- macOS Mail Fix: Authorization Error 400: invalid request - MacOS
- What is macOS Ventura? - MacOS
- Fix: Missing the following required SSO configuration values: sso_start_url, sso_region - AWS
- Android Error Generating Final Archive - Debug Certificate Expired - Android