So far I have learned about generating thread dump and heap dump using jstack
and and jmap
respectively.
However, jstack
thread dump contains only texts describing the stack on each thread. And opening heap dump (.hprof file) with Java VisualVM only shows the objects allocated in the heap.
What I actually want is to be able see the stack, to switch to particular stack frame, and watch local variables. This kind of post-mortem debugging can be done normally with tools like WinDbg, gdb and a core file (for a native C++ program.)
I wonder if such 'core' file (which will allow me to debug in non-live environment) exists in Java?
A core dump is a binary file capturing the entire heap contents at the moment the dump is captured. When you load a core dump in Java VisualVM, a node for the core dump appears below the Core Dump node. To view an overview of the core dump, right-click the core dump node and choose Open.
To control the core dump file size, you use the ulimit command, and the -c argument. You set it to 0 to disable core dumps, and to unlimited to enable them. If you run ulimit -c unlimited , you will enable core dumps for all users and all programs.
A thread dump is a snapshot of the state of all the threads of a Java process. The state of each thread is presented with a stack trace, showing the content of a thread's stack. A thread dump is useful for diagnosing problems, as it displays the thread's activity.
Core dump - Application use ,, Used to dump some Application core files, If was there any Application realted issues. crash dump -> This Used for both Application & System hardware & software failure.
Java does. If you are using an IBM VM, use com.ibm.jvm.Dump.SystemDump()
to programatically generate a dump. This can be debugged using a debugger. I believe "kill"ing your Java process should generate a system dump too. For Unix use kill -4 pid
where pid is the process id and could be queried by typing in top | grep java
if you have 1 VM instance running.
You could also add -Xdump:system
or -Xdump:heap
etc to your java command line to filter events and generate dumps on certain events like VM Stop (-Xdump:system:events=vmstop
), full garbage collections(-Xdump:system:events=fullgc
), etc. Note, depending on your heap size, generating a dump on a full GC is may not be a good idea (i.e you might create 50 dumps withing 20 seconds if you heap grows from 4M to around 60M in 20 seconds ) so you could add a counter like -Xdump:system:events=fullgc,range=50..55
which would generate 5 cores between the 50th to the 55th full garbage collect.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With