JVM学习之1 GC日志理解

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/GoSaint/article/details/83654340

    为了观察GC日志,我们需要设置JVM启动参数:

    -XX:+PrintGCDetails-----------------------------表示详细的GC日志的输出

下面程序代码是我摘抄《深入理解JVM》这个本书上的一个示例;

public class RefrenceCountingGC {
    public Object instance =null;
    private static final int _1MB=1024*1024;
    private byte[] bigSize=new byte[2*_1MB];
    public static void main(String[] args) {
        RefrenceCountingGC refrenceCountingGC1=new RefrenceCountingGC();
        RefrenceCountingGC refrenceCountingGC2=new RefrenceCountingGC();
        refrenceCountingGC1.instance=refrenceCountingGC2;
        refrenceCountingGC2.instance=refrenceCountingGC1;
        refrenceCountingGC1=null;
        refrenceCountingGC2=null;
        System.gc();
    }
}

      

我是在Intellij下运行的,下面查看GC日志:

[GC (System.gc()) [PSYoungGen: 11112K->1865K(38400K)] 11112K->1873K(125952K), 0.0025381 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[Full GC (System.gc()) [PSYoungGen: 1865K->0K(38400K)] [ParOldGen: 8K->1765K(87552K)] 1873K->1765K(125952K), [Metaspace: 4781K->4781K(1056768K)], 0.0084446 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
Heap
 PSYoungGen      total 38400K, used 665K [0x00000000d5f80000, 0x00000000d8a00000, 0x0000000100000000)
  eden space 33280K, 2% used [0x00000000d5f80000,0x00000000d60267f0,0x00000000d8000000)
  from space 5120K, 0% used [0x00000000d8000000,0x00000000d8000000,0x00000000d8500000)
  to   space 5120K, 0% used [0x00000000d8500000,0x00000000d8500000,0x00000000d8a00000)
 ParOldGen       total 87552K, used 1765K [0x0000000081e00000, 0x0000000087380000, 0x00000000d5f80000)
  object space 87552K, 2% used [0x0000000081e00000,0x0000000081fb9668,0x0000000087380000)
 Metaspace       used 4849K, capacity 5112K, committed 5248K, reserved 1056768K
  class space    used 521K, capacity 536K, committed 640K, reserved 1048576K

分析第一句:

[GC (System.gc()) [PSYoungGen: 11112K->1865K(38400K)] 11112K->1873K(125952K), 0.0025381 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 

GC (System.gc():表示GC的类型为GC,这里的System.gc()的含义我是比较迷惑的,因为System.gc()会触发Full GC。可是这里并不是Full GC,而是GC。

[PSYoungGen: 11112K->1865K(38400K)]    PSYoungGen:表示新生代区域;11112K->1865K(38400K)表示该内存区域内存总容量为37.5M,垃圾回收前占用该块区域内存为10.85M,垃圾回收后为1.82M。11112K->1873K(125952K),前面的数据几乎不变,含义基本相同,后面的125952K表示java堆空间值为123M。0.0025381 secs表示GC占用该内存区域的时间,单位是秒。

[Times: user=0.00 sys=0.00, real=0.00 secs]   user代表进程在用户态消耗的CPU时间,sys代表代表进程在内核态消耗的CPU时间、real代表程序从开始到结束所用的时钟时间。这个时间包括其他进程使用的时间片和进程阻塞的时间(比如等待 I/O 完成)。

猜你喜欢

转载自blog.csdn.net/GoSaint/article/details/83654340