为什么jmx中的G1 Old gen max memory等于最大堆大小?

时间:2017-10-01 02:47:55

标签: java jvm jmx g1gc

我启动了一个用jmx启用的tomcat实例,我检查了G1 old gen memory stat,找到max memory = max heap size。

  • 环境
# uname -a
Linux bogon 2.6.32-642.15.1.el6.x86_64 #1 SMP Fri Feb 24 14:31:22 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
# cat /etc/redhat-release
CentOS release 6.8 (Final)
# java -version
java version "1.8.0_65"
Java(TM) SE Runtime Environment (build 1.8.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.65-b01, mixed mode)
  • jvm选项
# ps -ef|grep tomcat
tomcat    3177     1  7 10:23 ?        00:00:06 /usr/java/jdk1.8.0_65//bin/java -Djava.util.logging.config.file=/apps/tomcat/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -server -Djava.awt.headless=true -Dfile.encoding=UTF-8 -Xms1696m -Xmx1696m -XX:+DisableExplicitGC -XX:MaxGCPauseMillis=200 -XX:+UseStringDeduplication -XX:MetaspaceSize=96m -XX:+UseG1GC -XX:InitiatingHeapOccupancyPercent=45 -XX:MinMetaspaceFreeRatio=50 -XX:MaxMetaspaceFreeRatio=80 -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintGCDateStamps -XX:+PrintClassHistogram -XX:+PrintTenuringDistribution -XX:+PrintGCApplicationStoppedTime -Xloggc:/var/log/tomcat/gc.log -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=10 -XX:GCLogFileSize=2M -XX:+HeapDumpOnOutOfMemoryError -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8415 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.rmi.port=8415 -classpath /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar -Dcatalina.base=/apps/tomcat -Dcatalina.home=/usr/local/tomcat -Djava.io.tmpdir=/apps/tomcat/temp org.apache.catalina.startup.Bootstrap -Dprocessname=tomcat start
  • jmap结果
# jmap -heap 3177
Attaching to process ID 3177, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.65-b01

using thread-local object allocation.
Garbage-First (G1) GC with 1 thread(s)

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 1778384896 (1696.0MB)
   NewSize                  = 1363144 (1.2999954223632812MB)
   MaxNewSize               = 1066401792 (1017.0MB)
   OldSize                  = 5452592 (5.1999969482421875MB)
   NewRatio                 = 2
   SurvivorRatio            = 8
   MetaspaceSize            = 100663296 (96.0MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize         = 17592186044415 MB
   G1HeapRegionSize         = 1048576 (1.0MB)

Heap Usage:
G1 Heap:
   regions  = 1696
   capacity = 1778384896 (1696.0MB)
   used     = 84934656 (81.0MB)
   free     = 1693450240 (1615.0MB)
   4.775943396226415% used
G1 Young Generation:
Eden Space:
   regions  = 81
   capacity = 93323264 (89.0MB)
   used     = 84934656 (81.0MB)
   free     = 8388608 (8.0MB)
   91.01123595505618% used
Survivor Space:
   regions  = 0
   capacity = 0 (0.0MB)
   used     = 0 (0.0MB)
   free     = 0 (0.0MB)
   0.0% used
G1 Old Generation:
   regions  = 0
   capacity = 1685061632 (1607.0MB)
   used     = 0 (0.0MB)
   free     = 1685061632 (1607.0MB)
   0.0% used

12869 interned Strings occupying 1777832 bytes.
  • 问题

jmx项java.lang:type=MemoryPool,name=G1 Old Gen,Usage.max是1778384896,它等于最大堆大小。

如果Old gen内存不足,所有堆内存都将用于Old gen内存?

1 个答案:

答案 0 :(得分:0)

我确实遇到了同样的问题,old gen的最大内存与-Xmx的值相同,而在JMX接口中,eden和survivor的最大内存均为-1(无限制)。在您提出问题后仅5个月,就收到了openjdk“ Revamp G1 JMX MemoryPool and GarbageCollector MXBean definitions”的问题单。恐怕我们只能等待它解决。