tags:

views:

50

answers:

2

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.

+1  A: 

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

skaffman
Thanks. I've been using this method, but it's not quite enough. I need to somehow trigger a heap dump at an arbitrary time.
jthg
@jthg: So see the profiler suggestion I made as well
skaffman
I'll think about the profiler if there's no free solution.
jthg
"P.S. You really need to upgrade to java 6..." - I wish :)
jthg
@jthg - you are obviously not beating on your management / customers / suppliers hard enough :-)
Stephen C
A: 

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

unbeli
Can Ctrl-Break be sent to a process if there is no console? Or do you know if there's way to have the Sun One App server keep a console open for the jvm process?
jthg
Not sure about Sun One server. Common ways are: 1- editing startup scripts (if present) and replacing javaw with java; 2- finding the main class and running it manually
unbeli