java.lang.OutOfMemoryError:压缩的类空间
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30511439/
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: Compressed class space
提问by user1236097
We are running on java-8-oracle.
我们在 java-8-oracle 上运行。
We moved to java8 six month ago.
六个月前我们搬到了 java8。
In the past few days we have been getting an OOME from time to time and we haven't been able to identify or reproduce the problem.
在过去的几天里,我们不时收到 OOME,但我们无法识别或重现该问题。
When we execute a call to the server (tomcat) we get this error on the stacktrace:
当我们执行对服务器 (tomcat) 的调用时,我们会在堆栈跟踪中收到此错误:
java.lang.OutOfMemoryError: Compressed class space
Restarting the server solves the problem. The same call to other server works, and so does another call of another type to the same server.
重启服务器即可解决问题。对其他服务器的相同调用起作用,对同一服务器的另一种类型的另一个调用也起作用。
When looking on the gc.log we see:
查看 gc.log 时,我们看到:
2015-05-27T16:05:42.991+0000: 98774.440: [Full GC (Last ditch collection) 98774.440: [CMS: 575745K->575330K(3495936K), 0.8687777 secs] 575745K->575330K(4107008K), [Metaspace: 97940K->97940K(1396736K)], 0.8696093 secs] [Times: user=0.95 sys=0.00, real=0.88 secs]
2015-05-27T16:05:55.486+0000: 98786.935: [Full GC (Metadata GC Threshold) 98786.935: [CMS: 573414K->578735K(3495936K), 0.9372859 secs] 925046K->578735K(4107008K), [Metaspace: 99428K->99428K(1396736K)], 0.9386626 secs] [Times: user=1.01 sys=0.00, real=0.94 secs]
jstat -gc
returns:
jstat -gc
返回:
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
87296.0 87296.0 0.0 3151.4 523776.0 148284.4 3495936.0 574868.5 1395640.0 98066.3 1048576.0 11339.1 12165 636.851 223 116.957
753.808
I don't see any memory problems either in the jstat log or in the gc log.
我在 jstat 日志或 gc 日志中都没有看到任何内存问题。
Trying to run jmap -clstats
hangs:
尝试运行jmap -clstats
挂起:
Attaching to process ID 5110, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.25-b02
finding class loader instances ..
回答by Albert
We faced a similar issue. Unfortunately heapdumps won't help you since the classes are not in the heap but in native memory. Enable these in your JVM settings to troubleshoot the classes loaded:
我们遇到了类似的问题。不幸的是 heapdumps 不会帮助你,因为这些类不在堆中,而是在本机内存中。在 JVM 设置中启用这些以对加载的类进行故障排除:
-XX:+PrintGCDetails -XX:+TraceClassUnloading -XX:+TraceClassLoading
In our case the issue was JAXBContext.newInstance not being singleton.
在我们的例子中,问题是 JAXBContext.newInstance 不是单例。
Good luck, Albert
祝你好运,阿尔伯特
回答by the8472
With compressed oops and compressed class pointers the available space for classes is constrained due to the necessary pointer mangling. 1GB in your case.
使用压缩的 oops 和压缩的类指针,由于必要的指针修改,类的可用空间受到限制。在您的情况下为 1GB。
That's a lot of classes, so this might be an indicate that something in your application is creating a lot of classes and never releasing them. Application reload maybe?
这是很多类,所以这可能表明您的应用程序中的某些东西正在创建很多类并且从未发布它们。应用程序重新加载可能吗?
If you are certain that your application just needs that much memory for classes you can try bumping the limit via -XX:CompressedClassSpaceSize=...
or disabling compressed class pointers via -XX:-UseCompressedClassPointers
.
如果您确定您的应用程序只需要为类提供那么多内存,您可以尝试-XX:CompressedClassSpaceSize=...
通过-XX:-UseCompressedClassPointers
.
Note that by default compressed class space + compressed heap (+ some overhead) cannot exceed 32GB. Although, AIUI, changing object alignment can bump that limit further.
请注意,默认情况下压缩类空间 + 压缩堆(+ 一些开销)不能超过 32GB。虽然,AIUI,改变对象对齐可以进一步突破这个限制。
Otherwise you should take a heapdump and analyze what's holding onto the loaded classes.
否则,您应该进行堆转储并分析加载的类中的内容。