jmap -heap pid 执行报错的解决方法: unknown CollectedHeap type : class sun.jvm.hotspot.gc_interface.Collect...

背景

环境

系统:

$ cat /etc/system-release
CentOS Linux release 7.4.1708 (Core)
$ java -version
openjdk version "1.8.0_151"
OpenJDK Runtime Environment (build 1.8.0_151-b12)
OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

复现

执行jmap -heap检查JVM堆情况时, 报错unknown CollectedHeap type : class sun.jvm.hotspot.gc_interface.CollectedHeap. 具体如下:

[root@node03 ~]# jmap -heap 9225
Attaching to process ID 9225, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.181-b13

using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC

Heap Configuration:
   MinHeapFreeRatio         = 40
   MaxHeapFreeRatio         = 70
   MaxHeapSize              = 2147483648 (2048.0MB)
   NewSize                  = 427819008 (408.0MB)
   MaxNewSize               = 427819008 (408.0MB)
   OldSize                  = 1719664640 (1640.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)

原因

从报错信息可以很容易看到是找不到相应的类.

解决

到这个网站http://debuginfo.centos.org/7/x86_64/中找到与系统和jvm相对应的包.
举个例子, 我的系统是centos7, java版本是openjdk version "1.8.0_151", 所以应该下载java-1.8.0-openjdk-debuginfo-1.8.0.151-1.b12.el7_4.x86_64.rpm

$ wget http://debuginfo.centos.org/7/x86_64/java-1.8.0-openjdk-debuginfo-1.8.0.151-1.b12.el7_4.x86_64.rpm   ## 下载
$ rpm -ivh java-1.8.0-openjdk-debuginfo-1.8.0.151-1.b12.el7_4.x86_64.rpm          ## 安装
$ rpm -qa | grep debuginfo                                                                      ## 检查是否安装成功

这回, 再执行jmap -heap ${JVM_PID} 就不会报错了.

你可能感兴趣的:(jmap -heap pid 执行报错的解决方法: unknown CollectedHeap type : class sun.jvm.hotspot.gc_interface.Collect...)