Java / JVM Architecture (Java21) Interview questions
What is Generational ZGC introduced in Java 21, and how does it differ from G1?
Generational ZGC, finalized in Java 21 via JEP 439, made ZGC's generational mode the default, replacing the earlier single-generation ZGC as the out-of-the-box behavior when -XX:+UseZGC is set.
Like G1, it now separates young and old objects to exploit the weak generational hypothesis, collecting the young generation far more often than the old one - but it keeps ZGC's core design of colored pointers and load barriers, which let almost all marking, relocation, and reference updating happen concurrently with running application threads.
The practical difference from G1 is pause time consistency: G1's pauses can grow somewhat with heap size and live-set size, while ZGC's pauses stay in the sub-millisecond range essentially independent of heap size, even on multi-terabyte heaps.
The trade-off is that ZGC's concurrent barriers add a small amount of constant per-access overhead and extra memory from multi-mapping, so G1 can still edge out ZGC on raw throughput for small-to-medium heaps with moderate latency requirements.
More Related questions...