views:

97

answers:

3

There are two following options in Java HotSpot VM Options:

-XX:OnError="<cmd args>;<cmd args>" Run user-defined commands on fatal error. (Introduced in 1.4.2 update 9.) 

-XX:OnOutOfMemoryError="<cmd args>; 
<cmd args>" Run user-defined commands when an OutOfMemoryError is first thrown. (Introduced in 1.4.2 update 12, 6) 

As far as I can see there are no such options in IBM JVM.
Is it correct?

I need to call some shell script in case if heap dump was generated.
What is the simplest way to do it?

A: 

I would expect IBM's JVM to support the same flags, as it is an instrumented version of the Sun JVM if I remember correctly. Is it possible you compare command line options between major versions of Java? (I.e. Sun 1.6 versus IBM 1.4.2?)

If you do not find a solution for the flags, you could take advantage of the fact that the IBM JVM updates the file /tmp/dump-locations by appending the full path of the dumpfile. A cron job can run your script when that file is touched since its last run.

rsp
+2  A: 

The IBM J9 JDK offers the said ability via the -Xdump flag; this is the preferred way of registering dump agents.

A typical way of configuring the JVM to produce heap dumps on OOME is to catch all Out Of Memory Errors thrown by the application or by the JVM, and to prepare the dump for "walking" (with a heap inspector).

-Xdump:system+heap+java:events=systhrow+user,filter=java/lang/OutOfMemoryError,request=exclusive+prepwalk+compact

Ref:Eclipse Memory Analyzer Guide

The JAVA_DUMP_OPTS environment variable can also be used. More information on this is available in the IBM JDK diagnostics guide.

EDIT

For the purpose of running a command on a OOME, the tool option needs to be specified in the -Xdump option.

Vineet Reynolds
+1  A: 

-Xdump is your friend and is very powerful.

For your OOM case, something like:

"-Xdump:tool:events=throw,filter=*OutOfMemoryError,exec=cmd_to_run

Trent Gray-Donald