java 如何在 Eclipse 中保存堆(转储到文件)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/837351/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I Save the Heap (Dump to a File) in Eclipse?
提问by Dave Babbitt
I'm getting this error when I run or debug my GA/AI from MyEclipse:
当我从 MyEclipse 运行或调试我的 GA/AI 时出现此错误:
Exception in thread "main" java.lang.OutOfMemoryError: Java heap space
线程“main”中的异常 java.lang.OutOfMemoryError: Java heap space
eclipse.ini looks like this:
eclipse.ini 看起来像这样:
-showsplash com.genuitec.myeclipse.product
--launcher.XXMaxPermSize 256m
-vmargs
-Xms128m
-Xmx512m
-Duser.language=en
-XX:PermSize=128M
-XX:MaxPermSize=256M
MyEclipse is called like this:
MyEclipse 是这样调用的:
"C:\Program Files\MyEclipse 6.0\eclipse\eclipse.exe" -vm "C:\Program Files\MyEclipse 6.0\jre\bin\javaw.exe" -vmargs -Xms1448M -Xmx1448M
bumping the vm settings up from this:
从这里提高 vm 设置:
"C:\Program Files\MyEclipse 6.0\eclipse\eclipse.exe" -vm "C:\Program Files\MyEclipse 6.0\jre\bin\javaw.exe" -vmargs -Xms80M -Xmx1024M
has had no effect. So I'm trying to get it to dump the heap to a file, but placing these:
没有效果。所以我试图让它将堆转储到一个文件,但放置这些:
-XX:+HeapDumpOnCtrlBreak
-XX:+HeapDumpOnOutOfMemoryError
in the Program arguments has had no effect. How do I get something to work with more memory usage analysis? jstack, for instance, is not currently available on Windows platforms. And using SendSignal has no effect that I can see.
在 Program 参数中没有任何效果。我如何获得更多内存使用分析的工作?例如,jstack 目前在 Windows 平台上不可用。并且使用 SendSignal 没有我能看到的效果。


回答by overthink
There are a number of ways to get heap dumps. Here are some I've used:
有多种方法可以获取堆转储。以下是我用过的一些:
-XX:+HeapDumpOnOutOfMemoryErrorshouldget you dump if you hit your OOM.- Connect with VisualVM(free) and use its GUI to force a heap dump
- Use one of the many good commercial profilers (JProfiler, YourKit, ...)
- Use jmap (see below) to force a dump from a running process
-XX:+HeapDumpOnOutOfMemoryError如果您遇到 OOM,应该让您倾倒。- 连接VisualVM(免费)并使用其 GUI 强制进行堆转储
- 使用众多优秀的商业分析器之一(JProfiler、YourKit 等)
- 使用 jmap(见下文)强制从正在运行的进程转储
If you're running Java 6, jmapshould work on Windows. This might be useful if you want to dump the heap and you haven't hit your OOM. Use Windows Task Manager to find the pid of your Java app, and in a console run this:
如果您运行的是 Java 6,jmap应该可以在 Windows 上运行。如果您想转储堆并且还没有达到 OOM,这可能很有用。使用 Windows 任务管理器查找 Java 应用程序的 pid,并在控制台中运行:
jmap -dump:format=b,file=c:\heap.bin <pid>
In addition to VisualVM, the Eclipse Memory Analyzer(also free) can help you analyze what's eating up all the space once you've got the dump.
除了 VisualVM,Eclipse 内存分析器(也是免费的)可以帮助您在获得转储后分析占用所有空间的内容。
回答by dave
-XX:+HeapDumpOnOutOfMemoryErrorshould be put in "VM Arguments" not "Program Arguments"
-XX:+HeapDumpOnOutOfMemoryError应该放在“ VM Arguments”而不是“ Program Arguments”

