V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
justNoBody
V2EX  ›  Java

macOS 11.1 无法使用 jmap 命令

  •  
  •   justNoBody · 2021-01-14 18:11:11 +08:00 · 1905 次点击
    这是一个创建于 1169 天前的主题,其中的信息可能已经有所发展或是发生改变。

    最近才发现 macOS 上 jmap 命令无法使用,报错如下

    ❯ jhsdb jmap --heap --pid 14657
    Attaching to process ID 14657, please wait...
    ERROR: attach: task_for_pid(14657) failed: '(os/kern) failure' (5)
    Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process. Could be caused by an incorrect pid or lack of privileges.
    sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process. Could be caused by an incorrect pid or lack of privileges.
    	at jdk.hotspot.agent/sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal$BsdDebuggerLocalWorkerThread.execute(BsdDebuggerLocal.java:170)
    	at jdk.hotspot.agent/sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal.attach(BsdDebuggerLocal.java:284)
    	at jdk.hotspot.agent/sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:641)
    	at jdk.hotspot.agent/sun.jvm.hotspot.HotSpotAgent.setupDebuggerDarwin(HotSpotAgent.java:629)
    	at jdk.hotspot.agent/sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:364)
    	at jdk.hotspot.agent/sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:329)
    	at jdk.hotspot.agent/sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:139)
    	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.start(Tool.java:187)
    	at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.execute(Tool.java:118)
    	at jdk.hotspot.agent/sun.jvm.hotspot.tools.JMap.main(JMap.java:176)
    	at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.runJMAP(SALauncher.java:331)
    	at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.main(SALauncher.java:483)
    Caused by: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process. Could be caused by an incorrect pid or lack of privileges.
    	at jdk.hotspot.agent/sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal.attach0(Native Method)
    	at jdk.hotspot.agent/sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal$1AttachTask.doit(BsdDebuggerLocal.java:275)
    	at jdk.hotspot.agent/sun.jvm.hotspot.debugger.bsd.BsdDebuggerLocal$BsdDebuggerLocalWorkerThread.run(BsdDebuggerLocal.java:145)
    

    我尝试的解决方案

    1. 根据 https://bugs.openjdk.java.net/browse/JDK-8025666 给出的解决方案就是使用 root 账号来运行,但我sudo jhsdb jmap --heap --pid 14657不行;
    2. 检查过运行所使用的 jdk 和使用 jmap 命令的 jdk,均是同一个。
    3. 升级 jdk 版本。在
    openjdk version "1.8.0_275"
    OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_275-b01)
    OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.275-b01, mixed mode)
    

    openjdk version "15.0.1" 2020-10-20
    OpenJDK Runtime Environment (build 15.0.1+9)
    OpenJDK 64-Bit Server VM (build 15.0.1+9, mixed mode, sharing)
    

    上验证了一下也不行

    2 条回复    2021-11-21 00:04:30 +08:00
    Kobayashi
        1
    Kobayashi  
       2021-01-15 00:59:12 +08:00 via Android
    盲猜:这个进程 ID 已被其他程序占用了?
    10458040
        2
    10458040  
       2021-11-21 00:04:30 +08:00
    解决了吗。遇到同样的问题 切到 jdk17 也不行
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3235 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 13:59 · PVG 21:59 · LAX 06:59 · JFK 09:59
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.