views:

1134

answers:

4

We have a long running server application running Java 5, and profiling it we can see the old generation growing slowly over time. It's correctly freed on a full GC, but I'd like to be able to look at the unreachable objects in Eclipse MAT using a heap dump. I've successfully obtained a heap dump using +XX:HeapDumpOnCtrlBreak, but the JVM always does a GC before dumping the heap. Apparently this doesn't happen on Java 6 but we're stuck on 5 for now. Is there any way to prevent this?

+2  A: 

I suggest a 3rd-party profiler such as YourKit, which may allow you to take snapshots without kicking off the GC first. Added bonus, you can take a snapshot without the whole ctrl-break shenanigans.

skaffman
Thanks, I actually have a copy of JProfiler, but I didn't realise it could do this. I'll give it a go.
Colin
A: 

jProfiler (ej-technologies) can do this.

Software Monkey
+1  A: 

I have some code here that can programmatically take a heap dump over JMX:

Link: JmxHeapDumper.java

The comments in the source code contain 2 links to articles that contained useful information about how to take heap dumps. I don't know for sure but if you are in luck, perhaps the JMX approach would have some way of avoiding the GC. Hope this helps !

Peter Thomas
Great, thanks, I'll take a look and see if it GCs beforehand or not. Being able to do it programmatically seems pretty useful, actually.
Colin
A: 

JmxHeapDumper.java works only for Java6 and above. Any programmable way of getting a heap dump on a remote JVM running Java-150_10 on Windows?

Sam

From what I can tell, the only way is to use one of the profiling tools discussed above. You can also use the +XX:HeapDumpOnCtrlBreak flag with the caveat that it will GC before getting the dump.
Colin