Is it possible to debug core dumps when using Java JNI?

Phil Harvey picture Phil Harvey · Nov 19, 2009 · Viewed 9.5k times · Source

My application is mostly Java but, for certain calculations, uses a C++ library. Our environment is Java 1.6 running on RedHat 3 (soon to be RedHat 5).

My problem is that the C++ library is not thread-safe. To work around this, we run multiple, single-threaded "worker" processes and give them work to do from a central Work Manager, also written in C++. Our Java application calls the C++ Work Manager via a third-party product.

For various reasons, we want to re-write the C++ Work Manager and workers. I'm in favour of writing them all in Java, using JNI in each worker to call the C++ library.

The main problem is what happens if the C++ library core dumps. Unfortunately, this is quite common, and we need to be able to see which line in our C++ library caused the problem, e.g. by examining a backtrace in something like GDB.

My colleagues believe that it will be impossible to analyse the core dumps, because tools like GDB don't understand core files produced by Java.

I hope that they're wrong, but I need to be sure before pushing my ideas further.

What is the best way to analyse a core dump produced from Java/JNI?

Answer

Pablo Santa Cruz picture Pablo Santa Cruz · Nov 19, 2009

Yes, there is. Everytime JVM crashes because of a SIGSEGV in the JNI part, you'll get a file with core dump in $JAVA_HOME/bin directory. It usually name hs_err_PID.log.

You can get more info here, and here. Here is a somewhat related stackoverflow question.