JNI is crashing the java in windows 7 -
i porting code linux windows , since there no support linux shared memory segments in java. hence, using java native interface (jni) access shared memory.it working fine on linux platform .
code shmget:
jniexport jint jnicall java_emulatorinterface_communication_shm_sharedmem_shmget (jnienv * env, jobject jobj, jint count,jint maxnumjavathreads,jint emuthreadsperjavathread, jlong coremap, jint pid) { uint64_t mask = coremap; int size;//=sizeof(packet)*(count+5)*maxnumjavathreads*emuthreadsperjavathread; char str[50]; int ptr; #ifdef _win32 handle hmapfile; #endif printf("hello"); size=sizeof(packet)*(count+5)*maxnumjavathreads*emuthreadsperjavathread; /*if (sched_setaffinity(0, sizeof(mask), (cpu_set_t *)&mask) <0) { perror("sched_setaffinity"); }*/ //set global variables gcount = count; gmaxnumjavathreads = maxnumjavathreads; gemuthreadsperjavathread = emuthreadsperjavathread; //size1 number of packets needed in segment. #ifdef _win32 _itoa(pid,str,10); hmapfile = createfilemapping(invalid_handle_value, null, page_readwrite, 0,32, str); if (hmapfile == null) { exit(1); } closehandle(hmapfile); hmapfile = createfilemapping(invalid_handle_value, null, page_readwrite, 0,size, str); if (hmapfile == null) { printf("unable create shared mem file."); exit(1); } if (hmapfile < 0) { return (-1); } /* if((hmapfile = createfilemapping(invalid_handle_value, null, page_readwrite, 0,size, str))<0) { printf("error window %d\n",size); return (-1); } */ ptr=*((int*)(hmapfile)); return ptr; ///////////////error in return type #else
if trying use other function in jni ,my java crashes.
error
# # fatal error has been detected java runtime environment: # # exception_access_violation (0xc0000005) @ pc=0x000007feedf911be, pid=4696, tid=4216 # # jre version: java(tm) se runtime environment (8.0_77-b03) (build 1.8.0_77-b03) # java vm: java hotspot(tm) 64-bit server vm (25.77-b03 mixed mode windows-amd64 compressed oops) # problematic frame: # c [jnishm.dll+0x11be] # # failed write core dump. minidumps not enabled default on client versions of windows # # error report file more information saved as: # d:\workspace\tejasminor\hs_err_pid4696.log # # if submit bug report, please visit: # http://bugreport.java.com/bugreport/crash.jsp # crash happened outside java virtual machine in native code. # see problematic frame report bug. #
can point out problem ?
you can't dereference handle
file mapping object. make function return handle, in:
return (int)hmapfile;
on 64 bits windows (with 64 bits jre/jni) handle
type 64 bits wide, lower 32 bits significant, that's ok.
side notes:
- don't use
hmapfile < 0
. if api fails, return valuenull
. - are sure need try @ first 32 bytes file, close it? why?
- you may want call
getlasterror
, test result againsterror_already_exists
(if want able detect condition)
Comments
Post a Comment