jvm G1 garbage collector

Glossary:
    Parallel is =
    Concurrency is >

Serial: single thread, stop-the-world, -XX:+UseSerialGC
Parallel: multithreading, stop-the-world, -XX:+UseParallerGC
cms: The young generation is similar to the parallel collector, -XX:+UseConcurrentMarkSweepGC, the old generation collection thread and the application thread work at the same time, it will stop-the-world during initial marking and re-marking, Disadvantages: Competing with application threads for cpu, advantages : The pause is short, and the old age is occupied by the threshold, which is suitable for applications that pursue higher throughput and can tolerate longer GC pauses.


G1: Hybrid garbage collector, which splits the heap into a series of partitions, and most garbage collection operations are performed in only one partition for a period of time. The old generation and the young generation memory space can occupy each other. The young generation is collected in parallel. The old generation collection is performed by one partition. Only one block is collected at a time, and it will be accompanied by a young generation collection. When the old generation exceeds the heap occupancy threshold, a concurrent stop-the-world initial mark is performed.
Initial marking (simultaneous with the young generation) -> concurrent multi-threaded marking, marking the surviving objects of the old generation -> parallel remarking, marking the objects missed by the application thread during the initial marking -> when no one of the old generation survives object is cleared.
G1 pauses mostly young generation collections and mixed collections
The design goal of G1 is to limit a larger memory space and specify the GC pause time. He uses a heuristic algorithm
G1 partition size is between 1M-32M, which is a power of 2
There will be a collection of collection partitions during the collection process, called CSet
RSet (remembered set) Each partition has a memory set, which is used to remember references from outside the partition to the inside of the partition.
The young generation is divided into: eden (new generation) and survivor (survivor generation)
When the space occupancy of the old age reaches the occupancy threshold, the old age will be performed. The default is 45%, which can be set by -XX:InitiatingHeapOccupancyPercent.
Huge object: more than 50% of the partition, use continuous partition to store, if there is no continuous partition, fullGC will be started
The full GC of G1 is the same as the serial collection algorithm
G1周期有5个阶段:初始标记-》并发根分区扫描-》并发标记-》重新标记-》清除
初始标记:收集所有对象的起点,stop-the-world
根分区扫描: 并发的进行根分区扫描,不会暂停
并发标记:不会发生stop-the-world
重新标记:非常短暂的stop-the-world
清除:找出没有存活对象的分区并回收。
堆空间调整:G1整堆尺寸是分区尺寸的整倍数,对象分配失败后,会扩大堆尺寸,新建分区来存放对象。

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324725184&siteId=291194637