This is a stop the world (STW) pause. Eden size and survivor size is calculated for the next young GC. Accounting information is kept to help calculate the size. Things like the pause time goal are taken into consideration.
This approach makes it very easy to resize regions, making them bigger or smaller as needed.
将活物撤离(即复制或移动)到一个或多个幸存者区域。 如果满足老化阈值,则某些对象将被提升到旧生成区域。
这是停止世界(STW)暂停。 计算下一个年轻GC的伊甸大小和幸存者大小。 保留会计信息以帮助计算大小。 需要考虑诸如暂停时间目标之类的事情。
这种方法使调整区域大小变得非常容易,可以根据需要增大或缩小区域。
5. End of a Young GC with G1
Live objects have been evacuated to survivor regions or to old generation regions
Recently promoted objects are shown in dark blue. 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.
活物已被疏散到幸存者地区或较老的地区
最近升级的对象以深蓝色显示。 幸存者区域为绿色。
总而言之,关于G1的年轻一代,可以说以下几点:
-堆是单个内存空间,分为多个区域。
-新生代内存由一组不连续的区域组成。 这使得在需要时易于调整大小。
-年轻一代的垃圾收集器或年轻的GC停止了世界大事。 将停止所有应用程序线程以进行操作。
-年轻的GC使用多个线程并行完成。
-将活动对象复制到新的幸存者或旧一代区域。
Old Generation Collection with G1
Like 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的旧系列
与CMS收集器类似,G1收集器被设计为用于旧对象的低暂停收集器。 下表描述了旧版本的G1收集阶段。
G1 Collection Phases - Concurrent Marking Cycle Phases
The G1 collector performs the following phases on the old generation of the heap. Note that some phases are part of a young generation collection.
Phase
Description
(1) Initial Mark (Stop the World Event)
This is a stop the world event. With G1, it is piggybacked on a normal young GC. Mark survivor regions (root regions) which may have references to objects in old generation.
(2) Root Region Scanning
Scan 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 Marking
Find 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 [GC pause (young)]. Or both young and old generation regions which are logged as [GC Pause (mixed)].
G1收集阶段-并行标记周期阶段
G1收集器在旧堆上执行以下阶段。请注意,某些阶段是年轻一代收藏的一部分。