JVM-之GC日志

一、 开启gc 日志

在项目中开启GC 日志打印后会查看gc 日志如下

bash 复制代码
nohup java -Xms768m -Xmx768m  -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./dumplog/dumplog.log  -Xloggc:./dumplog/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintHeapAtGC  -jar xxxx.jar > logsxxx.log 2>&1 &

gc日志如下

bash 复制代码
ava HotSpot(TM) 64-Bit Server VM (25.341-b10) for linux-amd64 JRE (1.8.0_341-b10), built on Jun 16 2022 15:46:36 by "java_re" with gcc 7.3.0
Memory: 4k page, physical 65808024k(44853816k free), swap 33030140k(33030140k free)
CommandLine flags: -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=./dumplog/dumplog.log -XX:InitialHeapSize=805306368 -XX:MaxHeapSize=805306368 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintHeapAtGC -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC 
{Heap before GC invocations=1 (full 0):
 PSYoungGen      total 229376K, used 196608K [0x00000000f0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 196608K, 100% used [0x00000000f0000000,0x00000000fc000000,0x00000000fc000000)
  from space 32768K, 0% used [0x00000000fe000000,0x00000000fe000000,0x0000000100000000)
  to   space 32768K, 0% used [0x00000000fc000000,0x00000000fc000000,0x00000000fe000000)
 ParOldGen       total 524288K, used 0K [0x00000000d0000000, 0x00000000f0000000, 0x00000000f0000000)
  object space 524288K, 0% used [0x00000000d0000000,0x00000000d0000000,0x00000000f0000000)
 Metaspace       used 8770K, capacity 9102K, committed 9344K, reserved 1056768K
  class space    used 994K, capacity 1091K, committed 1152K, reserved 1048576K
2024-05-27T10:41:48.427+0800: 0.514: [GC (Allocation Failure) [PSYoungGen: 196608K->4724K(229376K)] 196608K->4732K(753664K), 0.0063968 secs] [Times: user=0.02 sys=0.00, real=0.00 secs] 
Heap after GC invocations=1 (full 0):
 PSYoungGen      total 229376K, used 4724K [0x00000000f0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 196608K, 0% used [0x00000000f0000000,0x00000000f0000000,0x00000000fc000000)
  from space 32768K, 14% used [0x00000000fc000000,0x00000000fc49d1b0,0x00000000fe000000)
  to   space 32768K, 0% used [0x00000000fe000000,0x00000000fe000000,0x0000000100000000)
 ParOldGen       total 524288K, used 8K [0x00000000d0000000, 0x00000000f0000000, 0x00000000f0000000)
  object space 524288K, 0% used [0x00000000d0000000,0x00000000d0002000,0x00000000f0000000)
 Metaspace       used 8770K, capacity 9102K, committed 9344K, reserved 1056768K
  class space    used 994K, capacity 1091K, committed 1152K, reserved 1048576K
}
{Heap before GC invocations=2 (full 0):
 PSYoungGen      total 229376K, used 201332K [0x00000000f0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 196608K, 100% used [0x00000000f0000000,0x00000000fc000000,0x00000000fc000000)
  from space 32768K, 14% used [0x00000000fc000000,0x00000000fc49d1b0,0x00000000fe000000)
  to   space 32768K, 0% used [0x00000000fe000000,0x00000000fe000000,0x0000000100000000)
 ParOldGen       total 524288K, used 8K [0x00000000d0000000, 0x00000000f0000000, 0x00000000f0000000)
  object space 524288K, 0% used [0x00000000d0000000,0x00000000d0002000,0x00000000f0000000)
 Metaspace       used 12742K, capacity 13228K, committed 13568K, reserved 1060864K
  class space    used 1547K, capacity 1706K, committed 1792K, reserved 1048576K
2024-05-27T10:41:48.632+0800: 0.719: [GC (Allocation Failure) [PSYoungGen: 201332K->5623K(229376K)] 201340K->5647K(753664K), 0.0056089 secs] [Times: user=0.01 sys=0.00, real=0.01 secs] 
Heap after GC invocations=2 (full 0):
 PSYoungGen      total 229376K, used 5623K [0x00000000f0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 196608K, 0% used [0x00000000f0000000,0x00000000f0000000,0x00000000fc000000)
  from space 32768K, 17% used [0x00000000fe000000,0x00000000fe57de18,0x0000000100000000)
  to   space 32768K, 0% used [0x00000000fc000000,0x00000000fc000000,0x00000000fe000000)
 ParOldGen       total 524288K, used 24K [0x00000000d0000000, 0x00000000f0000000, 0x00000000f0000000)
  object space 524288K, 0% used [0x00000000d0000000,0x00000000d0006000,0x00000000f0000000)
 Metaspace       used 12742K, capacity 13228K, committed 13568K, reserved 1060864K
  class space    used 1547K, capacity 1706K, committed 1792K, reserved 1048576K
}

在项目中如果需要查看使用的垃圾收集器出了使用GC 日志中去分析还可以使用如下命令

bash 复制代码
java -XX:+PrintCommandLineFlags -version  

二 GC 日志 Parallel Scavenge+Parallel Old 类型日志分析

jdk1.8以后-XX:+UseParallelGC是默认开启的,所以垃圾回收器的组合就是ps+po,ps+po 类型的垃圾回收器是jdk8 默认的垃圾回收器组合,JDK9 默认是G1垃圾回收器

bash 复制代码
2024-05-27T10:41:49.016+0800: 1.103: [GC (Metadata GC Threshold) [PSYoungGen: 201464K->8164K(229376K)] 201560K->8268K(753664K), 0.0099723 secs] [Times: user=0.03 sys=0.01, real=0.01 secs] 
Heap after GC invocations=4 (full 0):
 PSYoungGen      total 229376K, used 8164K [0x00000000f0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 196608K, 0% used [0x00000000f0000000,0x00000000f0000000,0x00000000fc000000)
  from space 32768K, 24% used [0x00000000fe000000,0x00000000fe7f93d0,0x0000000100000000)
  to   space 32768K, 0% used [0x00000000fc000000,0x00000000fc000000,0x00000000fe000000)
 ParOldGen       total 524288K, used 104K [0x00000000d0000000, 0x00000000f0000000, 0x00000000f0000000)
  object space 524288K, 0% used [0x00000000d0000000,0x00000000d001a010,0x00000000f0000000)
 Metaspace       used 20580K, capacity 21180K, committed 21248K, reserved 1067008K
  class space    used 2594K, capacity 2752K, committed 2816K, reserved 1048576K
}
{Heap before GC invocations=5 (full 1):
 PSYoungGen      total 229376K, used 8164K [0x00000000f0000000, 0x0000000100000000, 0x0000000100000000)
  eden space 196608K, 0% used [0x00000000f0000000,0x00000000f0000000,0x00000000fc000000)
  from space 32768K, 24% used [0x00000000fe000000,0x00000000fe7f93d0,0x0000000100000000)
  to   space 32768K, 0% used [0x00000000fc000000,0x00000000fc000000,0x00000000fe000000)
 ParOldGen       total 524288K, used 104K [0x00000000d0000000, 0x00000000f0000000, 0x00000000f0000000)
  object space 524288K, 0% used [0x00000000d0000000,0x00000000d001a010,0x00000000f0000000)
 Metaspace       used 20580K, capacity 21180K, committed 21248K, reserved 1067008K
  class space    used 2594K, capacity 2752K, committed 2816K, reserved 1048576K
2024-05-27T10:41:49.026+0800: 1.113: [Full GC (Metadata GC Threshold) [PSYoungGen: 8164K->0K(229376K)] [ParOldGen: 104K->8031K(524288K)] 8268K->8031K(753664K), [Metaspace: 20580K->20578K(1067008K)], 0.0254521 secs] [Times: user=0.09 sys=0.00, real=0.02 secs] 

PSYoungGen 表示的是由Parallel Scavenge垃圾收集器管理的新生代,ParOldGen表示由Parallel Old管理的老年代。

第一行:

PSYoungGen total 229376K, used 196608K [0x00000000f0000000, 0x0000000100000000, 0x0000000100000000)

Parallel Scavenge垃圾收集器管理的新生代 ,新生代 工229M 使用 196 M

借用其他图说明

Full GC日志

Full GC (Metadata GC Threshold) \[PSYoungGen: 8164K-\>0K(229376K)\] \[ParOldGen: 104K-\>8031K(524288K)\] 8268K-\>8031K(753664K), \[Metaspace: 20580K-\>20578K(1067008K)\], 0.0254521 secs\] \[Times: user=0.09 sys=0.00, real=0.02 secs

[Full GC (Metadata GC Threshold) 表示触发了完整垃圾回收的特定原因是元数据区域的垃圾回收阈值被触发。

相关推荐
CS创新实验室1 小时前
Python 对象“死“了之后去了哪?——引用计数与分代垃圾回收
开发语言·jvm·python
wuminyu4 小时前
JMM学习总结:深入理解happens-before关系
java·linux·c语言·jvm·c++
DongQiShanRen12 小时前
六根硬件映射(下):物理闭环五步法,抽一条已实装的看
大数据·jvm·人工智能·算法·rust·哈希算法·集成学习
乌暮12 小时前
从 `println` 到生产级日志:Spring Boot 日志体系完全指南
java·开发语言·jvm·spring boot·后端·学习·面试
Sayai14 小时前
Java 进程 Unable to create new native thread 排查实战:Linux 线程数五层限制与 JVM -Xss 调优
java·linux·运维·jvm·性能优化
wuminyu14 小时前
Continuation::freeze与thaw的x86_64汇编Stack Chunk拆解源码分析
java·linux·c语言·汇编·jvm·c++
金銀銅鐵1 天前
[Java] 借助GUI展示class文件的内容(v1.0版本)
jvm·后端·ai编程
kunicoding1 天前
多线程编程核心概念详解:从线程基础到并发安全
java·jvm·安全
云老大-阿里云国际站代理商1 天前
华为云国际站渠道代理商:CSS查询很慢但CPU不高?磁盘I/O、JVM与分片问题怎么排查
css·jvm·华为云
呆呆虫121 天前
SerpBase 省 credit 实战:缓存 + 去重,把重复请求砍掉一半
jvm·缓存