CMS垃圾回收的7个重要阶段

1.CMS-initial-mark 初始标记(CMS的第一个STW阶段),标记GC Root直接引用的对象,GC Root直接引用的对象不多,所以很快。

2.CMS-concurrent-mark 并发标记阶段,由第一阶段标记过的对象出发,所有可达的对象都在本阶段标记。

3.CMS-concurrent-preclean/Rescan (parallel) 并发预清理阶段,也是一个并发执行的阶段。在本阶段,会查找前一阶段执行过程中,从新生代晋升或新分配或被更新的对象。通过并发地重新扫描这些对象,预清理阶段可以减少下一个stop-the-world 重新标记阶段的工作量。

4.CMS-concurrent-abortable-preclean 并发可中止的预清理阶段。这个阶段其实跟上一个阶段做的东西一样,也是为了减少下一个STW重新标记阶段的工作量。增加这一阶段是为了让我们可以控制这个阶段的结束时机,比如扫描多长时间(默认5秒)或者Eden区使用占比达到期望比例(默认50%)就结束本阶段。

5.CMS-remark 重标记阶段(CMS的第二个STW阶段),暂停所有用户线程,从GC Root开始重新扫描整堆,标记存活的对象。需要注意的是,虽然CMS只回收老年代的垃圾对象,但是这个阶段依然需要扫描新生代,因为很多GC Root都在新生代,而这些GC Root指向的对象又在老年代,这称为“跨代引用”。

6.CMS-concurrent-sweep ,并发清理。

7.CMS-concurrent-reset,重置。

2020-03-08T01:09:46.390+0800: 6253.734: [GC [1 CMS-initial-mark: 1945758K(2097152K)] 2079340K(11084992K), 0.1071190 secs] [Times: user=0.11 sys=0.00, real=0.11 secs] 
2020-03-08T01:09:46.499+0800: 6253.842: [CMS-concurrent-mark-start]
2020-03-08T01:09:47.188+0800: 6254.531: [CMS-concurrent-mark: 0.689/0.689 secs] [Times: user=4.31 sys=0.52, real=0.69 secs] 
2020-03-08T01:09:47.189+0800: 6254.532: [CMS-concurrent-preclean-start]
2020-03-08T01:09:47.212+0800: 6254.555: [CMS-concurrent-preclean: 0.021/0.023 secs] [Times: user=0.03 sys=0.00, real=0.02 secs] 
2020-03-08T01:09:47.212+0800: 6254.555: [CMS-concurrent-abortable-preclean-start]
 CMS: abort preclean due to time 2020-03-08T01:09:52.995+0800: 6260.338: [CMS-concurrent-abortable-preclean: 5.762/5.782 secs] [Times: user=24.38 sys=2.73, real=5.79 secs] 
2020-03-08T01:09:53.092+0800: 6260.435: [Rescan (parallel) , 0.0388170 secs]2020-03-08T01:09:53.131+0800: 6260.474: [weak refs processing, 0.0000360 secs]2020-03-08T01:09:53.131+0800: 6260.474: [scrub string table, 0.0219010 secs] [1 CMS-remark: 1949195K(2097152K)] 2116443K(11084992K), 0.1540610 secs] [Times: user=0.93 sys=0.01, real=0.15 secs] 
2020-03-08T01:09:53.154+0800: 6260.497: [CMS-concurrent-sweep-start]
2020-03-08T01:09:55.067+0800: 6262.410: [CMS-concurrent-sweep: 1.913/1.913 secs] [Times: user=9.52 sys=1.15, real=1.91 secs] 
2020-03-08T01:09:55.068+0800: 6262.411: [CMS-concurrent-reset-start]
2020-03-08T01:09:55.080+0800: 6262.423: [CMS-concurrent-reset: 0.012/0.012 secs] [Times: user=0.08 sys=0.01, real=0.01 secs] 
2020-03-08T01:45:52.240+0800: 8419.583: [GC [1 CMS-initial-mark: 1932441K(2097152K)] 2058634K(11084992K), 0.1032350 secs] [Times: user=0.10 sys=0.00, real=0.10 secs] 
2020-03-08T01:45:52.345+0800: 8419.688: [CMS-concurrent-mark-start]
2020-03-08T01:45:53.173+0800: 8420.517: [CMS-concurrent-mark: 0.829/0.829 secs] [Times: user=5.06 sys=0.54, real=0.83 secs] 
2020-03-08T01:45:53.174+0800: 8420.517: [CMS-concurrent-preclean-start]
2020-03-08T01:45:53.198+0800: 8420.541: [CMS-concurrent-preclean: 0.022/0.024 secs] [Times: user=0.04 sys=0.00, real=0.02 secs] 
2020-03-08T01:45:53.199+0800: 8420.542: [CMS-concurrent-abortable-preclean-start]
 CMS: abort preclean due to time 2020-03-08T01:45:58.235+0800: 8425.578: [CMS-concurrent-abortable-preclean: 5.025/5.036 secs] [Times: user=23.74 sys=2.77, real=5.04 secs] 
2020-03-08T01:45:58.344+0800: 8425.687: [Rescan (parallel) , 0.0408230 secs]2020-03-08T01:45:58.385+0800: 8425.728: [weak refs processing, 0.0000470 secs]2020-03-08T01:45:58.385+0800: 8425.728: [scrub string table, 0.0260130 secs] [1 CMS-remark: 1947880K(2097152K)] 2067301K(11084992K), 0.1721870 secs] [Times: user=1.05 sys=0.01, real=0.17 secs] 
2020-03-08T01:45:58.413+0800: 8425.756: [CMS-concurrent-sweep-start]
2020-03-08T01:46:00.548+0800: 8427.891: [CMS-concurrent-sweep: 2.135/2.135 secs] [Times: user=10.55 sys=1.28, real=2.14 secs] 
2020-03-08T01:46:00.549+0800: 8427.892: [CMS-concurrent-reset-start]
2020-03-08T01:46:00.555+0800: 8427.898: [CMS-concurrent-reset: 0.007/0.007 secs] [Times: user=0.04 sys=0.01, real=0.01 secs] 
image.png

你可能感兴趣的:(CMS垃圾回收的7个重要阶段)