tags:

views:

196

answers:

4

What should I (as a Java programmer who doesn't know anything about JVM internals) do when I come across a JVM crash?

In particular, how would you produce a reproducible test case? What should I be searching for in Sun's (or IBM's) bug database? What information can I get from the log files produced (e.g. hs_err_pidXYZ.log)?

A: 

When an iBM JVM crashes, it might have written to the file /tmp/dump_locations in there it lists any heapdump or javacore files it has written.

These files can be analysed using the Java Core Analyzer and Java heapdump Analyzer from IBM's alphaworks.

rsp
Is this something that I can do if I don't know anything about the JVM internals?
Simon Nickerson
Yes, the analyzers present threads, locks and possible deadlocks for the Java core and object tree and possible memory leaks for the Java heap. Both can point you to sources of trouble.
rsp
+6  A: 

If the crashes occur only one one specific machine, run memtest. I've seen recurring JVM crashes only two times, and in both cases the culprit turned out to be a hardware problem, namely faulty RAM.

Michael Borgwardt
+1 for faulty hardware being prime candidate. Error correcting ram is a good thing.
Thorbjørn Ravn Andersen
+1 Fix your hardware.
Milan Ramaiya
Accepting as it's not something I had considered, and could well be the answer.
Simon Nickerson
+2  A: 

Sun documents the details of the crash log here. There is also a nice tutorial written up here, if you want to get into the dirty details (it sounds like you don't, though)

However, as a commenter mentioned, a JVM crash is a pretty rare and serious event, and it might be worthwhile to call Sun or IBM professional support in this situation.

Ken Liu
+3  A: 
  1. In my experience they are nearly always caused by native code using JNI, either mine or someone else's. If you can, try re-running without the native code to see if you can reproduce it.

  2. Sometimes it is worth trying with the JIT compiler turned off, if your bug is easily reproducible.

  3. As others have pointed out, faulty hardware can also cause this, I've seen it for both Memory and video cards (when the crash was in swing code). Try running whatever hardware diagnostics are most appropriate for your system.

  4. As JVM crashes are rare I'd report them to Sun. This can be done at their bug database. Use category Java SE, Subcategory jvm_exact or jit.

  5. Under Unix/Linux you might get a Core dump. Under windows the JVM will usually tell you where it has stored a log of what has happened. These files often given some hint, but will vary from JVM to JVM. Sun gives full details of these files on their website. or IBM the files can be analysed using the Java Core Analyzer and Java heapdump Analyzer from IBM's alphaworks.

  6. Unfortunately Java debuggers in my experience tend to hurt more than help. However, attaching an OS specific debugger (eg Visual Studio) can help if you are familiar with reading C stack traces.

Trying to get a reproducible test case is hard. If you have a large amount of code that always (or nearly always) crashes it is easier, just slowly remove parts while it keeps crashing, getting the result as small as possible. If you have no reproducible test code at all then it is very difficult. I'd suggest getting hints from my numbered selection above.

Nick Fortescue