jmap error: unknown CollectedHeap type

jmap error: unknown CollectedHeap type

Use the jmap -heap command to view the detailed information of the heap and report an error

Caused by: java.lang.RuntimeException: unknown CollectedHeap type: class sun.jvm.hotspot.gc_interface.CollectedHeap

[root@dahai-java ~]# jmap -heap 27822
Attaching to process ID 27822, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.222-b10

using thread-local object allocation.
Parallel GC with 4 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 0
   MaxHeapFreeRatio = 100
   MaxHeapSize = 1073741824 (1024.0MB)
   NewSize = 536870912 (512.0MB)
   MaxNewSize = 536870912 (512.0MB)
   OldSize = 536870912 (512.0MB)
   NewRatio = 2
   SurvivorRatio = 8
   MetaspaceSize = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize = 17592186044415 MB
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.tools.jmap.JMap.runTool(JMap.java:201)
        at sun.tools.jmap.JMap.main(JMap.java:130)
Caused by: java.lang.RuntimeException: unknown CollectedHeap type: class sun.jvm.hotspot.gc_interface.CollectedHeap
        at sun.jvm.hotspot.tools.HeapSummary.run(HeapSummary.java:157)
        at sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:260)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:223)
        at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
        at sun.jvm.hotspot.tools.HeapSummary.main(HeapSummary.java:50)
        ... 6 more

Strange, it’s ok locally, but this happens on linux

Check the jdk version, all are 1.8, no problem

Local is HotSpot

Online is OpenJDK

Ultimate cause

The -heap parameter here will call the debug package under sun.jvm, which is not included in the default openJDK installation!

Solution

Download and install a java-openjdk-debug plug-in! And it needs to be consistent with the small version of openjdk ! ! !

Install debuginfo

Go to the website http://debuginfo.centos.org/7/x86_64 to find the version that matches the current openjdk, and the minor version number should also match.

Then use wget command to download

wget http://debuginfo.centos.org/7/x86_64/java-1.8.0-openjdk-debuginfo-1.8.0.222.b10-0.el7_6.x86_64.rpm

Use the rpm command to install

rpm -ivh java-1.8.0-openjdk-debuginfo-1.8.0.222.b10-0.el7_6.x86_64.rpm

Check if debuginfo is installed

[root@dahai-java ~]# rpm -qa|grep debuginfo
java-1.8.0-openjdk-debuginfo-1.8.0.222.b10-0.el7_6.x86_64

Query again

[root@dahai-java ~]# jmap -heap 27968
Attaching to process ID 27968, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.222-b10

using thread-local object allocation.
Parallel GC with 4 thread(s)

Heap Configuration:
   MinHeapFreeRatio = 0
   MaxHeapFreeRatio = 100
   MaxHeapSize = 2147483648 (2048.0MB)
   NewSize = 1073741824 (1024.0MB)
   MaxNewSize = 1073741824 (1024.0MB)
   OldSize = 1073741824 (1024.0MB)
   NewRatio = 2
   SurvivorRatio = 8
   MetaspaceSize = 21807104 (20.796875MB)
   CompressedClassSpaceSize = 1073741824 (1024.0MB)
   MaxMetaspaceSize = 17592186044415 MB
   G1HeapRegionSize = 0 (0.0MB)

Heap Usage:
PS Young Generation
Eden Space:
   capacity = 1054867456 (1006.0MB)
   used = 521443544 (497.28731536865234MB)
   free = 533423912 (508.71268463134766MB)
   49.43213870463741% used
From Space:
   capacity = 8388608 (8.0MB)
   used = 8377312 (7.989227294921875MB)
   free = 11296 (0.010772705078125MB)
   99.86534118652344% used
To Space:
   capacity = 9437184 (9.0MB)
   used = 0 (0.0MB)
   free = 9437184 (9.0MB)
   0.0% used
PS Old Generation
   capacity = 1073741824 (1024.0MB)
   used = 334280072 (318.79431915283203MB)
   free = 739461752 (705.205680847168MB)
   31.132257729768753% used

35880 interned Strings occupying 4018400 bytes.

ok, the solution is over!

Version problems encountered

My jdk version is 1.8.0_222-b10, I found two at http://debuginfo.centos.org/7/x86_64

It’s not easy to download the latest discovery first, then uninstall and re-download another one

rpm uninstall

rpm -e --nodeps java-1.8.0-openjdk-debuginfo-1:1.8.0.222.b10-1.el7_7.x86_64

Reinstall afterwards

Reference: https://cloud.tencent.com/developer/article/1511646 jmap error: unknown CollectedHeap type-云+社区-Tencent Cloud