一个jinfo使用问题的解决 can’t determine target’s VM version

1. 问题

在使用jinfo查看进程所运行的环境变量信息时,报can’t determine target’s VM version的错误。

$ jinfo -sysprops 15444
Attaching to process ID 15444, please wait...
Error attaching to process: java.lang.RuntimeException: can't determine target's VM version : field "_reserve_for_allocation_prefetch" not found in type Abstract_VM_Version
sun.jvm.hotspot.debugger.DebuggerException: java.lang.RuntimeException: can't determine target's VM version : field "_reserve_for_allocation_prefetch" not found in type Abstract_VM_Version
        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.JInfo.main(JInfo.java:138)
        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.jinfo.JInfo.runTool(JInfo.java:108)
        at sun.tools.jinfo.JInfo.main(JInfo.java:76)
Caused by: java.lang.RuntimeException: can't determine target's VM version : field "_reserve_for_allocation_prefetch" not found in type Abstract_VM_Version
        at sun.jvm.hotspot.runtime.VM.<init>(VM.java:291)
        at sun.jvm.hotspot.runtime.VM.initialize(VM.java:370)
        at sun.jvm.hotspot.HotSpotAgent.setupVM(HotSpotAgent.java:431)
        ... 11 more

2. 解决方法

  1. 刚开始认为是应用程序打包时没有指定编译的目标JDK,检查后排除了这个问题。
  2. 然后网上查找,有文说是权限问题,在Linux下使用su命令可以解决问题,但是我的是在windows下,应该不是权限问题。
  3. 然后想了想,会不会是jdk8/jdk9的配置不对,重新配置后,问题依然在,无论使用jdk8的jinfo,还是jdk9的jinfo都报同样问题。
  4. 最后觉得会不会是环境变量配置问题,然后使用set命令查看了下环境变量,发现path对应有如下设置,
    Path=...;G:\local\java-1.8.0-openjdk-1.8.0.151\bin;...
    
    在path中定义的java路径为open jdk 8。 将oracle jdk 9的路径指定到path中后,问题得到解决。
    set JDK_HOME=G:\local\java\jdk-9.0.1
    set PATH=%JDK_HOME%\bin;%PATH%
    
    上面看到的问题应该是open jdk 8和oracle jdk 9之间的匹配问题。