views:

283

answers:

1

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?

+2  A: 

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.

Pablo Santa Cruz
Thanks Pablo. kohsuke's article is excellent. Unfortunately, if I tell my colleagues that they'll need to understand assembler to discover which C++ line caused the seg fault, they'll run a mile.I'm on Linux and my .so files have been compiled with the debug flag turned on. Maybe this will make the process easier.