25

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

czh
  • 395
  • 1
  • 3
  • 8
  • 3
    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. – apangin Jun 20 '16 at 10:31
  • 2
    We have an application causes Metaspace OOM error with 1G of MaxMetaspaceSize, and I wanted to know how Metaspace memories are being used. – czh Jun 20 '16 at 21:56

2 Answers2

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.

apangin
  • 92,924
  • 10
  • 193
  • 247
  • 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? – czh Jun 21 '16 at 05:57
  • jhat eventually terminated with heap space OOM error after running about 2 hours. – czh Jun 21 '16 at 06:05
  • 1
    @czh [Eclipse Memory Analyzer](http://www.eclipse.org/mat/) works fine even with large heap dumps. – apangin Jun 21 '16 at 06:52
  • @czh You can also try VisualVM or YourKit for larger heaps. – Peter Lawrey Jun 21 '16 at 07:41
  • 1
    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 B – machinarium Mar 30 '19 at 14:38
  • 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. – SP193 Feb 12 '23 at 07:00
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.

JSchlather
  • 1,564
  • 2
  • 13
  • 22