Forcing a core dump of a JVM to test -XX:OnError

2385 views
Skip to first unread message

zheismann

unread,
Aug 25, 2010, 12:54:16 PM8/25/10
to The Java Posse
I'd like to be able to force a core dump of a running java process in
order to test the OnError handling. Does anyone know how to
accomplish this?

For example, I am starting up an application server using these
arguments and I want to verify my script will be executed as expected.

JAVA_OPTS="$JAVA_OPTS -XX:OnError="$APPSERVER_HOME/bin/
runAfterCoreDump.sh %p""
JAVA_HOME/bin/java $JAVA_OPTS com.corporation.Main

Thanks!

Wayne Fay

unread,
Aug 26, 2010, 12:12:32 AM8/26/10
to java...@googlegroups.com
> I'd like to be able to force a core dump of a running java process in
> order to test the OnError handling.  Does anyone know how to
> accomplish this?

I'd probably use "jps -l" to identify the process and then "kill
<pid>" or "kill -9 <pid>" on *nix or "taskkill /pid <pid>" on Windows
to kill it. Not completely sure if that will trigger the OnError or
not, you'd need to try it and report back.

Wayne

Christian Catchpole

unread,
Aug 26, 2010, 2:22:34 AM8/26/10
to The Java Posse
Just run some of Michael Neale's code.

Casper Bang

unread,
Aug 26, 2010, 5:49:06 AM8/26/10
to The Java Posse
In as post a little while back, I posted a "different" way to parse/
interpret a byte array:
http://groups.google.com/group/javaposse/browse_thread/thread/f610e8169f5c417b/bccd9bb1dfa67905?lnk=gst&q=unsafe#bccd9bb1dfa67905

I believe if you use the same technique, but does something silly like
$.putAddress(0, 0) you would trigger a core dump (on a Sun JVM).

/Casper

zheismann

unread,
Aug 27, 2010, 12:34:41 PM8/27/10
to The Java Posse
Thank you Casper. I wasn't aware of the sun.misc.Unsafe class, that
does the trick.

Here's what I came up with:

{code}
public class ForceCoreDump
{

public static void main( String[] args ) throws Exception
{
java.lang.reflect.Field field =
sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
field.setAccessible(true);
sun.misc.Unsafe $ = (sun.misc.Unsafe) field.get(null);
$.putAddress(0, 0);
}

}
{code}

runAfterCoreDump.sh:
{code}
#! /bin/sh
HOST=`/bin/uname -n`
PWD=`pwd`
CRASHED_HOST_SUBJECT="ForceCoreDump Crashed: $HOST $PWD"
PROCESSID=$1
cat hs_err_pid$PROCESSID.log|/bin/mailx -s "$CRASHED_HOST_SUBJECT"
myjv...@corporation.com
{code}

Here's my command which successfully invokes the runAfterCoreDump
script.

/usr/java6/binjava -cp . -XX:OnError="runAfterCoreDump.sh %p"
ForceCoreDump

Here's the output of the command

{code}
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0xfebd4230, pid=8471, tid=2
#
# JRE version: 6.0_14-b08
# Java VM: Java HotSpot(TM) Server VM (14.0-b16 mixed mode)
# Problematic frame:
# V [libjvm.so+0x7d4230]
#
# An error report file with more information is saved as:
# /tmp/hs_err_pid8471.log
#
# -XX:OnError="runAfterCoreDump.sh %p"
# Executing /usr/bin/sh -c "runAfterCoreDump.sh 8471" ...
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
Abort - core dumped
{code}

zheismann

unread,
Aug 27, 2010, 5:27:12 PM8/27/10
to The Java Posse
It was also pointed out to me that, at least on Solaris, /bin/kill -
ILL %p, will produce cause a core dump and allow the OnError handler
to run while /bin/kill -9 %p doesn't.

Dominic Mitchell

unread,
Aug 28, 2010, 2:18:05 AM8/28/10
to java...@googlegroups.com
Solaris also provides the gcore command for generating core dumps.  See Core Dump Management.

-Dom

Casey

unread,
Mar 28, 2014, 6:24:07 AM3/28/14
to java...@googlegroups.com
If you are on Linux you can make JVM crash by sending a signal to java process. For example to crash JVM from console you can call:
kill -SIGBUS <your PID>

Regards

Ashish Bhosle

unread,
May 10, 2017, 10:35:02 AM5/10/17
to Java Posse
Yeah, this a very simple way.
Reply all
Reply to author
Forward
0 new messages