Can someone explain how the G1 Garbage Collector works please? I haven't been able to find any comprehensive, easy-to-understand descriptions anywhere yet.
Thanks
Can someone explain how the G1 Garbage Collector works please? I haven't been able to find any comprehensive, easy-to-understand descriptions anywhere yet.
Thanks
The collector splits the heap up into fixed-size regions and tracks the live data in those regions. It keeps a set of pointers — the "remembered set" — into and out of the region. When a GC is deemed necessary, it collects the regions with less live data first (hence, "garbage first"). Often, this can mean collecting an entire region in one step: if the number of pointers into a region is zero, then it doesn't need to do a mark or sweep of that region.
For each region, it tracks various metrics that describe how long it will take to collect them. You can give it a soft real-time constraint about pause times, and it then tries to collect as much garbage as it can in that constrained time.
There is JavaOne talk about G1 and few articles on the topic:
The G1 is nicely explained also in this new JavaOne 2012 session : G1 Garbage Collector Performance Tuning [youtube], [PDF].
They start with introduction of CMS and G1, their comparison, and then the G1 analysis and tuning is explained.
G1 characteristics
A typical G1 heap may look like:
Here is a summary of each G1 phase:
1.1 Young Phase - Minor GC
1.2 Young / Initial Mark
2.1 Initial Mark - see 1.2.
2.2 GC remark
2.3. GC pause (mixed)
Note that G1 is intended to avoid Full GC as much as possible. As of Java 7u40, FullGC pauses in G1 are not optimized and are implemented as a single threaded operation. When using G1, try to avoid Full GC - if you see any FullGC pauses, your GC setup probably requires some tuning.
I found Oracle's page on this to be extremely helpful at explaining the concepts in an accessible manner without being too lengthy.
© 2022 - 2024 — McMap. All rights reserved.