[jvm] sun.jvm.hotspot.runtime.VMVersionMismatchException: Supported versions are 25.51-b03

一、问题现象

在打印java堆信息时报错。

jmap -heap \<PID>

二、报错内容

Error attaching to process: sun.jvm.hotspot.runtime.VMVersionMismatchException: Supported versions are 25.51-b03. Target VM is 25.162-b12
sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.runtime.VMVersionMismatchException: Supported versions are 25.51-b03. Target VM is 25.162-b12
	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:497)
	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.51-b03. Target VM is 25.162-b12
	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
whereis java

查看如下:
在这里插入图片描述

  • 使用当前java进程所用的jdk
/opt/jdk1.8.0_162/bin/jmap  -heap <PID>


执行成功!

你可能感兴趣的:(java,java)