1、CMS及其执行过程?
CMS,全称Concurrent Mark and Sweep,用于对年老代进行回收,目标是尽量减少应用的暂停时间,减少full gc发生的机率,利用和应用程序线程并发的垃圾回收线程来标记清除年老代。CMS并非没有暂停,而是用两次短暂停来替代串行标记整理算法的长暂停。
内外的设置正常收集周期是这样的:
1)CMS-initial-mark 初始标记
2)CMS-concurrent-mark 并发标记的
3)CMS-concurrent-preclean 执行预清理 注: 相当于两次 concurrent-mark. 因为上一次c mark,太长.会有很多 changed object 出现.先干掉这波.到最好的 stop the world 的 remark 阶段,changed object 会少很多.
4)CMS-concurrent-abortable-preclean 执行可中止预清理
5)CMS-remark 重新标记
6)CMS-concurrent-sweep 并发清除
7)CMS-concurrent-reset 并发重设状态等待下次CMS的触发其中,CMS-initial-mark和CMS-remark会stop-the-world。
2、为什么 CMS两次标记时要 stop the world?</