本文介绍了为什么MetaSpace大小是二手MetaSpace的两倍?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个程序来模拟MetaSpace OOM.但是我发现MetaSpace Size几乎总是Used MetaSpace的两倍.为什么?

I wrote a program to simulate MetaSpace OOM. But I found that MetaSpace Size is almost always twice as big as Used MetaSpace. Why?

我用标志-XX:MaxMetaspaceSize=50m运行程序,当Used MetaSpace达到25M而不是50M时,程序抛出OOM,为什么?

I run my program with flag -XX:MaxMetaspaceSize=50m, the program throw OOM when Used MetaSpace reached about 25M rather than 50M, Why?

推荐答案

我认为以下两个实验将解释 MetaSpace Size Used MetaSpace 之间的差距是什么意思:

I think the following two experiment will explain what does the gap between MetaSpace Size and Used MetaSpace mean:

EXP-1 :每个ClassLoader加载一个类,我得到了:

EXP-1: load one class per ClassLoader, I got this:

EXP-2 :每个ClassLoader加载五个类,我得到了:

EXP-2: load five classes per ClassLoader, I got this:

Java 8文档 说:

As Java 8 document says:

我认为这意味着一个块通常可以包含一个以上的类,因此,当您每个ClassLoader加载更多的类时,MetaSpace Size的利用率就会提高.

I think it means a chunk can contains usually more than one class, so utilization rate of MetaSpace Size grows as you load more classes per ClassLoader.

您可以通过运行 此处的代码 ,使用命令:

You can reappear the results by running code here using command:

java -XX:MaxMetaspaceSize=50m MetadataOOMSimulator 100000000

注意:确保所有加载的类均不应出现在CLASSPATH中(通常包括当前目录),否则这些类将由APPClassLoader而不是自定义的ClassLoader加载.

Attention: make sure that all classes be loaded should not appear in CLASSPATH (usually include current directory), or those classes will be loaded by APPClassLoader rather than customized ClassLoader.

这篇关于为什么MetaSpace大小是二手MetaSpace的两倍?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 19:09