table of Contents
Generate Java core dump
Can be invoked by jni accordance with the guidelines following article triggered Java core dump
The basic idea is to call native C code via Java, then triggers an error in C code, causing jvm
crash。
Need to pay attention to two issues
- gcc compile time to note the name of the library, which is an example
libnativelib.so
, needs to be changedlibnativelib.jnilib
$ gcc -fPIC -o libnativelib.jnilib -shared \
-I$JAVA_HOME/include/linux/ \
-I$JAVA_HOME/include/ \
CoreDumper.c
- The command is based on the example, if the header file jni_md.h mac at slightly different positions and linux, gcc compiler with time to pay attention, it is necessary to copy the files to the linux corresponding directory jni_md.h
sudo cp $JAVA_HOME/Contents/Home/include/darwin/jni_md.h $JAVA_HOME/Contents/Home/include
- java.lang.UnsatisfiedLinkError: no XXX in java.library.path
In the implementation of java mainClass may report this error, because when java execution mainClass of mainClass needs with a package name, look at the next generation of libnativelib.jnilib in a directory that is used -Djava.library.path point of libnativelib.jnilib path
After the above operation meal, you can see a directory performed hs_err_pidxxx.log java file, as well as in the corresponding directory core dump file, the directory core dump is mac
/cores
However, there may not generate a core dump, only hs_err_pidxxx.log file, we look hs_err_pidxxx.log file, there is a line
# Failed to write core dump. Core dumps have been disabled. To enable core dumping, try "ulimit -c unlimited" before starting Java again
Follow the prompts to core dump fails, you can set ulimit -c unlimited
to re-try it again, you can find similar core.xxx files in / cores directory.
Because of the restrictions will limit the processes under mac resource, -c represents the maximum core file, in units of blocks, ulimit -c unlimited
set to unlimited. Note that the current shell execution will only take effect in the current shell.
core dump analysis
hs_err_pidxxx.log is a text log file that can be viewed directly. core dump file may be analyzed by gdb, jmap, jstack, specific reference may Analysing a Java Core Dump
reference
Common causes of JVM Crashes in: Staying ON Top of JVM Crashes
gcc compiler can not find jni_md.h: Under Mac Java JNI tone C