Java / Java 17 Garbage Collection Interview Questions
What is the difference between G1 GC's young-only phase and space-reclamation phase?
G1 alternates between two operating phases over its lifetime. During the young-only phase, every evacuation pause collects only young-generation regions (Eden and survivors) - no old regions are touched - occasionally piggybacking an Initial Mark onto one of these pauses once old-gen occupancy crosses the IHOP threshold.
Once the concurrent marking cycle that Initial Mark kicked off finishes (through Root Region Scan, Concurrent Mark, Remark, and Cleanup), G1 enters the space-reclamation phase: a run of mixed collections that combine young regions with a batch of the highest-garbage old regions identified during marking, incrementally reclaiming old-gen space across multiple pauses.
That run of mixed collections continues until -XX:G1MixedGCCountTarget is reached or remaining reclaimable garbage drops below -XX:G1HeapWastePercent, at which point G1 reverts to the young-only phase and waits for old-gen occupancy to climb back past IHOP before the cycle repeats.
More Related questions...