JVM常用参数配置

2019-05-16 16:17:19 浏览数 (1)

本文涉及:gc、堆、栈、永久区、元数据区的常用参数

GC基本参数

打印gc简要信息:-XX: PrintGC

代码语言:javascript复制
[GC (System.gc())  198247K->197248K(261632K), 0.0178572 secs][Full GC (System.gc())  197248K->197184K(261632K), 0.0842625 secs]

上方结果描述:

分别是GC和Full GC释放的空间以及所用的时间

打印gc的详细信息 : -XX: PrintGCDetails

代码语言:javascript复制
Heap PSYoungGen      total 18944K, used 164K [0x00000000eb200000, 0x00000000ec700000, 0x0000000100000000)  eden space 16384K, 1% used [0x00000000eb200000,0x00000000eb2290d0,0x00000000ec200000)  from space 2560K, 0% used [0x00000000ec200000,0x00000000ec200000,0x00000000ec480000)  to   space 2560K, 0% used [0x00000000ec480000,0x00000000ec480000,0x00000000ec700000) ParOldGen       total 292352K, used 246336K [0x00000000c1600000, 0x00000000d3380000, 0x00000000eb200000)  object space 292352K, 84% used [0x00000000c1600000,0x00000000d0690290,0x00000000d3380000) Metaspace       used 2866K, capacity 4486K, committed 4864K, reserved 1056768K  class space    used 308K, capacity 386K, committed 512K, reserved 1048576K

上方结果描述:

  • 第2行:新生代总内存和已用内存
  • 第3、4、5行:新生代各个区总内存和已用内存,这里eden:from:to的比例为8:1:1
  • 第6行:老年代总内存和已用内存

指定gc日志的位置: -Xloggc:D:appLogapp.log

打印gc前后的堆栈信息: -XX: PrintHeapAtGC

代码语言:javascript复制
{Heap before GC invocations=1 (full 0):
 PSYoungGen      total 18944K, used 1639K [0x00000000eb200000, 0x00000000ec700000, 0x0000000100000000)
  eden space 16384K, 10% used [0x00000000eb200000,0x00000000eb399c28,0x00000000ec200000)
  from space 2560K, 0% used [0x00000000ec480000,0x00000000ec480000,0x00000000ec700000)
  to   space 2560K, 0% used [0x00000000ec200000,0x00000000ec200000,0x00000000ec480000)
 ParOldGen       total 491008K, used 442368K [0x00000000c1600000, 0x00000000df580000, 0x00000000eb200000)
  object space 491008K, 90% used [0x00000000c1600000,0x00000000dc600090,0x00000000df580000)
 Metaspace       used 2860K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 307K, capacity 386K, committed 512K, reserved 1048576K
 [Full GC (System.gc())  443064K->442944K(509952K), 0.1634157 secs]
Heap after GC invocations=1 (full 0):
 PSYoungGen      total 18944K, used 664K [0x00000000eb200000, 0x00000000ec700000, 0x0000000100000000)
  eden space 16384K, 0% used [0x00000000eb200000,0x00000000eb200000,0x00000000ec200000)
  from space 2560K, 25% used [0x00000000ec200000,0x00000000ec2a6030,0x00000000ec480000)
  to   space 2560K, 0% used [0x00000000ec480000,0x00000000ec480000,0x00000000ec700000)
 ParOldGen       total 491008K, used 442376K [0x00000000c1600000, 0x00000000df580000, 0x00000000eb200000)
  object space 491008K, 90% used [0x00000000c1600000,0x00000000dc602090,0x00000000df580000)
 Metaspace       used 2860K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 307K, capacity 386K, committed 512K, reserved 1048576K
}

上方结果描述:

  • 1-9行是gc之前的新生代、老年代和元空间(这是jdk8更新的,之前是永久区)信息
  • 第10行打印了一次full gc的相关信息

监控类的加载:-XX: TraceClassLoadingPreorder

代码语言:javascript复制

[Opened C:Program Files (x86)Javajdk1.8.0_181jrelibrt.jar]
[Loaded java.lang.Object from C:Program Files (x86)Javajdk1.8.0_181jrelibrt.jar]
[Loaded java.io.Serializable from C:Program Files (x86)Javajdk1.8.0_181jrelibrt.jar]
[Loaded java.lang.Comparable from C:Program Files (x86)Javajdk1.8.0_181jrelibrt.jar]
[Loaded java.lang.CharSequence from C:Program Files (x86)Javajdk1.8.0_181jrelibrt.jar]
[Loaded java.lang.String from C:Program Files (x86)Javajdk1.8.0_181jrelibrt.jar]
[Loaded java.lang.reflect.AnnotatedElement from C:Program Files (x86)Javajdk1.8.0_181jrelibrt.jar]
[Loaded java.lang.reflect.GenericDeclaration from C:Program Files (x86)Javajdk1.8.0_181jrelibrt.jar]
[Loaded java.lang.reflect.Type from C:Program Files (x86)Javajdk1.8.0_181jrelibrt.jar]
[Loaded java.lang.Class from C:Program Files (x86)Javajdk1.8.0_181jrelibrt.jar]
。。。。。。。

堆最大值: -Xmx20m

堆的最小值: -Xms5m

获取系统堆内存信息

代码语言:javascript复制
System.out.println("堆最大空间:"   Runtime.getRuntime().maxMemory() / 1024 / 1024   "M");System.out.println("空闲空间:"   Runtime.getRuntime().freeMemory() / 1024 / 1024   "M");System.out.println("可用空间:"   Runtime.getRuntime().totalMemory() / 1024 / 1024   "M");

新生代的内存: -Xmn10m

eden区和两个s区的和,正常情况下是eden:s0:s1=8:1:1

新生代占老年的的比值:-XX:NewRatio=6

新生代与老年代的比率为1:6,正常情况下是新生代:老年代=3:8

两个s区与eden的比值:-XX:SurvivorRatio=6

一个s区与eden的比率为1:6

发生堆溢出时异常文件路径:

-XX:HeapDumpPath=d:appLoga.dump

发生堆溢出时候执行的脚本:

-XX:OnOutOfMemoryError=d:a.sh

栈的大小-Xss10m

永久区的初始大小:-XX:PermSize5m

永久区的最大大小:-XX:MaxPermSize5m

元数据区大小:-XX:MaxMetaspaceSize=5m

0 人点赞