-XX:+HeapDumpOnOutOfMemoryError 未在 OOM 中创建 hprof 文件
我使用以下参数(以及其他参数)-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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不会尝试从 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).
内存不足在第一个错误时仅生成一个转储文件。如果你想获得更多,你可以尝试 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.