22

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?

Chris W.
  • 2,266
  • 20
  • 40
  • 2
    I guess, while the number of loaded classes stagnates, the amount of *actually used* code may still increase… – Holger Jun 19 '15 at 14:21
  • Hmm, I don't understand what you mean. The code of the classes is already there, what else should go there? – Chris W. Jun 19 '15 at 16:25
  • 5
    Do you think a JVM stores the classes in RAM the same way they reside on your hard disk? The meta-information are the result of analyzing, or more generally, processing the class file’s contents and that work (or parts of it) may be postponed until a method is really used. – Holger Jun 19 '15 at 16:37
  • Ah you're right. Maybe also native code that has been compiled by Hotspot goes there? – Chris W. Jun 22 '15 at 09:32
  • Nice read for compilation to native code here: http://stackoverflow.com/questions/15020152/can-i-force-the-jvm-to-natively-compile-a-given-method – Chris W. Jun 23 '15 at 11:07
  • 2
    Not sure about this. But I do know that compiled code goes to the `CodeCache` region, so nothing to do with MetaSpace. Do you use a lot reflection (or a framework that does, like Spring)? There might be meta-information about proxies (method handles, etc) being stored in Metaspace that don't count as a loaded class. – mabi Nov 20 '15 at 11:13

2 Answers2

10

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)

0

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.

mafahand
  • 66
  • 3
  • The OP specifically says the number of loaded classes doesn't increase anymore. So dead or not, the total amount should be stable. – mabi Nov 20 '15 at 11:01