Java 的核心转储等效项
到目前为止,我已经了解了分别使用 jstack
和 jmap
生成线程转储和堆转储。
但是,jstack
线程转储仅包含描述每个线程上的堆栈的文本。使用 Java VisualVM 打开堆转储(.hprof 文件)仅显示堆中分配的对象。
我真正想要的是能够看到堆栈,切换到特定的堆栈帧,并观察局部变量。这种事后调试通常可以使用 WinDbg、gdb 和核心文件(对于本机 C++ 程序)等工具来完成。
我想知道是否有这样的“核心”文件(这将允许我在非实时环境中进行调试) Java 中存在吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Java 确实如此。如果您使用的是 IBM VM,请使用 com.ibm.jvm.Dump.SystemDump() 以编程方式生成转储。这可以使用调试器进行调试。我相信“杀死”你的Java进程也应该生成系统转储。对于 Unix,请使用
kill -4 pid
,其中 pid 是进程 ID,可以通过输入top | 进行查询。 grep java
如果您有 1 个虚拟机实例正在运行。您还可以将
-Xdump:system
或-Xdump:heap
等添加到 java 命令行来过滤事件并针对某些事件(例如 VM Stop)生成转储(- Xdump:system:events=vmstop
)、完整垃圾收集(-Xdump:system:events=fullgc
) 等。请注意,根据您的堆大小,在完整垃圾收集上生成转储GC 可能不是一个好主意(即,如果堆在 20 秒内从 4M 增长到大约 60M,您可能会在 20 秒内创建 50 个转储),因此您可以添加一个类似-Xdump:system:events=fullgc 的计数器, range=50..55
这将在第 50 次到第 55 次完整垃圾收集之间生成 5 个核心。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 usekill -4 pid
where pid is the process id and could be queried by typing intop | 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.我在 Sun 论坛 和 SO 中找到了相关信息讨论:我没有太多运气,但它可能适用于你的情况。
注意:提到的一些工具是 Java 工具,但不受支持,并且在 Windows 版本的 JDK 上不可用。
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.
我认为标准 Java 中不存在这样的转储机制。
I don't think such a dump mechanism exists in standard Java.
某些操作系统(例如 Linux 上的 Solaris mdb 或 gdb)支持在转储文件上使用普通的本机调试器,并对显示 Java 堆栈帧提供一些特殊支持。但这是相当硬核的,可能不是您想要的,因为它与 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.