Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trigger Heap Dump of a 1.5 JVM running on Windows

Tags:

java

windows

jvm

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.

like image 455
jthg Avatar asked Nov 15 '22 09:11

jthg


1 Answers

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

like image 71
skaffman Avatar answered Dec 07 '22 23:12

skaffman