Backend Development 10 min read

Understanding the G1 Garbage Collector in Java: Detailed Process and Log Analysis

This article explains the G1 (Garbage‑First) garbage collector introduced in JDK7, its region‑based architecture, key differences from CMS, and the complete GC cycle—including Young GC, concurrent phases, mixed GC, and Full GC—while providing real‑world log examples and performance insights for Java developers.

Architect's Tech Stack
Architect's Tech Stack
Architect's Tech Stack
Understanding the G1 Garbage Collector in Java: Detailed Process and Log Analysis

G1 (Garbage First) is a modern garbage collector introduced in JDK7 and set as the default in JDK9; it partitions the heap into regions, weakening the traditional generational model and improving space reclamation.

Compared with CMS, G1 offers region‑based memory layout, better space compression, flexible pause‑time targets, and concurrent phases that avoid stop‑the‑world pauses for most work.

Complete G1 GC Process

G1 GC consists of four main operations: Young GC (YGC), concurrent phases, mixed GC, and Full GC.

YGC

YGC clears the Eden region when it fills, moves live objects to Survivor or Old regions, and can be observed via PrintGCDetails logs. Example log snippet:

23.430:[GC pause (young),0.23094400 secs] ...

Interpretation: Young GC took 230 ms, with GC threads using 850 ms CPU time; Eden reduced from 1286 MB to 0 B, Survivors grew from 78 MB to 152 MB, and heap usage dropped from 1454 MB to 242 MB.

Concurrent Phase

During the concurrent phase G1 scans root regions, marks regions with the most reclaimable garbage (X regions), and may pause briefly for initial marking. Sample logs show the start and end of concurrent root scanning and marking.

50.541:[GC concurrent-root-region-scan-start] ...

Mixed GC

Mixed GC combines a YGC with reclamation of previously marked X regions, reducing heap fragmentation. Example mixed GC log:

79.826:[GC pause (mixed),0.26161600 secs] ...

After mixed GC, Eden is emptied, some Survivor objects are promoted, and a portion of Old space is reclaimed.

Overall, G1 repeatedly cycles through these phases, providing predictable pause times and better memory compaction compared with CMS, making it suitable for multi‑core servers with large heap sizes.

Follow the "SouYunKu" technical team for more articles and updates.

JavaJVMGarbage CollectionPerformance TuningG1 GCGC Logs
Architect's Tech Stack
Written by

Architect's Tech Stack

Java backend, microservices, distributed systems, containerized programming, and more.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.