对象从新生代区域消失的过程,我们称之为 "minor GC"
对象从老年代区域消失的过程,我们称之为 "major GC"
Minor GC
清理整个YouGen的过程,eden的清理,S0\S1的清理都会由于MinorGC Allocation Failure(YoungGen 区内存不足),而触发minorGC
Major GC
OldGen区内存不足,触发Major GC
Full GC
Full GC 是清理整个堆空间—包括年轻代和永久代
Full GC 触发的场景
1)System.gc
2)promotion failed (年代晋升失败,比如eden区的存活对象晋升到S区放不下,又尝试直接晋 升到Old 区又放不下,那么Promotion Failed,会触发FullGC)
3)CMS的Concurrent-Mode-Failure 由于CMS回收过程中主要分为四步:
1⃣️CMS initial mark
2⃣️CMS Concurrent mark
3⃣️CMS remark
4⃣️CMS Concurrent sweep。
在2中gc线程与用户线程同时执行,那么用户线程依旧可 能同时产生垃圾, 如果这个垃圾较多无法放入预留的空间就会产生CMS-Mode-Failure, 切换 为SerialOld单线程做marksweep-compact。
4)新生代晋升的平均大小大于老年代的剩余空间 (为了避免新生代晋升到老年代失败) 当使用
G1,CMS 时,FullGC发生的时候 是 Serial+SerialOld。 当使用ParalOld时,FullGC发生的时候是
ParallNew +ParallOld.