package com.mousycoder.mycode.thinking_in_jvm; /** * @version 1.0 * @author: mousycoder * @date: 2019-07-15 17:57 */ public class ScavengeBeforeFullGC { public static void main(String[] args) { System.gc(); } }
虚拟机参数
-XX:+PrintGCDetails -XX:+UseSerialGC
输出
[Full GC (System.gc()) [Tenured: 0K->493K(129792K), 0.0025750 secs] 910K->493K(130944K), [Metaspace: 2735K->2735K(1056768K)], 0.0028750 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] Heap def new generation total 58496K, used 1561K [0x0000000740000000, 0x0000000743f70000, 0x000000076aaa0000) eden space 52032K, 3% used [0x0000000740000000, 0x00000007401864f8, 0x00000007432d0000) from space 6464K, 0% used [0x00000007432d0000, 0x00000007432d0000, 0x0000000743920000) to space 6464K, 0% used [0x0000000743920000, 0x0000000743920000, 0x0000000743f70000) tenured generation total 129792K, used 493K [0x000000076aaa0000, 0x0000000772960000, 0x00000007c0000000) the space 129792K, 0% used [0x000000076aaa0000, 0x000000076ab1b5c0, 0x000000076ab1b600, 0x0000000772960000) Metaspace used 2744K, capacity 4486K, committed 4864K, reserved 1056768K class space used 297K, capacity 386K, committed 512K, reserved 1048576K
虚拟机参数
-XX:+PrintGCDetails -XX:+UseParallelOldGC
输出
[GC (System.gc()) [PSYoungGen: 797K->512K(1024K)] 805K->544K(130560K), 0.0007440 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] [Full GC (System.gc()) [PSYoungGen: 512K->0K(1024K)] [ParOldGen: 32K->493K(129536K)] 544K->493K(130560K), [Metaspace: 2738K->2738K(1056768K)], 0.0038530 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] Heap PSYoungGen total 1024K, used 5K [0x0000000795580000, 0x0000000795700000, 0x00000007c0000000) eden space 512K, 1% used [0x0000000795580000,0x00000007955815f0,0x0000000795600000) from space 512K, 0% used [0x0000000795680000,0x0000000795680000,0x0000000795700000) to space 512K, 0% used [0x0000000795600000,0x0000000795600000,0x0000000795680000) ParOldGen total 129536K, used 493K [0x0000000740000000, 0x0000000747e80000, 0x0000000795580000) object space 129536K, 0% used [0x0000000740000000,0x000000074007b5c0,0x0000000747e80000) Metaspace used 2744K, capacity 4486K, committed 4864K, reserved 1056768K class space used 297K, capacity 386K, committed 512K, reserved 1048576K
可见并行 GC 的时候,在 FULL GC 前多了一次新生代的 GC,好处是为了缩短停顿,避免所有工作交给 FULL GC