G1's Region-Based Secret to Predictable Pauses

G1 GC divides the Java heap into fixed-size regions (1MB to 32MB by default), allowing it to collect garbage incrementally in smaller, prioritized segments, significantly reducing long 'stop-the-world' pauses compared to traditional collectors.

The top 3

  1. G1's Region Evacuation vs. Legacy Full Scans: G1 significantly reduces pause times by evacuating and compacting only select regions (young or high-garbage old) rather than the entire heap or generation, a distinct advantage over older collectors like Parallel GC's full heap compaction or CMS's lack of compaction.
  2. Remembered Sets: G1's Key to Localized Pauses: G1 leverages Remembered Sets (RSets) for each region to track incoming references from other regions. This mechanism allows G1 to perform localized garbage collection by scanning only specific regions and their RSets, avoiding a full heap scan and contributing to more predictable pause times.
  3. `MaxGCPauseMillis`: G1's Region-Driven Pause Target: The `-XX:MaxGCPauseMillis` flag guides G1's pause prediction model, which dynamically selects the optimal number of regions to collect within a given cycle to meet the desired pause time goal. This allows G1 to adjust its collection efforts based on runtime performance and user-defined latency targets.

Sources

Open the full topic