Why MetaSpace Size is twice as big as Used MetaSpace?

人走茶凉 提交于 2019-12-05 23:00:47
expoter

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

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

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

As Java 8 document says:

Space is requested from the OS and then divided into chunks. A class loader allocates space for metadata from its chunks (a chunk is bound to a specific class loader).

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

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.

Good question ;-)

Have a look at this pretty good article.

PermGenSpace vs MetaSpace

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!