JVM之常用JVM配置参数

来源:互联网 发布:两个excel表格匹配数据 编辑:程序博客网 时间:2024/05/21 18:47

Trace跟踪参数

-verbose:gc

-XX:+printGC

打印GC简要信息

[GC (Allocation Failure)  3344K->1296K(9728K), 0.0004129 secs][GC (Allocation Failure)  3344K->1296K(9728K), 0.0003914 secs][GC (Allocation Failure)  3344K->1296K(9728K), 0.0003756 secs]
-XX:+PrintGCDetails
打印GC详细信息,1.4.0引入,默认不启用
[GC [PSYoungGen: 2560K->0K(3072K)] 3068K->508K(10240K), 0.0005989 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] [GC [PSYoungGen: 2560K->0K(3072K)] 3068K->508K(10240K), 0.0004555 secs] [Times: user=0.00 sys=0.00, real=0.00 secs] [GC [PSYoungGen: 2560K->0K(3072K)] 3068K->508K(10240K), 0.0004692 secs] [Times: user=0.00 sys=0.00, real=0.00 secs]
  • 程序运行完后的输出,这是JDK 7
Heap PSYoungGen      total 3072K, used 1229K [0x00000000ffc80000, 0x0000000100000000, 0x0000000100000000)  eden space 2560K, 48% used [0x00000000ffc80000,0x00000000ffdb36d8,0x00000000fff00000)  from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)  to   space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000) ParOldGen       total 7168K, used 508K [0x00000000ff580000, 0x00000000ffc80000, 0x00000000ffc80000)  object space 7168K, 7% used [0x00000000ff580000,0x00000000ff5ff070,0x00000000ffc80000) PSPermGen       total 21504K, used 2527K [0x00000000fa380000, 0x00000000fb880000, 0x00000000ff580000)  object space 21504K, 11% used [0x00000000fa380000,0x00000000fa5f7d68,0x00000000fb880000)
  • 这是JDK 8,可以看到,JDK 8把永生代PSPermGen给去掉了,换成了Metaspace
Heap PSYoungGen      total 2560K, used 205K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)  eden space 2048K, 10% used [0x00000000ffd00000,0x00000000ffd33480,0x00000000fff00000)  from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000) ParOldGen       total 7168K, used 1308K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)  object space 7168K, 18% used [0x00000000ff600000,0x00000000ff747070,0x00000000ffd00000) Metaspace       used 4405K, capacity 4716K, committed 4992K, reserved 1056768K  class space    used 480K, capacity 531K, committed 640K, reserved 1048576K
-XX:+PrintGCTimeStamps
打印GC发生的时间戳
-Xloggc:log/gc.log
指定GC log的位置,以文件输出,帮助开发人员分析问题
-XX:+PrintHeapAtGC
每一次GC后, 都打印堆的信息
{Heap before GC invocations=1117 (full 0): PSYoungGen      total 2560K, used 2048K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)  eden space 2048K, 100% used [0x00000000ffd00000,0x00000000fff00000,0x00000000fff00000)  from space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000)  to   space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000) ParOldGen       total 7168K, used 1328K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)  object space 7168K, 18% used [0x00000000ff600000,0x00000000ff74c080,0x00000000ffd00000) Metaspace       used 4396K, capacity 4716K, committed 4992K, reserved 1056768K  class space    used 478K, capacity 531K, committed 640K, reserved 1048576KHeap after GC invocations=1117 (full 0): PSYoungGen      total 2560K, used 0K [0x00000000ffd00000, 0x0000000100000000, 0x0000000100000000)  eden space 2048K, 0% used [0x00000000ffd00000,0x00000000ffd00000,0x00000000fff00000)  from space 512K, 0% used [0x00000000fff00000,0x00000000fff00000,0x00000000fff80000)  to   space 512K, 0% used [0x00000000fff80000,0x00000000fff80000,0x0000000100000000) ParOldGen       total 7168K, used 1328K [0x00000000ff600000, 0x00000000ffd00000, 0x00000000ffd00000)  object space 7168K, 18% used [0x00000000ff600000,0x00000000ff74c080,0x00000000ffd00000) Metaspace       used 4396K, capacity 4716K, committed 4992K, reserved 1056768K  class space    used 478K, capacity 531K, committed 640K, reserved 1048576K}
-XX:+TraceClassLoading
监控类的加载
[Loaded java.lang.invoke.LambdaFormEditor from C:\Java\jdk1.8.0_101\jre\lib\rt.jar][Loaded java.lang.invoke.LambdaFormEditor$Transform$Kind from C:\Java\jdk1.8.0_101\jre\lib\rt.jar][Loaded java.lang.invoke.LambdaFormEditor$Transform from C:\Java\jdk1.8.0_101\jre\lib\rt.jar]
-XX:+PrintClassHistogram
按下Ctrl+Break后,打印类的信息。分别序号、实例数量、总大小、类型
-Xmx -Xms
指定最大堆最小堆
-XX:+TraceClassLoading, -XX:+TraceClassUnLoading
查看类的加载和卸载信息

堆的分配参数

-Xmn
设置新生代大小,绝对值
-XX:NewRatio=数字
新生代(eden+ 2 * survivor)和老年代(不含永久区)的比值。例如4,表示新生代:老年代=1:4,即年轻代占堆的1/5.对JDK 7来说
-XX:SurvivorRatio=数字
设置连个Survivor区和eden的比值,例如8,表示2*Survivor:eden=2:8
-XX:+HeapDumpOnOutOfMemoryError
OOM时道出堆到文件
-XX:+HeapDumpPath
导出OOM的路径
-XX:OnOutOfMemoryError
OOM时,执行一个脚本

总结

  • 根据实际,调整新生代和Survivor的大小
  • 官方推荐新生代占堆的3/8
  • Survivor占新生代的1/10
  • OOM时,Dump出堆,确保可以排查现场问题

栈的分配参数

  • 线程私有,每个线程都有独立的栈空间
  • 主要构成是栈帧,栈帧里边有局部变量表,操作数栈,常量池引用,地址等等,分配在栈上
-Xss
通常只有几百k,决定了函数调用的深度

抛出java.lang.StackOverflowError

永久区分配参数(JDK 7有,JDK 8没有永久区)

-XX:PermSize
设置初始空间,表示一个系统可以容纳多少个类型
-XX:MaxPermSize
设置最大空间,表示一个系统可以容纳多少个类型
-Xnoclassgc
是否对方法区的类回收
如果堆空间没有用完,却抛出OOM,那可能是永久区导致的

GC Parameters1

GC Parameters2

0 0
原创粉丝点击