How to get Java8 Metaspace dump (not heap dump)
Asked Answered
S

2

25

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

Ship answered 20/6, 2016 at 9:41 Comment(2)
In which form would you like to get this and what for? Note that data in Metaspace are not Java objects. Probably you're not interested in HotSpot internal structures, but in something else.Chop
We have an application causes Metaspace OOM error with 1G of MaxMetaspaceSize, and I wanted to know how Metaspace memories are being used.Ship
C
29

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.

Chop answered 20/6, 2016 at 22:52 Comment(6)
Hi apangin, thanks for your advice. I was able to dump the entire heap using jmap -dump command, however I am struggling to run jhat command to analyze the dump file. The heap dump is about 5GB, and jhat has been running 2 hours without completion, is this normal?Ship
jhat eventually terminated with heap space OOM error after running about 2 hours.Ship
@Ship Eclipse Memory Analyzer works fine even with large heap dumps.Chop
@Ship You can also try VisualVM or YourKit for larger heaps.Cesta
How to interpret below statistics to know whether my fix of METASPACE OOM is working? Dump Reason : JCMD MaxMetaspaceSize : 536870912 B CompressedClassSpaceSize : 528482304 B Class Space Used : 21412264 B Class Space Capacity : 25373696 B Class Space Committed : 44572672 B Class Space Reserved : 1073741824 B NonClass Spaces Used : 178477376 B NonClass Spaces Capacity : 219028480 B NonClass Spaces Committed : 347594752 B NonClass Spaces Reserved : 348127232 BWandy
I struggled to determine what was causing metaspace leaks in my project. I used jcmd PID GC.class_stats to identify the resident classes, then a heap dump + VisualVM to identify what (which GC root) was holding onto these unwanted classes.Fortyniner
G
0

If you wanted to dig into what your metaspace allocations are, a more in depth option would be to use Native Memory Tracking. You would want to use detail level native memory tracking, which can be enabled by passing -XX:NativeMemoryTracking=detail to the JVM. Then you can run

jcmd <pid> VM.native_memory baseline

To establish a baseline. Then after letting the JVM run until the problem should have reoccurred, you can run

jcmd <pid> VM.native_memory detail.diff

Then the Class allocations in the NMT diff will provide the metaspace allocations. The orcale docs have more information on NMT.

Gonroff answered 31/5, 2022 at 20:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.