1、常用JVM配置参数
- Trace跟踪参数
- 堆的分配参数
- 栈的分配参数
1.1Trace跟踪参数
打印GC信息:
-verbose:gc
-XX:+PrintGC
-XX:+PrintGCDetails
打印GC详细信息
-XX:+PrintGCTimeStamps
打印CG发生的时间戳
各个参数效果:
package com.thread.study;
public class GCPrint {
public static void main(String[] args) {
for(int i = 0;i<100000000;i++){
byte[] bytes = new byte[1024*1024];
}
}
}
栈的分配参数
-verbose:gc
[GC (Allocation Failure) 853077K->608K(987648K), 0.0004369 secs]
[GC (Allocation Failure) 813447K->608K(950272K), 0.0003791 secs]
[GC (Allocation Failure) 776007K->608K(914944K), 0.0004622 secs]
[GC (Allocation Failure) 741407K->608K(881152K), 0.0004329 secs]
[GC (Allocation Failure) 706850K->608K(848896K), 0.0003218 secs]
[GC (Allocation Failure) 675424K->608K(818176K), 0.0004226 secs]
[GC (Allocation Failure) 644232K->608K(953856K), 0.0005373 secs]
[GC (Allocation Failure) 780384K->608K(1117696K), 0.0006502 secs]
[GC (Allocation Failure) 944103K->608K(1316352K), 0.0004409 secs]
[GC (Allocation Failure) 1142880K->608K(1545216K), 0.0006066 secs]
[GC (Allocation Failure) 1371376K->608K(1480192K), 0.0004724 secs]
[GC (Allocation Failure) 1306720K->608K(1418240K), 0.0004022 secs]
[GC (Allocation Failure) 1244768K->608K(1359360K), 0.0004724 secs]
-XX:+PrintGC
[GC (Allocation Failure) 1031747K->608K(1157120K), 0.0005155 secs]
[GC (Allocation Failure) 983648K->608K(1111040K), 0.0004537 secs]
[GC (Allocation Failure) 937568K->608K(1067520K), 0.0004591 secs]
[GC (Allocation Failure) 893916K->608K(1026048K), 0.0003697 secs]
[GC (Allocation Failure) 852105K->608K(986624K), 0.0005231 secs]
[GC (Allocation Failure) 812447K->608K(949248K), 0.0005524 secs]
[GC (Allocation Failure) 775776K->608K(913920K), 0.0004457 secs]
[GC (Allocation Failure) 740353K->608K(880128K), 0.0004911 secs]
[GC (Allocation Failure) 705902K->608K(847872K), 0.0003844 secs]
[GC (Allocation Failure) 674400K->608K(1016320K), 0.0005853 secs]
[GC (Allocation Failure) 842791K->608K(1201664K), 0.0017719 secs]
[GC (Allocation Failure) 1027652K->608K(1427968K), 0.0003986 secs]
[GC (Allocation Failure) 1254496K->608K(1552896K), 0.0003520 secs]
-XX:+PrintGCDetails
[GC (Allocation Failure) [PSYoungGen: 1250123K->0K(1191936K)] 1250739K->616K(1365504K), 0.0003675 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 1190912K->0K(1135104K)] 1191528K->616K(1308672K), 0.0005857 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 1134592K->0K(1082368K)] 1135208K->616K(1255936K), 0.0003582 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 1081301K->0K(1031168K)] 1081917K->616K(1204736K), 0.0004613 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 1030153K->0K(983040K)] 1030769K->616K(1156608K), 0.0003320 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 982528K->0K(937472K)] 983144K->616K(1111040K), 0.0007119 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[GC (Allocation Failure) [PSYoungGen: 936960K->0K(1218560K)] 937576K->616K(1392128K), 0.0011195 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
栈的分配参数
指定GC日志打印至指定文件:
-Xloggc:log/gc.log
-XX:+PrintHeapAtGC
每次一次GC后,都打印堆信息,打印出GC前后的堆信息。
{Heap before GC invocations=17 (full 0):
PSYoungGen total 1379840K, used 1378201K [0x000000076bb80000, 0x00000007c0000000, 0x00000007c0000000)
eden space 1378816K, 99% used [0x000000076bb80000,0x00000007bfd665f8,0x00000007bfe00000)
from space 1024K, 0% used [0x00000007bff00000,0x00000007bff00000,0x00000007c0000000)
to space 1024K, 0% used [0x00000007bfe00000,0x00000007bfe00000,0x00000007bff00000)
ParOldGen total 173568K, used 624K [0x00000006c3200000, 0x00000006cdb80000, 0x000000076bb80000)
object space 173568K, 0% used [0x00000006c3200000,0x00000006c329c070,0x00000006cdb80000)
Metaspace used 2634K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 284K, capacity 386K, committed 512K, reserved 1048576K
Heap after GC invocations=17 (full 0):
PSYoungGen total 1379840K, used 0K [0x000000076bb80000, 0x00000007c0000000, 0x00000007c0000000)
eden space 1378816K, 0% used [0x000000076bb80000,0x000000076bb80000,0x00000007bfe00000)
from space 1024K, 0% used [0x00000007bfe00000,0x00000007bfe00000,0x00000007bff00000)
to space 1024K, 0% used [0x00000007bff00000,0x00000007bff00000,0x00000007c0000000)
ParOldGen total 173568K, used 624K [0x00000006c3200000, 0x00000006cdb80000, 0x000000076bb80000)
object space 173568K, 0% used [0x00000006c3200000,0x00000006c329c070,0x00000006cdb80000)
Metaspace used 2634K, capacity 4486K, committed 4864K, reserved 1056768K
class space used 284K, capacity 386K, committed 512K, reserved 1048576K
}
监控类的加载:(会打印出类的加载信息)
-XX:+TraceClassLoading
[Opened D:\install\jdk1.8\jre\lib\rt.jar]
[Loaded java.lang.Object from D:\install\jdk1.8\jre\lib\rt.jar]
[Loaded java.io.Serializable from D:\install\jdk1.8\jre\lib\rt.jar]
[Loaded java.lang.Comparable from D:\install\jdk1.8\jre\lib\rt.jar]
[Loaded java.lang.CharSequence from D:\install\jdk1.8\jre\lib\rt.jar]
[Loaded java.lang.String from D:\install\jdk1.8\jre\lib\rt.jar]
[Loaded java.lang.reflect.AnnotatedElement from D:\install\jdk1.8\jre\lib\rt.jar]
[Loaded java.lang.reflect.GenericDeclaration from D:\install\jdk1.8\jre\lib\rt.jar]
-XX:+PrintClassHistogram
按下Ctrl+Break后,打印类的信息: