Reputation: 179
I'm tired to trying to dump java heap when I need it. Any time when I could do that none of utils are not able to do that. I'm trying jmap
, jvisualvm
, jconsole
, jmc
and none of them not able to do that easy task -- just dump the *** heap!
How people uses that programs???
First, I tried visual instruments, but none of them have worked (sorry, but I didn't think that I'll need screenshots of their errors). Ok, I did think, but console tools should work!
$ 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)
What?
$ 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
Ok...
$ 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)
Hm...
$ 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)
WTF???
This is the basics! Why the java tools are so poor? How I should get the heap? That is not a single case. I've got such results every time when I trying to get the dump
For the reference, this is how program launched:
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>
Upvotes: 0
Views: 2153
Reputation: 1660
jmap -dump:format=b,file=server.bin ...
: will only work if 1) the JVM is not frozen, e.g. due to permanent full GC, because it uses a cooperative mechanism where the target JVM actually runs commands doing the heap dump (Java Attach API), 2) you run jmap
as the same user as the one who started the JVM. I take from your comments that condition 1) is not met in your case.jmap -F -dump:format=b,file=server.bin ...
: the option -F
was removed in JDK 9.jhsdb jmap --binaryheap --dumpfile server.bin --pid ...
: fails because you either need to run it as root or set some liberal restrictions in the linux kernel for ptrace (ptrace_scope should be 0).sudo jhsdb jmap --binaryheap --dumpfile server.bin --pid ...
: has a restriction that jhsdb
must come from the exactly same JDK version as the target JVM (like, if the target JVM has version 14.1.2+3
then I would make sure that jhsdb
comes from JDK 14.1.2+3
as well just for safety). Seems to be the case in your case because no warning is printed, but I would suggest to check it for sure. The only other thing I can think of is you might need to install openjdk-debuginfo
as mentioned e.g. here.Upvotes: 2
Reputation: 566
Firstly you need find the real java jpid:
launch jps, find the pid value like:
./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
Your pid should be one of the list. Please find yours.
./jmap -dump:live,format=b,file=heap.bin 39616
Finally you will find the heap.bin
Upvotes: 0