我厭倦了在需要時嘗試轉儲 Java 堆。任何時候我可以做到這一點,沒有一個工具不能做到這一點。我正在嘗試jmap, jvisualvm, jconsole,jmc沒有一個人不能完成這項簡單的任務——只需轉儲 *** 堆!
人們如何使用這些程式???
首先,我嘗試了視覺儀器,但它們都沒有奏效(對不起,但我認為我不需要他們的錯誤截圖)。好的,我確實認為,但是控制臺工具應該可以作業!
$ jmap -dump:format=b,file=server.bin 136447
Exception in thread "main" com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file /proc/136447/root/tmp/.java_pid136447: target process 136447 doesn't respond within 10500ms or HotSpot VM not loaded
at jdk.attach/sun.tools.attach.VirtualMachineImpl.<init>(VirtualMachineImpl.java:103)
at jdk.attach/sun.tools.attach.AttachProviderImpl.attachVirtualMachine(AttachProviderImpl.java:58)
at jdk.attach/com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:207)
at jdk.jcmd/sun.tools.jmap.JMap.executeCommandForPid(JMap.java:128)
at jdk.jcmd/sun.tools.jmap.JMap.dump(JMap.java:218)
at jdk.jcmd/sun.tools.jmap.JMap.main(JMap.java:114)
什么?
$ jmap -F -dump:format=b,file=server.bin 136447
Error: -F option used
Cannot connect to core dump or remote debug server. Use jhsdb jmap instead
行...
$ jhsdb jmap --binaryheap --dumpfile server.bin --pid 136447
Attaching to process ID 136447, please wait...
ERROR: ptrace(PTRACE_ATTACH, ..) failed for 136447: Операция не позволена
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 136447: Операция не позволена
sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 136447: Операция не позволена
at jdk.hotspot.agent/sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.execute(LinuxDebuggerLocal.java:179)
at jdk.hotspot.agent/sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach(LinuxDebuggerLocal.java:337)
at jdk.hotspot.agent/sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:672)
at jdk.hotspot.agent/sun.jvm.hotspot.HotSpotAgent.setupDebuggerLinux(HotSpotAgent.java:612)
at jdk.hotspot.agent/sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:338)
at jdk.hotspot.agent/sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:305)
at jdk.hotspot.agent/sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:141)
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:321)
at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.main(SALauncher.java:406)
Caused by: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..) failed for 136447: Операция не позволена
at jdk.hotspot.agent/sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach0(Native Method)
at jdk.hotspot.agent/sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$1AttachTask.doit(LinuxDebuggerLocal.java:328)
at jdk.hotspot.agent/sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.run(LinuxDebuggerLocal.java:154)
嗯……
$ sudo jhsdb jmap --binaryheap --dumpfile server.bin --pid 136447
[sudo] пароль для Mingun:
Attaching to process ID 136447, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 14.0.2 12-Ubuntu-120.04
sun.jvm.hotspot.types.WrongTypeException: No suitable match for type of address 0x00007f20500286d0
at jdk.hotspot.agent/sun.jvm.hotspot.runtime.InstanceConstructor.newWrongTypeException(InstanceConstructor.java:62)
at jdk.hotspot.agent/sun.jvm.hotspot.runtime.VirtualConstructor.instantiateWrapperFor(VirtualConstructor.java:80)
at jdk.hotspot.agent/sun.jvm.hotspot.memory.Universe.heap(Universe.java:102)
at jdk.hotspot.agent/sun.jvm.hotspot.utilities.HeapHprofBinWriter.write(HeapHprofBinWriter.java:423)
at jdk.hotspot.agent/sun.jvm.hotspot.tools.JMap.writeHeapHprofBin(JMap.java:182)
at jdk.hotspot.agent/sun.jvm.hotspot.tools.JMap.run(JMap.java:97)
at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.startInternal(Tool.java:262)
at jdk.hotspot.agent/sun.jvm.hotspot.tools.Tool.start(Tool.java:225)
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:321)
at jdk.hotspot.agent/sun.jvm.hotspot.SALauncher.main(SALauncher.java:406)
怎么回事???
這是基礎!為什么java工具這么差?我應該如何獲得堆?這不是一個案例。每次嘗試轉儲時,我都會得到這樣的結果
作為參考,這是程式的啟動方式:
java -XX:-OmitStackTraceInFastThrow -XX: ShowCodeDetailsInExceptionMessages -XX: PrintConcurrentLocks -agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=9009 -server -Xmx3G -Duser.language=en -Duser.region=US <main class> <app parameters>
uj5u.com熱心網友回復:
jmap -dump:format=b,file=server.bin ...: 僅在 1) JVM 沒有被凍結時起作用,例如由于永久完全 GC,因為它使用協作機制,其中目標 JVM 實際運行執行堆轉儲(Java Attach API)的命令,2)您jmap以相同的方式運行用戶作為啟動 JVM 的人。我從您的評論中得知,您的情況不滿足條件 1)。jmap -F -dump:format=b,file=server.bin ...: 該選項-F在 JDK 9 中被洗掉。jhsdb jmap --binaryheap --dumpfile server.bin --pid ...: 失敗,因為您要么需要以 root 身份運行它,要么在 linux 內核中為 ptrace 設定一些自由限制(ptrace_scope應該為 0)。sudo jhsdb jmap --binaryheap --dumpfile server.bin --pid ...: 有一個限制,它jhsdb必須來自與目標 JVM 完全相同的 JDK 版本(例如,如果目標 JVM 有版本,14.1.2 3那么我會確保它也jhsdb來自 JDK14.1.2 3,只是為了安全起見)。您的情況似乎就是這種情況,因為沒有列印警告,但我建議您確定檢查一下。我能想到的唯一另一件事是您可能需要按照此處openjdk-debuginfo所述進行安裝。
uj5u.com熱心網友回復:
首先你需要找到真正的java jpid:
啟動 jps,找到 pid 值,如:
./jps
15552 org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar
2816 org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar
29504 org.eclipse.equinox.launcher_1.6.400.v20210924-0641.jar
34032 Jps
39616 org.eclipse.equinox.launcher_1.6.100.v20201223-0822.jar
10248 org.eclipse.equinox.launcher_1.3.201.v20161025-1711.jar
您的 pid 應該是串列之一。請找到你的。
- 創建轉儲
./jmap -dump:live,format=b,file=heap.bin 39616
最后你會找到heap.bin
uj5u.com熱心網友回復:
你有什么問題?
只需閱讀****手冊,搜索錯誤訊息/例外:“com.sun.tools.attach.AttachNotSupportedException”。
基于此,我假設您查詢堆轉儲的 JVM 的配置方式不支持 Attach API,因此所有控制臺工具都變得無用......
通常,這是 J9 JVM 的默認設定(或曾經是默認設定),但從提供的堆疊跟蹤來看,至少您的工具在 Hotspot 上運行。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/474284.html
