java.lang.OutOfMemoryError:从 Java 7 迁移到 Java 8 后的元空间错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/45632230/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.OutOfMemoryError: Metaspace error after migrating to Java 8 from Java 7
提问by Valsaraj Viswanathan
We got OutOfMemoryError when upgraded. The JVM settings are kept same as Java 7 which was working fine.
升级时我们遇到了 OutOfMemoryError。JVM 设置与运行良好的 Java 7 保持相同。
Here is the settings in Jboss 4.2 server:
这是 Jboss 4.2 服务器中的设置:
-server -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Xms4096m -Xmx7168m -XX:MaxMetaspaceSize=512m -XX:+UseConcMarkSweepGC -XX:+CMSClassUnloadingEnabled -Djava.security.egd=file:///dev/urandom
-server -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Xms4096m -Xmx7168m -XX:MaxMetaspaceSize=512m -XX:+UseConcMarkSweepClassJavaUnloadSecurityXX: .egd=file:///dev/urandom
Only difference in Java 7 is XX:MaxMetaspaceSize=512m was replace with PermGen max.
Java 7 的唯一区别是 XX:MaxMetaspaceSize=512m 被 PermGen max 替换。
I wonder why it needs more Metaspace for class loading since the server & application is same & only change in Java version.
我想知道为什么它需要更多的元空间来加载类,因为服务器和应用程序是相同的,并且只在 Java 版本中发生了变化。
回答by Hendrik
You should probably remove -XX:MaxMetaspaceSize=512m
altogether.
您可能应该-XX:MaxMetaspaceSize=512m
完全删除。
My guess is, that in Java 7 you've needed to increasethe permanent generation to get things to run at all, because the default max was too low.
我的猜测是,在 Java 7 中,你需要增加永久代才能让事情运行起来,因为默认的最大值太低了。
In Java 8, the metaspace that holds your classes can expand without limit by default, so you probably don't run into the issue you have tried to solve for Java 7 in the first place. Instead, as you have experienced, you run into another issue: Setting too low a metaspace limit. Removing said limit will probably solve the issue and allow the JVM to make suitable decisions for you.
在 Java 8 中,默认情况下,保存类的元空间可以无限制地扩展,因此您可能不会遇到您首先尝试为 Java 7 解决的问题。相反,正如您所经历的,您遇到了另一个问题:将元空间限制设置得太低。删除上述限制可能会解决问题并允许 JVM 为您做出合适的决定。
See also this answer.
另请参阅此答案。
回答by Vlad Skurtolov
One thing that comes to my mind is that java8 uses lambdas and every lambda is some sort of class in java 8. Correct me if im wrong but thats what my inspection sees when creating class chart of a java8 app. Thus java8 uses more class memory.
我想到的一件事是 java8 使用 lambdas 并且每个 lambda 都是 java 8 中的某种类。如果我错了,请纠正我,但这就是我在创建 java8 应用程序的类图表时看到的。因此 java8 使用更多的类内存。