How do I Save the Heap (Dump to a File) in Eclipse?

孤街浪徒 提交于 2019-12-31 23:08:01

问题


I'm getting this error when I run or debug my GA/AI from MyEclipse:

Exception in thread "main" java.lang.OutOfMemoryError: Java heap space

eclipse.ini looks like this:

-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:

"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:

"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.


回答1:


There are a number of ways to get heap dumps. Here are some I've used:

  1. -XX:+HeapDumpOnOutOfMemoryError should get you dump if you hit your OOM.
  2. Connect with VisualVM (free) and use its GUI to force a heap dump
  3. Use one of the many good commercial profilers (JProfiler, YourKit, ...)
  4. Use jmap (see below) to force a dump from a running process

If you're running Java 6, jmap should 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:

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.




回答2:


-XX:+HeapDumpOnOutOfMemoryError should be put in "VM Arguments" not "Program Arguments"




回答3:


You can monitor memory usages with JConsole.

The jstat also will help.



来源:https://stackoverflow.com/questions/837351/how-do-i-save-the-heap-dump-to-a-file-in-eclipse

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!