JVM—日志参数

一、概述

阅读分析虚拟机和垃圾收集器的日志是处理Java虚拟机内存问题必备的基础技能,下面列举一下学习过程中所接触到的日志参数

-XX:+PrintGC:输出Gc日志。类似: 一verbose:gc

  • jdk9后使用:-Xlog:gc

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

  • JDK 9之后使用-X-log: gc*

-XX: +PrintGCTimeStamps:输出GC的时间戳(以基准时间的形式)

-XX:+PrintGCDateStamps:输出GC的时间戳(以日期的形式,如2013一05一04T21 : 53:59.234+0800 )

-XX:+PrintHeapAtGC:在进行GC的前后打印出堆的信息

  • JDK 9之后使用-Xlog: gc+heap=debug:

-Xloggc:. . /logs/gc. log:日志文件的输出路径

二、详细概述

2.1 -XX:+PrintGC

打印GC行为,具体进行了几次GC,每次回收了多少内存

[GC (Allocation Failure)  15282K->14386K(58880K), 0.0031547 secs]
[GC (Allocation Failure)  29695K->29596K(58880K), 0.0036302 secs]
[Full GC (Ergonomics)  29596K->29389K(58880K), 0.0068183 secs]
[Full GC (Ergonomics)  44682K->44292K(58880K), 0.0040688 secs]

参数解析

GC、Full GC: GC的类型,GC只在新生代上进行,Full GC包括永久代(元空间),新生代, 老年代。
Allocation Failure: GC发生的原因,即内存分配失败
15282K->14386K:堆在GC前的使用大小和GC后的使用大小。
58880K:堆空间的总大小。
0.0084018 secs: GC耗时。
2.2 -XX:+PrintGCDetails

是上面PrintGC的详细信息,包括具体使用的垃圾收集器、更详细的GC耗时、堆内存的分配情况、新生代、老年代、元空间的回收及占用情况等,如下

[GC (Allocation Failure) [PSYoungGen: 15282K->2528K(17920K)] 15282K->14362K(58880K), 0.0034135 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
[GC (Allocation Failure) [PSYoungGen: 17837K->2480K(17920K)] 29671K->29516K(58880K), 0.0038755 secs] [Times: user=0.09 sys=0.02, real=0.00 secs] 
[Full GC (Ergonomics) [PSYoungGen: 2480K->0K(17920K)] [ParOldGen: 27036K->29389K(40960K)] 29516K->29389K(58880K), [Metaspace: 2927K->2927K(1056768K)], 0.0069195 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
[Full GC (Ergonomics) [PSYoungGen: 15292K->3400K(17920K)] [ParOldGen: 29389K->40891K(40960K)] 44682K->44292K(58880K), [Metaspace: 2927K->2927K(1056768K)], 0.0052698 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
Heap
 PSYoungGen      total 17920K, used 10075K [0x00000000fec00000, 0x0000000100000000, 0x0000000100000000)
  eden space 15360K, 65% used [0x00000000fec00000,0x00000000ff5d6d08,0x00000000ffb00000)
  from space 2560K, 0% used [0x00000000ffd80000,0x00000000ffd80000,0x0000000100000000)
  to   space 2560K, 0% used [0x00000000ffb00000,0x00000000ffb00000,0x00000000ffd80000)
 ParOldGen       total 40960K, used 40891K [0x00000000fc400000, 0x00000000fec00000, 0x00000000fec00000)
  object space 40960K, 99% used [0x00000000fc400000,0x00000000febeefb0,0x00000000fec00000)
 Metaspace       used 2933K, capacity 4496K, committed 4864K, reserved 1056768K
  class space    used 316K, capacity 388K, committed 512K, reserved 1048576K

参数解析

GC,Full FC:GC的类型,GC只在新生代上进行,Full GC包括永久代(元空间),新生代, 老年代。
Allocation Failure: GC原因,即内存分配失败
PSYoungGen:表示当前使用了Parallel Scavenge并行垃圾收集器进行新生代回收
ParOldGen:表示当前使用了Parallel Old并行垃圾收集器进行老年代回收
Metaspace: 元数据区GC前后大小的变化,JDK1.8中引入了元数据区以替代永久代
xxx secs : 指Gc花费的时间
Times: user: 指的是垃圾收集器花费的所有CPU时间,sys:花费在等待系统调用或系统事件的时间,real:GC从开始到结束的时间,包括其他进程占用时间片的实际时间。
Heap:整个堆内存的详细使用以及回收情况  
2.3 -XX:+PrintGCTimeStamps

此参数需要搭配上面两个参数之一使用,作用就是在GC信息前面加上了耗时时间

0.120: [GC (Allocation Failure) [PSYoungGen: 15282K->2528K(17920K)] 15282K->14322K(58880K), 0.0034063 secs] [Times: user=0.03 sys=0.06, real=0.00 secs] 
0.126: [GC (Allocation Failure) [PSYoungGen: 17837K->2548K(17920K)] 29631K->29484K(58880K), 0.0036538 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
0.129: [Full GC (Ergonomics) [PSYoungGen: 2548K->0K(17920K)] [ParOldGen: 26936K->29389K(40960K)] 29484K->29389K(58880K), [Metaspace: 2927K->2927K(1056768K)], 0.0080570 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
0.139: [Full GC (Ergonomics) [PSYoungGen: 15292K->3400K(17920K)] [ParOldGen: 29389K->40891K(40960K)] 44682K->44292K(58880K), [Metaspace: 2927K->2927K(1056768K)], 0.0037076 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
2.4 -XX:+PrintGCDateStamps

此参数也是需要搭配具体的日志信息输出参数来使用,用来输出当前时间以及所在时区,0800代表东八区

2020-07-12T14:14:11.158+0800: [GC (Allocation Failure) [PSYoungGen: 15282K->2528K(17920K)] 15282K->14362K(58880K), 0.0034974 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2020-07-12T14:14:11.164+0800: [GC (Allocation Failure) [PSYoungGen: 17837K->2464K(17920K)] 29671K->29500K(58880K), 0.0039444 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] 
2020-07-12T14:14:11.168+0800: [Full GC (Ergonomics) [PSYoungGen: 2464K->0K(17920K)] [ParOldGen: 27036K->29389K(40960K)] 29500K->29389K(58880K), [Metaspace: 2927K->2927K(1056768K)], 0.0069428 secs] [Times: user=0.00 sys=0.00, real=0.01 secs] 
2020-07-12T14:14:11.176+0800: [Full GC (Ergonomics) [PSYoungGen: 15292K->3400K(17920K)] [ParOldGen: 29389K->40891K(40960K)] 44682K->44292K(58880K), [Metaspace: 2927K->2927K(1056768K)], 0.0045931 secs] [Times: user=0.09 sys=0.02, real=0.00 secs]
2.5 说明

“GC"和"Full GC"说明了这次垃圾收集的停顿类型,如果有"Full"则说明GC发生了"STW”

使用Serial收集器在新生代的名字是De fault New Generation, 因此显示的是" DefNew"

使用ParNew收集器在新生代的名字会变成" ParNew",意思是"Parallel New Generation"

使用Parallel Scavenge收 集器在新生代的名字是" PSYoungGen"

老年代的收集和新生代道理一样,名字也是收集器决定的

使用G1收集器的话,会显示为"garbage一 first heap"

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值