-XX:+HeapDumpOnOutOfMemoryError 未在 OOM 中创建 hprof 文件

发布于 2024-08-07 03:57:51 字数 446 浏览 2 评论 0原文

我使用以下参数(以及其他参数)-XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs 开始我的 java 代码(Vista 中为 1.6.0_16)。我运行代码,可以在日志中看到有两个 OOM。

我知道的第一个是因为我可以在 stdout 中看到正在创建 hprof 文件:

java.lang.OutOfMemoryError: Java heap space
Dumping heap to ../logs\java_pid4604.hprof ...
Heap dump file created [37351818 bytes in 1.635 secs]

然后,在代码末尾我得到另一个 OOM,我捕获了这个,但我没有创建第二个 hprof 文件。有人知道这是为什么吗??是不是因为我捕获了OOM异常?

I start my java code (1.6.0_16 in Vista) with the following params (among others) -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=../logs. I run the code and I can see in the logs there are two OOM.

The first one I know cause I can see in the stdout that the hprof file is being created:

java.lang.OutOfMemoryError: Java heap space
Dumping heap to ../logs\java_pid4604.hprof ...
Heap dump file created [37351818 bytes in 1.635 secs]

And then, towards the end of the code I get another OOM, I capture this, but I don't get a second hprof file created. Anybody knows why is that?? Is it because I have captured the OOM exception?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

治碍 2024-08-14 03:57:51

我不会尝试从 OutOfMemoryError 中恢复,因为某些对象可能最终处于未定义状态(例如,仅考虑无法分配其数组来存储日期的 ArrayList)。

关于你的问题,我怀疑 -XX:+HeapDumpOnOutOfMemoryError 只是故意创建一个转储以防止多个堆转储:只需考虑多个线程同时抛出 OOME,导致每个抛出的异常都进行堆转储。

总结一下:不要尝试从 OOME 中恢复,也不要期望 JVM 写入多个堆转储。但是,如果您仍然觉得需要生成堆转储,您可以尝试手动处理 OOME 异常并调用 jmap 创建转储或使用“-XX:+HeapDumpOnCtrlBreak”(但不确定如何以编程方式模拟 CtrlBreak) 。

I wouldn't try to recover from an OutOfMemoryError as some objects might end up in an undefined state (just thinking about an ArrayList that couldn't allocate its array to store date for instance).

Regarding your question, I'd suspect that -XX:+HeapDumpOnOutOfMemoryError is only creating a single dump intentionally to prevent multiple heap dumps: just think about several threads throwing an OOME at the same time, causing a heap dump for each thrown exception.

As a summary: don't try to recover from OOME and don't expect the JVM to write more than a single heap dump. However, if you still feel the need to generate a heap dump, you could try to manually handle an OOME exception and call jmap to create a dump or use "-XX:+HeapDumpOnCtrlBreak" (not sure though, how to simulate CtrlBreak programmatically).

哎呦我呸! 2024-08-14 03:57:51

内存不足在第一个错误时仅生成一个转储文件。如果你想获得更多,你可以尝试 jmap 或将 jconsole 保留在 jvm(版本 6)上,然后你可以在一切崩溃后,即早上从 jconsole (或你选择的分析工具)创建你自己的转储。

有关转储主题的更多信息,请参阅 Eclipse MemoryAnalyser

Out of memory generates only one dump-file on the first error. If you want to get more you can try jmap or keep jconsole on the jvm (version 6) then you can after everything crashed i.e in the morning create your own dump from jconsole (or your analyser tool of choice).

More on the dumping subject can be read in Eclipse MemoryAnalyser.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文