The article G1: One Garbage Collector To Rule Them All gives a detailed description of G1 GC.
However, one thing I feel really confused is that why G1 GC did not have any marking information
after we've just finished a marking cycle phase. Before we can do a mixed GC, we still need to piggyback a young GC phase again for the mixed GC so as to collect non-empty old regions.
In the marking cycle, we have already done marking among the whole heap. In this case, we know what can be reclaimed in old regions. It makes me feel uncertain about the purpose of marking cycle phase.
I find that in slides: Garbage Collector Details and Tuning - AWS(page 41), Cleanup phase → recycles empty old regions
. In marking cycle phase, we only collect old regions that are completely empty.
Why can we not reclaim not completely empty old regions? We even need to postpone collecting non-empty(not completely empty) old regions in a mixed GC phase. Since I think mixed GC phase is not necessary, we can do collection immediately after the marking cycle phase.
Once G1 GC successfully completes the concurrent marking cycle, it has the information that it needs to start the old generation collection. Up until now, the collection of the old regions was not possible since G1 GC did not have any marking information associated with those regions. A collection that facilitates the compaction and evacuation of old generation is appropriately called a 'mixed' collection since G1 GC not only collects the eden and the survivor regions, but also (optionally) adds old regions to the mix. Let us now discuss some details that are important to understand a mixed collection.
I cannot understand why when we finish a marking cycle phase
, we still don't know any marking information associated with those regions.
Does those regions
mean those newly allocated objects in eden and survivor regions? Can we collect non-empty old regions during CleanUp
phase in a marking phase?