Docker Community Forums

Share and learn in the Docker community.

How to dump heap from a Java program running in container


(Mrjunwang) #1

On host machine, when dumping the heap of a Java process in container, I got an error:

# docker ps
CONTAINER ID        IMAGE                 COMMAND        CREATED             STATUS              PORTS               NAMES
acbf49802353        while:1.0             "/root/boot"   4 days ago          Up 4 days                               trusting_fermi
# ps aux | grep java
root     134937  0.2  1.2 42757600 1662936 ?    Sl   Aug27  14:22 java -jar /root/while.jar
# jmap -heap 134937
Attaching to process ID 134937, please wait...
sun.jvm.hotspot.debugger.NoSuchSymbolException: Could not find symbol "gHotSpotVMTypes" in any of the known library names (libjvm.so, libjvm_g.so, gamma_g)
        at sun.jvm.hotspot.HotSpotTypeDataBase.lookupInProcess(HotSpotTypeDataBase.java:585)
        at sun.jvm.hotspot.HotSpotTypeDataBase.readVMTypes(HotSpotTypeDataBase.java:150)
        at sun.jvm.hotspot.HotSpotTypeDataBase.<init>(HotSpotTypeDataBase.java:85)
        at sun.jvm.hotspot.bugspot.BugSpotAgent.setupVM(BugSpotAgent.java:569)
        at sun.jvm.hotspot.bugspot.BugSpotAgent.go(BugSpotAgent.java:493)
        at sun.jvm.hotspot.bugspot.BugSpotAgent.attach(BugSpotAgent.java:331)
        at sun.jvm.hotspot.tools.Tool.start(Tool.java:163)
        at sun.jvm.hotspot.tools.HeapSummary.main(HeapSummary.java:40)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:606)
        at sun.tools.jmap.JMap.runTool(JMap.java:197)
        at sun.tools.jmap.JMap.main(JMap.java:128)
Debugger attached successfully.
sun.jvm.hotspot.tools.HeapSummary requires a java VM process/core!

If attach into the container:

# docker attach trusting_fermi
bash-4.3# ps
PID   USER     TIME   COMMAND
  1   root     0:00   /bin/sh -c /root/boot
  5   root     0:00   {busybox} ash /root/boot
  6   root     0:00   java -jar while.jar
  7   root     0:00   /bin/bash
 27   root     0:00   ps
bash-4.3# jmap -heap 6
Attaching to process ID 6, please wait...
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process

How can I dump the heap of a Java process running in a container?


(Sabin Basyal) #2

Instead of doing docker attach, can you try docker exec -it trusting_fermi /bin/bash?


(Mrjunwang) #3

There’s no difference between using “docker attach” and “docker exec -it”. They both can get into the container by /bin/bash. The error remains the same:

# /opt/jdk1.7.0_80/bin/jmap -heap 6
Attaching to process ID 6, please wait...
Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process

I am wondering if it is because Java debug tool jmap cannot find the process information of Java program running in container. But how to make it work?

Help!


(Mrjunwang) #4

Problem solved by applying method in https://github.com/jpetazzo/nsenter

Thanks !