jmap错误:unknown CollectedHeap type : class sun.jvm.hotspot.gc_interface.CollectedHeap

使用jmap -heap命令查看堆的详细信息报错

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

[root@bangbet-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

奇怪,在本地是没问题的,在linux上却出现这种情况

查看了下jdk版本,都是1.8,没啥问题呀

本地是HotSpot

线上是OpenJDK

最终原因

这里-heap参数会调用用到了sun.jvm下的debug包,而默认openJDK的安装中不包含!

解决方式

下载并安装一个java-openjdk-debug插件!而且需要和openjdk小版本也一致!!!

安装debuginfo

去网站http://debuginfo.centos.org/7/x86_64里面找匹配当前的openjdk的版本,小版本号也要匹配上。

然后使用wget命令下载

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

使用rpm命令安装

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

查看是否安装了debuginfo

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

再次查询

[root@bangbet-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,解决完毕!

遇到的版本问题

我的jdk版本是1.8.0_222-b10,在http://debuginfo.centos.org/7/x86_64找到两个

jmap错误:unknown CollectedHeap type : class sun.jvm.hotspot.gc_interface.CollectedHeap_第1张图片

先下载了个最新的发现并不好使,之后卸载重新下载另一个

rpm卸载

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

之后重新安装即可

你可能感兴趣的:(jmap错误:unknown CollectedHeap type : class sun.jvm.hotspot.gc_interface.CollectedHeap)