GC日志分析之配置参数
启动示例程序
$ javac demo/jvm0204/*.java $ java demo.jvm0204.GCLogAnalysis 正在执行... 执行结束!共生成对象次数:1423
输出 GC 日志详情
java -XX:+PrintGCDetails demo.jvm0204.GCLogAnalysis
正在执行... [GC (Allocation Failure) [PSYoungGen: 65081K->10728K(76288K)] 65081K->27102K(251392K), 0.0112478 secs] [Times: user=0.03 sys=0.02, real=0.01 secs] ......此处省略了多行 [Full GC (Ergonomics) [PSYoungGen: 80376K->0K(872960K)] [ParOldGen: 360220K->278814K(481280K)] 440597K->278814K(1354240K), [Metaspace: 3443K->3443K(1056768K)], 0.0406179 secs] [Times: user=0.23 sys=0.01, real=0.04 secs] 执行结束!共生成对象次数:746 Heap PSYoungGen total 872960K, used 32300K [0x000000076ab00000, 0x00000007b0180000, 0x00000007c0000000) eden space 792576K, 4% used [0x000000076ab00000,0x000000076ca8b370,0x000000079b100000) from space 80384K, 0% used [0x00000007a3800000,0x00000007a3800000,0x00000007a8680000) to space 138240K, 0% used [0x000000079b100000,0x000000079b100000,0x00000007a3800000) ParOldGen total 481280K, used 278814K [0x00000006c0000000, 0x00000006dd600000, 0x000000076ab00000) object space 481280K, 57% used [0x00000006c0000000,0x00000006d1047b10,0x00000006dd600000) Metaspace used 3449K, capacity 4494K, committed 4864K, reserved 1056768K class space used 366K, capacity 386K, committed 512K, reserved 1048576K
Heap 堆内存使用情况
PSYoungGen total 872960K, used 32300K [0x......) eden space 792576K, 4% used [0x......) from space 80384K, 0% used [0x......) to space 138240K, 0% used [0x......)
ParOldGen total 481280K, used 278814K [0x......) object space 481280K, 57% used [0x......)
Metaspace used 3449K, capacity 4494K, committed 4864K, reserved 1056768K class space used 366K, capacity 386K, committed 512K, reserved 1048576K
指定 GC 日志文件
# 请注意命令行启动时没有换行,此处是手工排版 java -Xloggc:gc.demo.log -XX:+PrintGCDetails demo.jvm0204.GCLogAnalysis
提示
正在执行... 执行结束!共生成对象次数:1327
Java HotSpot(TM) 64-Bit Server VM (25.162-b12) ...... Memory: 4k page,physical 16777216k(1519448k free) /proc/meminfo: CommandLine flags: -XX:InitialHeapSize=268435456 -XX:MaxHeapSize=4294967296 -XX:+PrintGC -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC 0.310: [GC (Allocation Failure) [PSYoungGen: 61807K->10732K(76288K)] 61807K->22061K(251392K), 0.0094195 secs] [Times: user=0.02 sys=0.02, real=0.01 secs] 0.979: [Full GC (Ergonomics) [PSYoungGen: 89055K->0K(572928K)] [ParOldGen: 280799K->254491K(434176K)] 369855K->254491K(1007104K), [Metaspace: 3445K->3445K(1056768K)], 0.0362652 secs] [Times: user=0.20 sys=0.01, real=0.03 secs] ...... 此处省略部分内容 Heap ...... 堆内存信息格式请参考前面的日志
打印 GC 事件发生的日期和时间
java -Xloggc:gc.demo.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps demo.jvm0204.GCLogAnalysis
...... 省略多行 CommandLine flags: -XX:InitialHeapSize=268435456 -XX:MaxHeapSize=4294967296 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC 2019-12-15T15:09:59.235-0800: 0.296: [GC (Allocation Failure) [PSYoungGen: 63844K->10323K(76288K)] 63844K->20481K(251392K), 0.0087896 secs] [Times: user=0.02 sys=0.02, real=0.01 secs] 2019-12-15T15:09:59.889-0800: 0.951: [Full GC (Ergonomics) [PSYoungGen: 81402K->0K(577536K)] [ParOldGen: 270176K->261230K(445952K)] 351579K->261230K(1023488K), [Metaspace: 3445K->3445K(1056768K)], 0.0369622 secs] [Times: user=0.19 sys=0.00, real=0.04 secs] Heap .......省略内容参考前面的格式
指定堆内存的大小
java -Xms512m -Xmx512m -Xloggc:gc.demo.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps demo.jvm0204.GCLogAnalysis
...... CommandLine flags: -XX:InitialHeapSize=536870912 -XX:MaxHeapSize=536870912 -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC 2019-12-15T15:15:09.677-0800: 0.358: [GC (Allocation Failure) [PSYoungGen: 129204K->21481K(153088K)] 129204K->37020K(502784K), 0.0121865 secs] [Times: user=0.03 sys=0.03, real=0.01 secs] 2019-12-15T15:15:10.058-0800: 0.739: [Full GC (Ergonomics) [PSYoungGen: 20742K->0K(116736K)] [ParOldGen: 304175K->247922K(349696K)] 324918K->247922K(466432K), [Metaspace: 3444K->3444K(1056768K)], 0.0319225 secs] [Times: user=0.18 sys=0.01, real=0.04 secs]
指定垃圾收集器
-XX:+UseSerialGC -XX:+UseParallelGC -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseConcMarkSweepGC -XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+UseG1GC
其他参数
-XX:+PrintGCApplicationStoppedTime
-XX:+PrintReferenceGC
说明
辨析
Minor GC(小型 GC)
Major GC vs. Full GC
本文来自博客园,作者:邴越,转载请注明原文链接:https://www.cnblogs.com/binyue/p/17374260.html