jmap錯誤:unknown CollectedHeap type : class sun.jvm.hotspot.gc_interface.CollectedHeap

  • 2019 年 10 月 6 日
  • 筆記

使用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找到兩個

先下載了個最新的發現並不好使,之後卸載重新下載另一個

rpm卸載

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

之後重新安裝即可