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) 表示触发了完整垃圾回收的特定原因是元数据区域的垃圾回收阈值被触发。

相关推荐
麦兜*16 小时前
Spring Boot启动优化7板斧(延迟初始化、组件扫描精准打击、JVM参数调优):砍掉70%启动时间的魔鬼实践
java·jvm·spring boot·后端·spring·spring cloud·系统架构
真实的菜1 天前
JVM类加载系统详解:深入理解Java类的生命周期
java·开发语言·jvm
在未来等你1 天前
JVM调优实战 Day 15:云原生环境下的JVM配置
java·jvm·性能优化·虚拟机·调优
黄雪超2 天前
JVM——函数式语法糖:如何使用Function、Stream来编写函数式程序?
java·开发语言·jvm
ThetaarSofVenice2 天前
对象的finalization机制Test
java·开发语言·jvm
很小心的小新2 天前
12、jvm运行期优化
java·开发语言·jvm·笔记
ThetaarSofVenice2 天前
垃圾收集相关算法Test
java·jvm·算法
暮 夏2 天前
Java测试题一
java·开发语言·jvm
程序员弘羽2 天前
C++ 第四阶段 内存管理 - 第二节:避免内存泄漏的技巧
java·jvm·c++
好名字更能让你们记住我2 天前
Linux多线程(十二)之【生产者消费者模型】
linux·运维·服务器·jvm·windows·centos