今天在查看 JVM 堆内存具体使用情况的时候,执行 jmap 命令发现如下的报错信息,报错说的是虚拟机版本不匹配,感觉很奇怪因为我刚在另外一台机器上执行了这个命令,换了一台机器就执行报错,初步判断是机器环境的问题,最后对比了两个机器的 JDK 环境,发现报错的这台机器上有两个不同版本的 JDK 所以推测跟多个版本有关系.
Error attaching to process: sun.jvm.hotspot.runtime.VMVersionMismatchException: Supported versions are 25.221-b11. Target VM is 25.111-b14 sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.runtime.VMVersionMismatchException: Supported versions are 25.221-b11. Target VM is 25.111-b14 at sun.jvm.hotspot.HotSpotAgent.setupVM(HotSpotAgent.java:435) at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:305) at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:140) at sun.jvm.hotspot.tools.Tool.start(Tool.java:185) at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118) at sun.jvm.hotspot.tools.HeapSummary.main(HeapSummary.java:49) 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: sun.jvm.hotspot.runtime.VMVersionMismatchException: Supported versions are 25.221-b11. Target VM is 25.111-b14 at sun.jvm.hotspot.runtime.VM.checkVMVersion(VM.java:227) at sun.jvm.hotspot.runtime.VM.<init>(VM.java:294) at sun.jvm.hotspot.runtime.VM.initialize(VM.java:370) at sun.jvm.hotspot.HotSpotAgent.setupVM(HotSpotAgent.java:431) ... 11 more
解决办法有两个,最简单直接的就是删除其中一个 JDK 只保留一个即可,另外一种方法是执行命令的时候指定 JDK 的绝对路径,这样也可以解决.
/home/jason/bigdata/jdk/jdk1.8.0_111/bin/jmap -heap 23639 [root@storm1 jdk]# /home/jason/bigdata/jdk/jdk1.8.0_111/bin/jmap -heap 23639 Attaching to process ID 23639, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.111-b14 using parallel threads in the new generation. using thread-local object allocation. Concurrent Mark-Sweep GC Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 161480704 (154.0MB) NewSize = 53084160 (50.625MB) MaxNewSize = 53084160 (50.625MB) OldSize = 108396544 (103.375MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxMetaspaceSize = 268435456 (256.0MB) G1HeapRegionSize = 0 (0.0MB) Heap Usage: New Generation (Eden + 1 Survivor Space): capacity = 47775744 (45.5625MB) used = 41301888 (39.3885498046875MB) free = 6473856 (6.1739501953125MB) 86.44949202674897% used Eden Space: capacity = 42467328 (40.5MB) used = 41134400 (39.22882080078125MB) free = 1332928 (1.27117919921875MB) 96.86128592785494% used From Space: capacity = 5308416 (5.0625MB) used = 167488 (0.15972900390625MB) free = 5140928 (4.90277099609375MB) 3.1551408179012346% used To Space: capacity = 5308416 (5.0625MB) used = 0 (0.0MB) free = 5308416 (5.0625MB) 0.0% used concurrent mark-sweep generation: capacity = 108396544 (103.375MB) used = 29516576 (28.149200439453125MB) free = 78879968 (75.22579956054688MB) 27.230181803582227% used 18288 interned Strings occupying 1882760 bytes.