此内存区域被分割为固定大小的区域。
区域大小是在JVM启动时确定的。 JVM通常有2,000个大小不同的32Mb空间。
thecolorsinthepictureshowswhichregionisassociatedwithwhichrole.liveobjectsareevacuated (I.e . copiedormoved (fromoneregiontoanother.regionsaredesignedtobecollectedinparallelwithorwithoutstoppingallotherapplicationthretionthrethretionthrer
asshownregionscanbeallocatedintoeden,survivor,andoldgenerationregions.in addition, thereisafourthtypeofobjectknownashumongousregions.theseregionsaredesignedtoholdobjectsthatare 50 % thesizeofastandardregionor fcontiguousregions.finallythelasttypeofregionswouldbetheunusedareasoftheheap。
note : at the time of this writing,collectinghumongousobjectshasnotbeenoptimized.therefore,youshouldavoidcreatingobjectsofted
theheapissplitintoapproximately 2000 regions.minimumsizeis1mbandmaximumsizeis 32m b.blueregionsholdoldgenerationobjectsandgreeeis
notethattheregionsarenotrequiredtobecontiguousliketheolderjjdds。
liveobjectsareevacuated(I.e .copied or moved ) tooneormoresurvivorregions.iftheagingthresholdismet,someoftheobjectsarrred
thisisastoptheworld(STW ) )。 pause.edensizeandsurvivorsizeiscalculatedforthenextyounggc.accountinginformationiskepttohelpcalculatethesize.thingsliketethete
thisapproachmakesitveryeasytoresizeregions,makingthembiggerorsmallerasneeded。
endofayounggcwithxnd/strongkddw/pliveobjectshavebeenevacuatedtosurvivorregionsortooldgenerationregions。
recentlypromotedobjectsareshownindarkbl
ue. Survivor regions in green.In summary, the following can be said about the young generation in G1:
The heap is a single memory space split into regions.Young generation memory is composed of a set of non-contiguous regions. This makes it easy to resize when needed.Young generation garbage collections, or young GCs, are stop the world events. All application threads are stopped for the operation.The young GC is done in parallel using multiple threads.Live objects are copied to new survivor or old generation regions. Old Generation Collection with G1Like the CMS collector, the G1 collector is designed to be a low pause collector for old generation objects. The following table describes the G1 collection phases on old generation.
G1 Collection Phases - Concurrent gxdlsing Cycle PhasesThe G1 collector performs the following phases on the old generation of the heap. Note that some phases are part of a young generation collection.
PhaseDescription(1) Initial gxdls(Stop the World Event)This is a stop the world event. With G1, it is piggybacked on a normal young GC. gxdls survivor regions (root regions) which may have references to objects in old generation.(2) Root Region ScanningScan survivor regions for references into the old generation. This happens while the application continues to run. The phase must be completed before a young GC can occur.(3) Concurrent gxdlsingFind live objects over the entire heap. This happens while the application is running. This phase can be interrupted by young generation garbage collections.(4) Remark
(Stop the World Event)Completes the marking of live object in the heap. Uses an algorithm called snapshot-at-the-beginning (SATB) which is much faster than what was used in the CMS collector.(5) Cleanup
(Stop the World Event and Concurrent) Performs accounting on live objects and completely free regions. (Stop the world)Scrubs the Remembered Sets. (Stop the world)Reset the empty regions and return them to the free list. (Concurrent)(*) Copying
(Stop the World Event)These are the stop the world pauses to evacuate or copy live objects to new unused regions. This can be done with young generation regions which are logged as htddx pause (young)]. Or both young and old generation regions which are logged as htddx Pause (mixed)]. G1 Old Generation Collection Step by Step
With the phases defined, let's look at how they interact with the old generation in the G1 collector.
Initial marking of live object is piggybacked on a young generation garbage collection. In the logs this is noted as GC pause (young)(inital-mark).
If empty regions are found (as denoted by the "X"), they are removed immediately in the Remark phase. Also, "accounting" information that determines liveness is calculated.
Empty regions are removed and reclaimed. Region liveness is now calculated for all regions. The regions selected have been collected and compacted into the dark blue region and the dark green region shown in the diagram. In summary, there are a few key points we can make about the G1 garbage collection on the old generation. 【参考资料】 1. Oarcle . http://www.oracle.com/technetwork/tutorials/tutorials-1876574.html