3

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

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

enter image description here

assylias
  • 321,522
  • 82
  • 660
  • 783
expoter
  • 1,622
  • 17
  • 34
  • 1
    Possible duplicate of [How do I measure fragmentation in Hotspot's Metaspace?](http://stackoverflow.com/questions/32117471/how-do-i-measure-fragmentation-in-hotspots-metaspace) – the8472 Aug 23 '16 at 08:30

2 Answers2

1

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: enter image description here

EXP-2: load five classes per ClassLoader, I got this: enter image description here

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.

assylias
  • 321,522
  • 82
  • 660
  • 783
expoter
  • 1,622
  • 17
  • 34
0

Good question ;-)

Have a look at this pretty good article.

PermGenSpace vs MetaSpace

Rainer
  • 761
  • 5
  • 20
  • If you believe the link answers the question, you should summarise your finding in your answer instead of posting a link-only answer. – assylias Aug 23 '16 at 08:12
  • Yes you are right but I was writing this on my smartphone while waiting for a flight... Typing on this is horrible. – Rainer Aug 24 '16 at 23:36
  • And you are also right that it doesn't really answer the question. Stupid me... I red this article a year ago and was sure it explains this behavior. But it only notes it. – Rainer Aug 24 '16 at 23:43