简体   繁体   中英

G1GC compaction within regions

As I understand, G1 GC performs evacuation to reclaim heap from both young and old regions, in doing so it indirectly compacts heap (copying live objects from a to-be-collected region to an empty region). Could G1 GC get into a case where there are no fully empty regions left to copy objects to but there is enough fragmented heap in semi-full regions? I wanted to ask, does G1 keeps track of free space within the regions, and does it do compacting within a region?

The HotSpot VM Garbage Collection Tuning Guide says in the Allocation (Evacuation) Failure section:

If a free (empty) region cannot be found during the evacuation of a region being garbage collected, then an allocation failure occurs (because there is no space to allocate the live objects from the region being evacuated) and a stop-the-world (STW) full collection is done.

This implies, though not stated explicitly, that the STW full collection is capable of performing compacting, as otherwise, it wouldn't be a cure for the fragmentation problem. I only found an indirect hint about compacting capabilities in the section about Humongous Objects and Humongous Allocations :

To reduce copying overhead, the humongous objects are not included in any evacuation pause. A full garbage collection cycle compacts humongous objects in place.

This does not imply that “G1 keeps track of free space within the regions”, as that would defeat the purpose of performing copying by default, but rather, this necessary information will likely be acquired during the full collection, as part of the process.

when will be G1 ( Garbage Collector) starts running and in which memory area it collect first?

The pile is divided into a lot of equivalent estimated pile areas, each a touching scope of virtual memory. Certain district sets are allocated similar jobs (eden, survivor, old)

G1 plays out a simultaneous worldwide stamping stage to decide the liveness of items all through the pile. After the imprint stage finishes, G1 knows which districts are for the most part unfilled. It gathers in these districts first, which as a rule yields a lot of free space. This is the reason this strategy for trash assortment is called Garbage-First. As the name proposes, G1 concentrates its assortment and compaction movement on the regions of the stack that are probably going to be loaded with reclaimable articles, that is, trash. G1 utilizes an interruption forecast model to meet a client characterized stop time target and chooses the quantity of locales to gather dependent on the predetermined respite time target.

The locales distinguished by G1 as ready for recovery are trash gathered utilizing clearing. G1 duplicates objects from at least one locales of the store to a solitary district on the stack, and in the process the two compacts and opens up memory. This departure is performed in parallel on multi-processors, to diminish stop times and increment throughput. In this manner, with every trash assortment, G1 consistently attempts to decrease fracture, working inside the client characterized delay times. This is past the ability of both the past techniques.

Basically, The amount of live data in each region is tracked, and when a collection is triggered the G1GC will clear the ones with the most 'garbage' first.

This means it can collect garbage from semi-full regions as well.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM