如何测量Hotspot的元空间中的碎片? [英] How do I measure fragmentation in Hotspot's Metaspace?

查看:170
本文介绍了如何测量Hotspot的元空间中的碎片?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找在我的应用程序中调试"OutOfMemoryError:Metaspace"错误的方法.就在OOME之前,我在gc日志中看到以下内容:

I'm looking into debugging an "OutOfMemoryError: Metaspace" error in my application. Right before the OOME I see the following in the gc logs:

{Heap before GC invocations=6104 (full 39):
 par new generation   total 943744K, used 0K [...)
  eden space 838912K,   0% used [...)
  from space 104832K,   0% used [...)
  to   space 104832K,   0% used [...)
 concurrent mark-sweep generation total 2097152K, used 624109K [...)
 Metaspace       used 352638K, capacity 487488K, committed 786432K, reserved 1775616K
  class space    used 36291K, capacity 40194K, committed 59988K, reserved 1048576K
2015-08-11T20:34:13.303+0000: 105892.129: [Full GC (Last ditch collection) 105892.129: [CMS: 624109K->623387K(2097152K), 3.4208207 secs] 624109K->623387K(3040896K), [Metaspace: 352638K->352638K(1775616K)], 3.4215100 secs] [Times: user=3.42 sys=0.00, real=3.42 secs] 
Heap after GC invocations=6105 (full 40):
 par new generation   total 943744K, used 0K [...)
  eden space 838912K,   0% used [...)
  from space 104832K,   0% used [...)
  to   space 104832K,   0% used [...)
 concurrent mark-sweep generation total 2097152K, used 623387K [...)
 Metaspace       used 352638K, capacity 487488K, committed 786432K, reserved 1775616K
  class space    used 36291K, capacity 40194K, committed 59988K, reserved 1048576K
}

据我所见,元空间的容量甚至没有接近承诺的大小(在本例中为-XX:MaxMetaspaceSize=768m).因此,我怀疑Metaspace的碎片化导致分配器无法为新的类加载器找到新的块.

From what I can see, Metaspace capacity isn't even nearing the committed size (in this case, -XX:MaxMetaspaceSize=768m). So I suspect fragmentation of Metaspace causing the allocator to fail to find a new chunk for the new classloader.

我知道-XX:PrintFLSStatistics,但是它仅涵盖CMS,而不涉及本机内存.

I'm aware of -XX:PrintFLSStatistics but that only covers CMS, not native memory.

所以我的问题是:Hotspot的本地内存是否有类似于PrintFLSStatistics的调试帮助?

So my question is: is there a debugging help similar to PrintFLSStatistics available for Hotspot's native memory?

这是将Java HotSpot™64位服务器VM(25.45-b02)用于linux-amd64 JRE(1.8.0_45-b14).

This is using Java HotSpot(TM) 64-Bit Server VM (25.45-b02) for linux-amd64 JRE (1.8.0_45-b14).

推荐答案

我刚刚研究了HotSpot中元空间的实现.元空间被划分为多个块,并使用空闲列表进行管理.因此,碎片化确实是您出现问题的可能原因.

I've just looked into the implementation of the Metaspace in HotSpot. The Metaspace is divided into chunks and managed using a freelist. So fragmentation is indeed a possible reason for your problem.

我还浏览了HotSpot VM(-XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal)的标志,发行版中没有标志.

I've also looked through the flags of the HotSpot VM (-XX:+UnlockDiagnosticVMOptions -XX:+PrintFlagsFinal), there is no flag in the release version.

但是,Metaspace类中有一个dump()方法,该方法似乎是通过设置-XX:+TraceMetadataChunkAllocation标志来触发的.还有-XX:+TraceMetavirtualspaceAllocation听起来很有趣.但是,这些是开发"标志,这意味着您需要虚拟机的调试版本.

However, there is a dump() method in the Metaspace class which seems to be triggered by setting the -XX:+TraceMetadataChunkAllocation flag. There is also the -XX:+TraceMetavirtualspaceAllocation which is sounding to be of interest for you. However, those are "develop" flags, meaning you need a debug version of the VM.

这篇关于如何测量Hotspot的元空间中的碎片?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆