-XX:+PrintGC
只要遇到GC,就会打印日志;
[GC 44068K->42008K(62976K), 0.0017377 secs]
[Full GC 42008K->719K(54784K), 0.0113301 secs]
复制代码
GC 和 Full GC指垃圾收集的停顿类型,而不是指新生代GC和老年代GC;
GC前java堆已使用容量 -> GC后java堆已使用容量(Java堆总容量)
-XX:+PrintGCDetails
输出更加详细的日志;
[GC [PSYoungGen: 3108K->1048K(19456K)] 44068K->42008K(62976K), 0.0017887 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
[Full GC [PSYoungGen: 1048K->0K(19456K)] [ParOldGen: 40960K->719K(35328K)] 42008K->719K(54784K) [PSPermGen: 3833K->3832K(21504K)], 0.0115238 secs] [Times: user=0.16 sys=0.00, real=0.01 secs]
复制代码
PSYoungGen、ParOldGen 和 PSPermGen 指 GC 位置,与垃圾收集器有关
-XX:+PrintHeapAtGC
每次 GC 前后分别打印堆的信息;
{Heap before GC invocations=1 (full 0):
PSYoungGen total 19456K, used 3108K [0x00000000fea80000, 0x0000000100000000, 0x0000000100000000)
eden space 16896K, 18% used [0x00000000fea80000,0x00000000fed89138,0x00000000ffb00000)
from space 2560K, 0% used [0x00000000ffd80000,0x00000000ffd80000,0x0000000100000000)
to space 2560K, 0% used [0x00000000ffb00000,0x00000000ffb00000,0x00000000ffd80000)
ParOldGen total 43520K, used 40960K [0x00000000fc000000, 0x00000000fea80000, 0x00000000fea80000)
object space 43520K, 94% used [0x00000000fc000000,0x00000000fe800020,0x00000000fea80000)
PSPermGen total 21504K, used 3833K [0x00000000f6e00000, 0x00000000f8300000, 0x00000000fc000000)
object space 21504K, 17% used [0x00000000f6e00000,0x00000000f71be658,0x00000000f8300000)
Heap after GC invocations=1 (full 0):
PSYoungGen total 19456K, used 992K [0x00000000fea80000, 0x0000000100000000, 0x0000000100000000)
eden space 16896K, 0% used [0x00000000fea80000,0x00000000fea80000,0x00000000ffb00000)
from space 2560K, 38% used [0x00000000ffb00000,0x00000000ffbf8030,0x00000000ffd80000)
to space 2560K, 0% used [0x00000000ffd80000,0x00000000ffd80000,0x0000000100000000)
ParOldGen total 43520K, used 40960K [0x00000000fc000000, 0x00000000fea80000, 0x00000000fea80000)
object space 43520K, 94% used [0x00000000fc000000,0x00000000fe800020,0x00000000fea80000)
PSPermGen total 21504K, used 3833K [0x00000000f6e00000, 0x00000000f8300000, 0x00000000fc000000)
object space 21504K, 17% used [0x00000000f6e00000,0x00000000f71be658,0x00000000f8300000)
}
复制代码
-XX:+PrintGCTimeStamps
额外输出GC发生的时间,改时间为虚拟机启动后的时间偏移量;
1.077: [GC 44073K->41992K(62976K), 0.0018222 secs]
1.078: [Full GC 41992K->719K(54784K), 0.0117782 secs]
复制代码
-XX:+PrintGCApplicationConcurrentTime
打印应用程序执行多久时间后发生 GC;
Application time: 2.5044489 seconds
[GC 54313K->41904K(62976K), 0.0018123 secs]
Application time: 0.4979832 seconds
[GC 52317K->41928K(62976K), 0.0015642 secs]
复制代码
-XX:+PrintGCApplicationStoppedTime
打印应用程序由于 GC 产生的停顿的时间;
[GC 54308K->41968K(62976K), 0.0018500 secs]
Total time for which application threads were stopped: 0.0019686 seconds, Stopping threads took: 0.0000184 seconds
[GC 52381K->41944K(62976K), 0.0015066 secs]
Total time for which application threads were stopped: 0.0015832 seconds, Stopping threads took: 0.0000172 seconds
复制代码
-Xloggc:${logPath}
指定 GC 输出日志到文件;
-XX:+PrintVMOptions
打印虚拟机接受到的显式参数;
VM option '+PrintVMOptions'
VM option '+PrintGC'
复制代码
-XX:+PrintCommandLineFlags
打印虚拟机虚拟机接收到的显式和隐式参数;
-XX:InitialHeapSize=67108864
-XX:MaxHeapSize=67108864
-XX:+PrintCommandLineFlags
-XX:+PrintGC
-XX:+UseCompressedOops
-XX:-UseLargePagesIndividualAllocation
-XX:+UseParallelGC
复制代码
-XX:+PrintFlagsFinal 查看所有系统参数的值。
-Xms -Xmx
初始堆大小,最大堆大小;
推荐设置两者相等,减少垃圾回收次数,提高性能。
-Xmn
新生代大小,一般设置为整个堆空间的 1/3 到 1/4 左右。
-XX:SurvivorRatio
新生代中 eden 空间和 from/to 空间的比例;
-XX:SurvivorRatio = eden/from = eden/to
-XX:NewRatio
新生代和老年代的比例;
-XX:NewRatio = 老年代/新生代
-XX:PermSize -XX:MaxPermSize
初始永久区大小,最大永久区大小;
JDK 1.8 彻底移除永久区,取而代之是元数据区,-XX:MaxMetaspaceSize 指定。
-Xss
栈空间大小;
-XX:MaxDirectMemorySize
最大可用直接内存大小,如果 NIO 库使用直接内存,垃圾回收不能有效释放空间,会引发 OOM;