CMS garbage collector and G1 collector

CMS collector:

1 is a collector that aims to obtain the shortest collection pause time.

2 Implemented based on the "mark-sweep" algorithm

3 The operation process is as follows

1) Initial markup  

2) Concurrent marking

3) Relabel

4) Concurrent clearing

    The two steps of initial marking and re-marking still require "stop the world". Initial markup is fast.

4 Advantages and disadvantages of CMS

Main advantages: concurrent collection, low pauses.

Main disadvantages:

1) The CMS collector is very sensitive to CPU resources. In the concurrent phase, although it will not cause the user thread to stop, it will cause the application to slow down because a part of the thread is occupied, and the total throughput will be reduced.

2) The CMS collector cannot handle floating garbage, and a "Concurrent Mode Failure" failure may occur, resulting in a Full GC.

Floating garbage: Since the user thread is still running in the concurrent cleanup phase of the CMS, new garbage will naturally be generated as the program runs. After the marking process of this part of garbage, the CMS cannot deal with them in the current collection, so it has to Leave it for the next GC to clean up. This garbage is "floating garbage"

3) CMS is a collector implemented by a "mark-sweep" algorithm, which is prone to a large amount of space debris. When there are too many space fragments, it will bring a lot of trouble to the allocation of large objects. Often, there is still a lot of space left in the old age, but it cannot find a large enough continuous space to allocate the current object. It has to trigger a Full GC.


G1 collector

1 G1 is a garbage collector for server-side applications.

2 G1 has the following features:

1) Parallel to concurrency: G1 can make full use of the hardware advantages of CPU and multi-core environment, and use multiple CPUs (CPU or CPU core) to shorten the stop-The-World pause time. Some other collectors originally need to suspend the GC action executed by the Java thread, but the G1 collector can still allow the Java program to continue executing in a concurrent manner.

2) Generational collection: Although G1 can independently manage the entire GC heap without the cooperation of other collectors, it still retains the concept of generation. It can handle newly created objects and old objects that have survived for a while and survived multiple GCs in a different way to get better collection results.

3) 空间整合:与CMS的“标记--清理”算法不同,G1从整体来看是基于“标记整理”算法实现的收集器;从局部上来看是基于“复制”算法实现的。

4) 可预测的停顿:这是G1相对于CMS的另一个大优势,降低停顿时间是G1和CMS共同的关注点,但G1除了追求低停顿外,还能建立可预测的停顿时间模型,能让使用者明确指定在一个长度为M毫秒的时间片段内,

5) G1运作步骤:

 

初始标记--> 并发标记--> 最终标记-->筛选回收

初始标记:仅标记一下GC Roots能直接关联到的对象,这一阶段需要停顿线程,但是耗时很短,

并发标记:从GC Root开始对堆中对象进行可达性分析,找出存活的对象,这阶段时耗时较长,但可与用户程序并发执行。

最终标记:为了修正在并发标记期间因用户程序继续运作而导致标记产生变动的那一部分标记记录,这一阶段需要停顿线程,但是可并行执行。

筛选回收:首先对各个Region的回收价值和成本进行排序,根据用户所期望的GC停顿时间来制定回收计划。

 

 

 

 

 

 

 

来源

http://blog.csdn.net/linhu007/article/details/48897597

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326914683&siteId=291194637