Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Java8 Metaspace dump (not heap dump)

Tags:

Are there any tools that are able to get Metaspace dump from a Java8 hotspot vm ?

like image 922
czh Avatar asked Jun 20 '16 09:06

czh


People also ask

Where is Metaspace stored?

They live in a native memory region outside of the Java heap. That region is called Metaspace.

What is heap Metaspace?

The Metaspace takes up a significant portion of the JVM's Non-Heap memory. Its main purpose is to store class metadata — the internal runtime representation of Java classes. By default, the metaspace is comprised of two parts — the Class Space and the Non-Class Space.

How do you get heap dump on OutOfMemoryError?

They are very useful to troubleshoot memory-leak problems and optimize memory usage in Java applications. In order to capture a heap dump automatically, we need to add the HeapDumpOnOutOfMemoryError command-line option that generates a heap dump when a java. lang. OutOfMemoryError is thrown.


1 Answers

It seems you encounter a class loading leak.
Use

  • jmap -clstats PID to dump class loader statistics;
  • jcmd PID GC.class_stats to print the detailed information about memory usage of each loaded class. The latter requires -XX:+UnlockDiagnosticVMOptions.

The heap dump will also help, because each class in the Metaspace has a corresponding java.lang.Class instance in the heap.

like image 103
apangin Avatar answered Sep 28 '22 03:09

apangin