java - SIGSEGV with JNI call converting jlong to long -
i'm working jni call java application external c library given software editor access/write datas application.
i sigsegv fatal error calls , can't found out why. here error log given jvm :
# # fatal error has been detected java runtime environment: # # sigsegv (0xb) @ pc=0x00007f1b357729e0, pid=18693, tid=139752817592064 # # jre version: 6.0_45-b06 # java vm: java hotspot(tm) 64-bit server vm (20.45-b01 mixed mode linux-amd64 compressed oops) # problematic frame: # c 0x00007f1b357729e0 # # if submit bug report, please visit: # http://java.sun.com/webapps/bugreport/crash.jsp # crash happened outside java virtual machine in native code. # see problematic frame report bug. # --------------- t h r e d --------------- current thread (0x00007f1b1001d000): javathread "http-bio-10.70.4.12-10767-exec-12" daemon [_thread_in_native, id=18888, stack(0x00007f1abcfc8000,0x00007f1abd0c9000)] siginfo:si_signo=sigsegv: si_errno=0, si_code=1 (segv_maperr), si_addr=0x00007f1b357729e0 registers: rax=0x00007f1b35dfd990, rbx=0x000000000000000b, rcx=0x000000000000000b, rdx=0x00007f1ac1d3d650 rsp=0x00007f1abd0c5178, rbp=0x00007f1abd0c51a0, rsi=0x000000000000000b, rdi=0x00007f1ac1d3d650 r8 =0x00007f1b506c9278, r9 =0x00007f1b1001e328, r10=0x00007f1b45011894, r11=0x00007f1b503b2d10 r12=0x00007f1ac1d3d650, r13=0x00000000e2de9358, r14=0x00007f1abd0c5260, r15=0x00007f1b1001d000 rip=0x00007f1b357729e0, eflags=0x0000000000010202, csgsfs=0x0000000000000033, err=0x0000000000000014 trapno=0x000000000000000e top of stack: (sp=0x00007f1abd0c5178) 0x00007f1abd0c5178: 00007f1b35beed30 00007f1b1001d000 ... 0x00007f1abd0c5358: 00007f1abd0c5358 00000000e321a20a 0x00007f1abd0c5368: 00007f1abd0c5440 00000000e4699898 instructions: (pc=0x00007f1b357729e0) 0x00007f1b357729c0: [error occurred during error reporting (printing registers, top of stack, instructions near pc), id 0xb] register memory mapping: rax=0x00007f1b35dfd990: s_fnamgetfieldlongvalue+0 in /app/rct/ask4it/2/tomcat7/installedapps/ask4itweb.war/web-inf/dll/hp/assetmanager/x64/libamapijni.so @ 0x00007f1b35be5000 rbx=0x000000000000000b unknown value rcx=0x000000000000000b unknown value rdx=0x00007f1ac1d3d650 unknown value rsp=0x00007f1abd0c5178 pointing stack thread: 0x00007f1b1001d000 rbp=0x00007f1abd0c51a0 pointing stack thread: 0x00007f1b1001d000 rsi=0x000000000000000b unknown value rdi=0x00007f1ac1d3d650 unknown value r8 =0x00007f1b506c9278: <offset 0xaa2278> in /tech/java/oracle/jdk-1.6.0_45/jre/lib/amd64/server/libjvm.so @ 0x00007f1b4fc27000 r9 =0x00007f1b1001e328 unknown value r10=0x00007f1b45011894 interpreter codelet method entry point (kind = native_synchronized) [0x00007f1b450114c0, 0x00007f1b45011e80] 2496 bytes r11=0x00007f1b503b2d10: <offset 0x78bd10> in /tech/java/oracle/jdk-1.6.0_45/jre/lib/amd64/server/libjvm.so @ 0x00007f1b4fc27000 r12=0x00007f1ac1d3d650 unknown value r13=0x00000000e2de9358 oop {method} - klass: {other class} r14=0x00007f1abd0c5260 pointing stack thread: 0x00007f1b1001d000 r15=0x00007f1b1001d000 thread stack: [0x00007f1abcfc8000,0x00007f1abd0c9000], sp=0x00007f1abd0c5178, free space=1012k native frames: (j=compiled java code, j=interpreted, vv=vm code, c=native code) c 0x00007f1b357729e0 j com.afkl.ask4it.amapi.jni.base.amgetfieldlongvalue(jj)j+0 java frames: (j=compiled java code, j=interpreted, vv=vm code) j com.afkl.ask4it.amapi.jni.base.amgetfieldlongvalue(jj)j+0 j com.afklm.askfourit.query.queryutil.getfieldvalue(jjjljava/lang/string;ljava/lang/string;)ljava/lang/object; j com.afklm.askfourit.dao.ask4itmodeldao.createask4itmodelbean(jj)lcom/afklm/askfourit/entity/ask4itmodel;+602 ...
as can see in stack, method causing crash 1 :
jniexport jlong jnicall java_com_afkl_ask4it_amapi_jni_base_amgetfieldlongvalue(jnienv * env, jclass c, jlong jlhquery, jlong jipos) { long lfieldval = amgetfieldlongvalue(jl2c(jlhquery), jl2c(jipos)); if(fhlog) amapi_jni_log("amgetfieldlongvalue","object %ld pos %ld : %ld",jl2c(jlhquery), jl2c(jipos),lfieldval); return lfieldval; }
this function call native function amgetfieldlongvalue of external library. translation allow java call it, without doing else passing argument , retrieve results.
the thing can think causing sigsegv call jl2c convert jlong long, defined :
#define jl2c(_jl) ((long)(_jl))
or returned value lfieldval defined in function long whereas method returns jlong.
i expect thoses convertions causing trouble because read somewhere "passing char* jstring needed crash jvm". had many jvm crashes because of before, rewrote jni stop doing this, , pass jbytearray jstring used, , use code convert char* :
jsize lengthtable = (*env)->getarraylength(env, jstrtable); jbyte* jbytestrtable = (*env)->getbytearrayelements(env, jstrtable, 0); char* psztable = malloc(lengthtable + 1); memcpy(psztable, jbytestrtable, lengthtable); psztable[lengthtable] = '\0';
now seems have no more crashes on functions, hope code correct previous problem, seems have same kind of problems others types conversions.
but can't found out what's wrong it. read jlong 64bit signed integer , cast jlong long cause kind of error if long defined 32bit integer don't know how securise cast, or else.
many help.
Comments
Post a Comment