一、-XX:+PrintGCDetails 打印GC日志

参数配置:-Xms10M -Xmx10M -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCTimeStamps  -Xloggc:F:gc1.log

-Xloggc:输出到文件

2020-01-03T14:13:18.866+0800: 0.224: [GC (Allocation Failure) [PSYoungGen: 2048K->496K(2560K)] 2048K->744K(9728K), 0.0128127 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
2020-01-03T14:13:18.881+0800: 0.229: [GC (System.gc()) [PSYoungGen: 565K->496K(2560K)] 813K->752K(9728K), 0.0009625 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
2020-01-03T14:13:18.882+0800: 0.230: [Full GC (System.gc()) [PSYoungGen: 496K->0K(2560K)] [ParOldGen: 256K->675K(7168K)] 752K->675K(9728K), [Metaspace: 3460K->3460K(1056768K)], 0.0053436 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
2020-01-03T14:13:19.889+0800: 1.236: [GC (System.gc()) [PSYoungGen: 117K->128K(2560K)] 793K->803K(9728K), 0.0006856 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2020-01-03T14:13:19.889+0800: 1.237: [Full GC (System.gc()) [PSYoungGen: 128K->0K(2560K)] [ParOldGen: 675K->696K(7168K)] 803K->696K(9728K), [Metaspace: 3475K->3475K(1056768K)], 0.0057842 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
Heap
 PSYoungGen      total 2560K, used 59K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 2048K, 2% used [0x00000000ffd00000,0x00000000ffd0ecc0,0x00000000fff00000)
  from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
  to   space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
 ParOldGen       total 7168K, used 696K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
  object space 7168K, 9% used [0x00000000ff600000,0x00000000ff6ae138,0x00000000ffd00000)
 Metaspace       used 3481K, capacity 4500K, committed 4864K, reserved 1056768K
  class space    used 381K, capacity 388K, committed 512K, reserved 1048576K

第一行:2020-01-03T14:13:18.866+0800: 0.224: [GC (Allocation Failure) [PSYoungGen: 2048K->496K(2560K)] 2048K->744K(9728K), 0.0128127 secs] [Times: user=0.00 sys=0.00, real=0.01 secs]

GC (Allocation Failure):GC表示YoungGC年轻代垃圾回收;(Allocation Failure)表示内存分配失败;

[PSYoungGen: 2048K->496K(2560K)]:PSYoungGen表示年轻代使用的垃圾回收器是Paralle Scavenge  ;2048K表示年轻代垃圾回收前内存占用大小;496K表示年轻代垃圾回收后内存占用大小;(2560K)表示年轻代总大小;

2048K->744K(9728K):2048K表示堆内存垃圾回收前内存占用大小;744K表示堆内存垃圾回收后内存占用大小;(9728K)表示堆内存总大小;

0.0128127 secs:表示YoungGC耗时,单位秒

[Times: user=0.00 sys=0.00, real=0.01 secs]user=0.00表示用户耗时,sys=0.00表示系统耗时,real=0.01表示真实耗时,secs表示时间单位秒
第二行:2020-01-03T14:13:18.881+0800: 0.229: [GC (System.gc()) [PSYoungGen: 565K->496K(2560K)] 813K->752K(9728K), 0.0009625 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
 [GC (System.gc())表示系统显示调用gc
第三行:2020-01-03T14:13:18.882+0800: 0.230: [Full GC (System.gc()) [PSYoungGen: 496K->0K(2560K)] [ParOldGen: 256K->675K(7168K)] 752K->675K(9728K), [Metaspace: 3460K->3460K(1056768K)], 0.0053436 secs]
 [Full GC (System.gc()):Full GC表示YoungGC+OldGC(年轻代垃圾回收+年老代垃圾回收)即整个JVM内存的回收(除了方法区或者元空间);System.gc()表示系统显示调用GC

[PSYoungGen: 496K->0K(2560K)]:PSYoungGen表示年轻代使用的垃圾回收器是Paralle Scavenge  ;496K表示Full GC垃圾回收前内存占用大小;0K表示Full GC垃圾回收后内存占用大小(0是因为年轻代使用的是复制算法);(2560K)表示年轻代总大小;

752K->675K(9728K):752K表示Full GC垃圾回收前堆内存占用大小;675K表示Full GC垃圾回收后堆内存占用大小;(9728K)表示堆内存总大小;

ParOldGen: 256K->675K(7168K):ParOldGen表示老年代使用的垃圾回收器Parallel Old,256K表示Full GC垃圾回收前内存占用大小;675K表示Full GC垃圾回收后内存占用大小;(7168K)表示老年代总大小;

[Metaspace: 3460K->3460K(1056768K)]:Metaspace表示元空间本文使用JDK1.8,3460K:表示Full GC垃圾回收前Metaspace占用大小,3460K表示Full GC垃圾回收后Metaspace占用大小;(1056768K)表示Metaspace总大小。

Full GC分析下可以得出结论:
    新生代变化:496k-0L=496K 新生代减少了496k

    老年代变化:256k-675k=-419k(老年代增加了419k)
    Heap区变化:752k-675k=77K 整个堆减少了 77k
    496k – 77K =419K,说明该次共有419k内存从年轻代移到了老年代,可以看出来数量不少,说明大部分对象的生命周期较长。由于Full GC会引发stop  the word ,所以我们要尽量避免Full GC的发生,让对象尽可能的在老年代多呆会,所以这里可以增加老年轻代的大小。

第五行:

Heap
 PSYoungGen      total 2560K, used 59K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)
  eden space 2048K, 2% used [0x00000000ffd00000,0x00000000ffd0ecc0,0x00000000fff00000)
  from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)
  to   space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)
 ParOldGen       total 7168K, used 696K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)
  object space 7168K, 9% used [0x00000000ff600000,0x00000000ff6ae138,0x00000000ffd00000)
 Metaspace       used 3481K, capacity 4500K, committed 4864K, reserved 1056768K
  class space    used 381K, capacity 388K, committed 512K, reserved 1048576K

PSYoungGen total 2560K, used 59K:total 年轻代占用的总内存大小2560K,used:表示当前使用量
eden space 2048K, 2% used:年轻代的eden区占用的总内存大小2048K,used:已经使用2%
from space 512K, 0% used:年轻代的 from s1区占用的总内存大小512K,used:已经使用0%
to space 512K, 0% used:年轻代的 from s2区占用的总内存大小512K,used:已经使用0%
ParOldGen total 7168K:老年代的总内存大小
object space 7168K, 9% used:老年已使用9%

 -XX:NewRatio=2:年轻代与老年代的比值1:2, 但是根据实际数据显然年轻代没有占到整个堆的三分之一,很是费解?不知这种误差是否合理,在这里不吝赐教,求大神指点迷津。

内容来源于网络如有侵权请私信删除

文章来源: 博客园

原文链接: https://www.cnblogs.com/jalja365/p/12144938.html

你还没有登录,请先登录注册
  • 还没有人评论,欢迎说说您的想法!

相关课程

3692 0元 限免
4016 9.8元 98元 1折