开发者

Core dump equivalent for Java

开发者 https://www.devze.com 2022-12-23 07:26 出处:网络
So far I have learned about generating thread dump and heap dump using jstack and and jmap respectively.

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 debug开发者_StackOverflow社区ging 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?


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.


I've found relevant information in a Sun forum and in an SO discussion: I have not had much luck with it, but it might work in your case.

Note: some of the tools mentioned are Java tools, but are unsupported and are not available on Windows versions of the JDK.


I don't think such a dump mechanism exists in standard Java.


Some operating systems (for example Solaris mdb or gdb on Linux) support using the normal native debugger on dump files, with some special support for showing Java stack frames. But this is pretty hardcore and probably not what you want, since it is not well integrated with the Java Debugger.

0

精彩评论

暂无评论...
验证码 换一张
取 消