Parallel Scavenge收集器-GC日志分析

1) jvm参数配置

                 默认使用的就是Parallel Scavenge收集器

                 也可以通过 -XX:+UseParallelGC 来配置

-Xms10m -Xmx10m -XX:SurvivorRatio=2 -XX:+PrintGCDetails -XX:NewRatio=2

 2)代码

package com.roger.jvmparam;

public class JvmParamMain {

    public static void main(String[] args) {

        byte[] b = null;
        for (int i = 0; i < 10; i++) {
            b = new byte[1 * 1024 * 1024];
        }
    }
}

3.控制台打印

[GC (Allocation Failure) [PSYoungGen: 1930K->488K(2560K)] 8074K->6832K(9728K), 0.0023006 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) --[PSYoungGen: 1512K->1512K(2560K)] 7856K->7856K(9728K), 0.0211116 secs] [Times: user=0.03 sys=0.00, real=0.02 secs] 
[Full GC (Ergonomics) [PSYoungGen: 1512K->0K(2560K)] [ParOldGen: 6344K->1655K(7168K)] 7856K->1655K(9728K), [Metaspace: 3462K->3462K(1056768K)], 0.0060138 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
Heap
 PSYoungGen      total 2560K, used 1067K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 2048K, 52% used [0x00000000ffd00000,0x00000000ffe0af48,0x00000000fff00000)
  from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
  to   space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
 ParOldGen       total 7168K, used 3703K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
  object space 7168K, 51% used [0x00000000ff600000,0x00000000ff99dc80,0x00000000ffd00000)
 Metaspace       used 3470K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 384K, capacity 388K, committed 512K, reserved 1048576K

4.概念

 GC日志参数                                                        含义
PSYoungGen 新生代,这个名称由收集器决定。PS是Parallel Scavenge收集器的缩写
ParOldGen Parallel Scavenge收集器配套的老年代
Metaspace  Parallel Scavenge收集器配套的永久代
total & used 总的空间和用掉的空间

5.具体分析

GC (Allocation Failure)-GC类型表示Major GC
Full GC (Ergonomics) -GC类型表示Full GC

[PSYoungGen: 1946K->504K(2560K)] 
[新生代:gc回收前该内存区域已使用容量->gc回收后该内存区域使用容量(该内存区域的总容量)]

也就说:新生代 gc回收前:该区域已使用1946k
              gc回收后:该区域已使用504k
              gc释放了 1946 - 504 = 1442 k的空间
       新生代的总大小为:2560k

[ParOldGen: 6344K->1680K(7168K)] ---老年代类比新生代

[Metaspace: 3486K->3486K(1056768K)] ---永久代类别新生代

8090K->6840K(9728K), 0.0019093 secs
gc前Java堆已使用容量->gc后Java堆已使用容量(Java堆的总容量-已分配), PSYoungGen回收gc耗时

也就是说 gc释放了 8090 - 6040 = 2050k的空间
        Java堆已分配的大小为 9728k

[Times: user=0.00 sys=0.00, real=0.00 secs] 
[Times: 用户消耗的cpu时间 内核态消耗的cpu时间, 操作从开始到结束所经过的墙钟时间即实际消耗的时间]

也就是说 user+sys是cpu时间
        cpu时间和墙钟时间的差别是,墙钟时间包括各种非运算的等待耗时,
       例如等待磁盘I/O、等待线程阻塞,而cpu时间不包括这些耗时。

6.规律

[名称:gc前内存占用-> gc后内存占用(该区内存总大小)]

7.-Xms10m -Xmx10m -XX:SurvivorRatio=2 -XX:NewRatio=2

      初始堆大小为10M,堆可用最大为10m,from区: eden区 : = 1 : 2, 新生代:老年代 = 1 : 2

Heap
 PSYoungGen      total 2560K, used 1076K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 2048K, 52% used [0x00000000ffd00000,0x00000000ffe0d0b0,0x00000000fff00000)
  from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
  to   space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
 ParOldGen       total 7168K, used 3713K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
  object space 7168K, 51% used [0x00000000ff600000,0x00000000ff9a04b0,0x00000000ffd00000)


新生代总大小:2048 + 512 + 512 = 3072k
老年代总大小:7168k

新生代 : 老年代 ≈ 1 : 2


这里的from区和eden区不符合所设置的比例,是因为堆的大小关系,堆的空间大小太小了,
如果把堆的大小扩大 这个jvm参数-XX:SurvivorRatio才会起作用

猜你喜欢

转载自blog.csdn.net/lihongtai/article/details/84565297