views:

810

answers:

4

Well this is embarrassing ...

I'm starting to play with the Eclipse Memory Analyzer to look for Java memory leaks on a Windows box. Step 1 is to obtain a heap dump file. To do this I start my Java (javaw.exe) process from within Eclipse and connect to it with jconsole. Then on the jconsole MBeans tab I click the dumpHeap button. The first time I did this, I saw a pop-up saying it had created the heap dump file, but not giving its name or location. Now whenever I do a dumpHeap again while connected to a different javaw.exe process, jconsole says:

Problem invoking dumpHeap : java.io.IOException: File exists

and of course doesn't give its name or path. Where could it be?

I've searched my C: drive (using cygwin command line tools) for files containing "hprof" or "java_pid" or "heapdump" and didn't find anything plausible. I've even used the Windows search to look for all files in my Eclipse workspace that have changed in the last day.

I'm using the Sun Java 1.6 JVM, and don't have -XX:HeapDumpPath set.

Update (28 April 2010): My original heap file location must have been determined by jconsole, the tool I triggered the heap dump from. The JVM's heap dump location must apply only to heap dumps it triggers (eg, on an OutOfMemoryException).

Matt B's suggestion to use jvisualvm nicely solves my problem by pointing me to a far more useful replacement for the old jconsole. It has a nice memory profiler that shows which types of objects are most numerous and hold the most memory. And it has a monitor that shows actual memory use over time. When you ask it for a heap dump, it tells you the file name even! The Eclipse Memory Analyzer gives you full details.

+1  A: 

You could always use ProcessMonitor to see where it's trying to write to :) Done this myself in the past.

Chris Dennett
@Chris: Interesting advice, I'll give it a try!
Jim Ferrans
+2  A: 

According to the docs for the Sun Java SE6 JVM:

By default the heap dump is created in a file called java_pid<pid>.hprof in the working directory of the VM

In Eclipse, the working directory is defined on the "Arguments" tab of the "Run Configurations" dialog. The default value is the same directory as the class that you are running.

Jason Jenkins
Thanks Jason, I'll take a look at the Run Configurations dialog. I was unable to create a second heap dump file for a different process, which would seem to contradict this naming scheme.
Jim Ferrans
Hmm, there was no hprof file in the current directory of the process. Since jvisualvm sets a heapdump file name in a different directory, I suppose jconsole does too?
Jim Ferrans
+2  A: 

Try jvisualvm, it has a much better interface

matt b
Thanks, this solved my problem *and* taught me something new and very useful!
Jim Ferrans
+1  A: 

why don't you set the first parameter for dumpHeap(String,boolean) when you try to invoke dumpHeap() from jconsole? it's the generated heapdump file's location and filename.

tsimgsong