JavaGC - jni_invoke_nonstatic SIGSEGV

Question:

I'm using javacpp to wrap proprietary library and sometimes I get this error with VM crash:
#
# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGSEGV (0xb) at pc=0x00007fed23973d99, pid=25503, tid=140656031770368
#
# JRE version: 7.0_05-b05
# Java VM: Java HotSpot(TM) 64-Bit Server VM (23.1-b03 mixed mode linux-amd64 compressed oops)
# Problematic frame:
# V  [libjvm.so+0x560d99]  jni_invoke_nonstatic(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, Thread*)+0x199
#
# Core dump written. Default location: /home/robot/asianrobot2/core or core.25503 (max size 2097152 kB). To ensure a full core dump, try "ulimit -c unlimited" before starting Java again
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
#
...
Stack: [0x00007fed08bf2000,0x00007fed08cf3000],  sp=0x00007fed08ce1100,  free space=956k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V  [libjvm.so+0x560d99]  jni_invoke_nonstatic(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, Thread*)+0x199
V  [libjvm.so+0x56aa9c]  jni_CallVoidMethodA+0xec
...

Backtrace from gdb:
#0  0x00007fed24168445 in raise () from /lib/x86_64-linux-gnu/libc.so.6
(gdb) bt
#0  0x00007fed24168445 in raise () from /lib/x86_64-linux-gnu/libc.so.6
#1  0x00007fed2416bbab in abort () from /lib/x86_64-linux-gnu/libc.so.6
#2  0x00007fed23b53dd5 in os::abort(bool) () from /usr/local/jdk1.7.0_05/jre/lib/amd64/server/libjvm.so
#3  0x00007fed23cb37e7 in VMError::report_and_die() () from /usr/local/jdk1.7.0_05/jre/lib/amd64/server/libjvm.so
#4  0x00007fed23b57b80 in JVM_handle_linux_signal () from /usr/local/jdk1.7.0_05/jre/lib/amd64/server/libjvm.so
#5  <signal handler called>
#6  0x00007fed23973d99 in jni_invoke_nonstatic(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, Thread*) ()
   from /usr/local/jdk1.7.0_05/jre/lib/amd64/server/libjvm.so
#7  0x00007fed2397da9c in jni_CallVoidMethodA () from /usr/local/jdk1.7.0_05/jre/lib/amd64/server/libjvm.so
#8  0x00007fed09f5e16f in ?? () from /home/robot/asianrobot2/lib/linux64/libjniiXAPI.so
#9  0x00007fed09f5e23c in ?? () from /home/robot/asianrobot2/lib/linux64/libjniiXAPI.so
#10 0x00007fed09c70f3e in createMessage (
    message_buffer=0x7fec00000a22 "\034\061\037\061\034\063\037\061\034\066\037E\034\067\037LI3\034\070\037VTBR\034\071\037\070\065\070\034\062\060\037\066\034\062\062\037\060\070\061\065\060\063\061\062\063\061\070\066\034\070\062\037T\034\061\060\063\037\062\034\063\062\037\061\060\034\063\063\037\061\060\034\063\064\037\061\060\034\063\060\037\060\034\063\061\037\060\034\063\062\037\061\060\034\063\063\037\061\060\034\063\037\062\062\034\064\037\062\067_4\034\065\037\061\034\071\037\067\065\062\067\034\062\060\037\062", 
    message_size=132, object_p=0x7fec44080300, mcb_p=<optimized out>, ml3_mcb_p=0x7fed08ce9410) at /opt/home/pgagnon/dev/tix_api/trunk/src/max_api_core.cpp:383
#11 0x00007fed09c9bc05 in om_publish_message (mcb_p=0x0, mi_session_p=0x7fec4403e1a0) at /opt/home/pgagnon/dev/mdn/trunk/src/mdn2_api.c:1484
#12 0x00007fed09c9bec2 in om_do_stuff (tcb_p=<optimized out>) at /opt/home/pgagnon/dev/mdn/trunk/src/mdn2_api.c:1883
#13 0x00007fed09c9bfd5 in om_handler () at /opt/home/pgagnon/dev/mdn/trunk/src/mdn2_api.c:1958
#14 0x00007fed24910e9a in start_thread () from /lib/x86_64-linux-gnu/libpthread.so.0
#15 0x00007fed242244bd in clone () from /lib/x86_64-linux-gnu/libc.so.6
#16 0x0000000000000000 in ?? ()
With javacpp-0.2 it crashes rarely, and with head version of javacpp - every time application runs.
It seems that problem is when C++ library calls java function. But what is wrong?
Any ideas how to debug this?

Answer:

Are you talking about a FunctionPointer? Make sure to keep a reference in Java or it gets garbage collected.
Add a check there to make sure the object is valid before trying to call it and print an error message if not instead of crashing here.

Exactly! FunctionPointer was simply garbage-collected :)

你可能感兴趣的:(JavaGC - jni_invoke_nonstatic SIGSEGV)