5
votes

I'm trying to diagnose a PermGen memory leak problem in a Sun One 9.1 Application Server. In order to do that I need to get a heap dump of the JVM process. Unfortunately, the JVM process is version 1.5 running on Windows. Apparently, none of the ways for triggering a heap dump support that setup. I can have the JVM do a heap dump after it runs out of memory, or when it shuts down, but I need to be able to get heap dumps at arbitrary times.

The two often mentioned ways for getting heap dumps are either using jmap or using the HotSpotDiagnostic MBean. Neither of those support jvm 1.5 on Windows.

Is there a method that I've missed? If there's a way to programmatically trigger a heap dump (without using the HotSpotDiagnostic MBean), that would do too...

If it's really not possible to do it in Windows, I guess I'd have to resort to building a Linux VM and doing my debugging in there.

Thanks.

2
I've resorted to using -XX:+HeapDumpOnOutOfMemoryError together with a jsp page that tries to allocate very large arrays. I can just hit the jsp page when I need a memory dump. Works well enough.jthg

2 Answers

1
votes

There was a new hotspot option introduced in Java6, -XX:-HeapDumpOnOutOfMemoryError, which was actually backported to the Java5 JVM.

http://java.sun.com/javase/technologies/hotspot/vmoptions.jsp

Dump heap to file when java.lang.OutOfMemoryError is thrown. Manageable. (Introduced in 1.4.2 update 12, 5.0 update 7.)

It's very handy. The JVM lives just long enough to dump its heap to a file, then falls over.

Of course, it does mean that you have to wait for the leak to get bad enough to trigger an OutOfMemoryError.

An alternative is to use a profiler, like YourKit. This provides the means to take a heap snapshot of a running JVM. I believe it still supports Java5.

P.S. You really need to upgrade to java 6....

0
votes

If it's 1.5.0_14 or later, you can use -XX:+HeapDumpOnCtrlBreak and hit Ctrl-Break in the console