1

我在使用 java 8 元空间内存管理时遇到了困难。我目前在 RHEL 上使用 jdk 1.8_60。

这是我的 tomcat 类路径:

/opt/java/jdk1.8.0_60/bin/java
-Djava.util.logging.config.file=/opt/apache/tomcat/apache-tomcat/conf/logging.properties
-Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
-Xms1g
-Xmx16g
-XX:MetaspaceSize=128m
-XX:MaxMetaspaceSize=256m
-XX:+UnlockDiagnosticVMOptions
-XX:NativeMemoryTracking=summary
-Dorg.apache.cxf.stax.allowInsecureParser=1
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/opt/apache/tomcat/apache-tomcat/temp/heap.dump
-Xloggc:/opt/apache/tomcat/apache-tomcat/logs/gc.log
-XX:+PrintGC
-XX:+PrintGCDateStamps
-XX:+PrintGCDetails
-XX:+UseGCLogFileRotation
-XX:GCLogFileSize=5m
-XX:NumberOfGCLogFiles=20
-Dcom.sun.management.jmxremote
-Dcom.sun.management.jmxremote.port=9999
-Dcom.sun.management.jmxremote.rmi.port=9998
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.local.only=false
-Djava.rmi.server.hostname=localhost
-Djava.endorsed.dirs=/opt/apache/tomcat/apache-tomcat/endorsed
-classpath /opt/apache/tomcat/apache-tomcat/bin/bootstrap.jar:/opt/apache/tomcat/apache-tomcat/bin/tomcat-juli.jar
-Dcatalina.base=/opt/apache/tomcat/apache-tomcat
-Dcatalina.home=/opt/apache/tomcat/apache-tomcat
-Djava.io.tmpdir=/opt/apache/tomcat/apache-tomcat/temp
org.apache.catalina.startup.Bootstrap start

当我执行时,jcmd <PID> VM.native_memory summary.diff它显示为 Class 保留的内存(我认为是元空间大小)超过 256m(看起来像默认值 1g)。

-                 Java Heap (reserved=16777216KB, committed=5485568KB)
                            (mmap: reserved=16777216KB, committed=5485568KB)

-                     Class (reserved=1149430KB, committed=112886KB)
                            (classes #16384 +1)
                            (malloc=6646KB #23800)
                            (mmap: reserved=1142784KB, committed=106240KB)

-                    Thread (reserved=32005KB -2065KB, committed=32005KB -2065KB)
                            (thread #32 -2)
                            (stack: reserved=31868KB -2056KB, committed=31868KB -2056KB)
                            (malloc=101KB -7KB #161 -10)
                            (arena=36KB -2 #62 -4)

我正在使用 cxf动态客户端进行动态 WS 调用,因此每个调用都会生成大量类,但看起来这些类永远不会从元空间中删除(即使我单击按钮在 jvisualvm 中执行 gc)。最后元空间已满,应用程序以OutOfMemoryException: Metaspace结束

我也在这个配置中使用了 GC1,-XX:+UseG1GC -XX:MaxGCPauseMillis=200 -XX:+ParallelRefProcEnabled -XX:+AggressiveOpts但这对我没有帮助。

那么jvm中是否可能存在错误,显示元空间的内存分配错误(或者更糟糕的是它使用这个值来管理元空间)?有人可以指出一些如何解决元空间清理问题的方向吗?

非常感谢

4

0 回答 0