Java 8: Why does Metaspace size increase but number of loaded classes stay the same?

7.4k views Asked by At

In our app running on Jdk 8 we use VisualVM to track the usage of loaded classes and the usage of the metaspace.

At some point in time while our app is running we see that the number of loaded classes don't increase any more but the metaspace still increases in it's size while our program is running. So what else apart from classes is stored in metaspace, that could cause that?

2

There are 2 answers

0
Vyacheslav Tverskoy On BEST ANSWER

While your program is running, some parts of your code may be determined as "hot" by HotSpot's JIT compiler. This will cause those parts to be transformed/compiled to native code, and also some other code may be inlined into it. This native code representation has to go somewhere, and it goes into the same place as other class metadata - the Metaspace.

It explains continuous growth you're seeing: hot parts are determined over time using a simple metric of how much times did that piece of code got executed. Over time more and more code pieces will be JIT'ed as they'll hit threshold set by -XX:CompileThreshold (defaults to 10000)

1
mafahand On

i am not sure but hier (http://java.dzone.com/articles/java-8-permgen-metaspace) i fund this

Garbage collection of the dead classes and classloaders is triggered once the class metadata usage reaches the “MaxMetaspaceSize”.

maybe is this the cause for increasing metaspace size.