I'm testing out my JNI dll and I'm getting system crashes when executing certain calls to my C based functions. Some calls work (see below getSession 1-5) and some cause crashes (see below getSession 6-8). Below is a list of my testing findings. I've removed all logic from the C functions and just return an int. Any ideas on how to troubleshoot this further?
My JNI and C library dll are being cross compiled on Linux 32-bit, using these make file contents. These issues don't occur on Linux, just Windows XP. I'm using SWIG to generate my JNI.
The pattern to create the crash seems to be to have a C function that has more pointer parameters than non-pointer parameters. A crash doesn't occur if the non-pointer to pointer parameter ratio is equal or non-pointer params > pointer params or just one pointer param without any other parameters.
Java JNI Signatures:
public final static native int getSession1(String jarg1); //works
public final static native int getSession2(int jarg1); //works
public final static native int getSession3(String jarg1, int jarg2); // works
public final static native int getSession4(int jarg1, int jarg2); //works
public final static native int getSession5(int jarg1, String jarg2, String jarg3, int jarg4); //works
public final static native int getSession6(String jarg1, String jarg2); //causes system failure, see below for stack details
public final static native int getSession7(String jarg1, String jarg2, int jarg3, String jarg4); //causes system failure
public final static native int getSession8(String jarg1, String jarg2, String jarg3); //causes system failure
C function Header Signatures:
int getSession1(char *arg1); //works
int getSession2(int arg1); //works
int getSession3(char *ag1, int arg2); //works
int getSession4(int arg1, int arg2); //works
int getSession5(int arg1, char *agr2, char *arg3, int arg4); //works
int getSession6(char *arg1, char *arg2); //crashes
int getSession7(char *arg1, char *arg2, int arg3, char *arg4); //crashes
int getSession8(char *arg1, char *arg2, char *arg3);
JRE System Failure Log (some contents removed for clarity):
#
# A fatal error has been detected by the Java Runtime Environment
#
# EXCEPTION_SINGLE_STEP (0x80000004) at pc=0x7c90eaf0, pid=2704, tid=2396
#
# JRE version: 6.0_30-b12
# Java VM: Java HotSpot(TM) Client VM (20.5-b03 mixed mode, sharing windows-x86 )
# Problematic frame:
# C [ntdll.dll+0xeaf0]
--------------- T H R E A D ---------------
Current thread (0x003a6400): JavaThread "main" [_thread_in_native, id=2396, stack(0x00990000,0x009e0000)]
siginfo: ExceptionCode=0x80000004
Registers:
EAX=0x003a654c, EBX=0x3278fc38, ECX=0x009df9a8, EDX=0x00000000
ESP=0x009df984, EBP=0x009dfcbc, ESI=0x3278fc38, EDI=0x003a6400
EIP=0x7c90eaf0, EFLAGS=0x00204602
Top of Stack: (sp=0x009df984)
0x009df984: 009df98c 009df9a8 c0000005 00000000
0x009df994: 00000000 009dfcc7 00000002 00000001
0x009df9a4: 0000003e 0001003f 00000000 00000000
0x009df9b4: 00000000 00000000 00000000 00000000
0x009df9c4: ffff027f ffff0000 ffffffff 00a0fb5a
0x009df9d4: 073c001b 009dfc90 ffff0023 0008fb30
0x009df9e4: 7c911538 2ca81596 00120003 2d280000
0x009df9f4: 00030000 7c910732 00000004 26400003
Instructions: (pc=0x7c90eaf0)
0x7c90ead0: 83 c4 04 5a 64 a1 18 00 00 00 8b 40 30 8b 40 2c
0x7c90eae0: ff 14 90 33 c9 33 d2 cd 2b cc 8b ff 8b 4c 24 04
0x7c90eaf0: 8b 1c 24 51 53 e8 c7 8c 02 00 0a c0 74 0c 5b 59
0x7c90eb00: 6a 00 51 e8 11 eb ff ff eb 0b 5b 59 6a 00 51 53
Register to memory mapping:
EAX=0x003a654c is an unknown value
EBX=0x3278fc38 is an oop
{method}
- klass: {other class}
ECX=0x009df9a8 is pointing into the stack for thread: 0x003a6400
EDX=0x00000000 is an unknown value
ESP=0x009df984 is pointing into the stack for thread: 0x003a6400
EBP=0x009dfcbc is pointing into the stack for thread: 0x003a6400
ESI=0x3278fc38 is an oop
{method}
- klass: {other class}
EDI=0x003a6400 is a thread
Stack: [0x00990000,0x009e0000], sp=0x009df984, free space=318k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C [ntdll.dll+0xeaf0] KiUserExceptionDispatcher+0x4
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j com.test.jni.SampleJNI.getSession6(Ljava/lang/String;Ljava/lang/String;)I+0
j com.test.jni.Sample.getSession6(Ljava/lang/String;Ljava/lang/String;)I+2
j com.test.jni.Example.main([Ljava/lang/String;)V+605
v ~StubRoutines::call_stub
--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
0x02c48c00 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=2748, stack(0x02ec0000,0x02f10000)]
0x02c43800 JavaThread "C1 CompilerThread0" daemon [_thread_blocked, id=2372, stack(0x02e70000,0x02ec0000)]
0x02c41400 JavaThread "Attach Listener" daemon [_thread_blocked, id=2484, stack(0x02e20000,0x02e70000)]
0x02c3fc00 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=3800, stack(0x02dd0000,0x02e20000)]
0x02c3bc00 JavaThread "Finalizer" daemon [_thread_blocked, id=2512, stack(0x02d80000,0x02dd0000)]
0x02c37000 JavaThread "Reference Handler" daemon [_thread_blocked, id=3716, stack(0x02d30000,0x02d80000)]
=>0x003a6400 JavaThread "main" [_thread_in_native, id=2396, stack(0x00990000,0x009e0000)]
Other Threads:
0x02bfa400 VMThread [stack: 0x02ce0000,0x02d30000] [id=2052]
0x02c4bc00 WatcherThread [stack: 0x02f10000,0x02f60000] [id=3304]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
def new generation total 4864K, used 495K [0x22970000, 0x22eb0000, 0x27e10000)
eden space 4352K, 11% used [0x22970000, 0x229ebf60, 0x22db0000)
from space 512K, 0% used [0x22db0000, 0x22db0000, 0x22e30000)
to space 512K, 0% used [0x22e30000, 0x22e30000, 0x22eb0000)
tenured generation total 10880K, used 0K [0x27e10000, 0x288b0000, 0x32770000)
the space 10880K, 0% used [0x27e10000, 0x27e10000, 0x27e10200, 0x288b0000)
compacting perm gen total 12288K, used 156K [0x32770000, 0x33370000, 0x36770000)
the space 12288K, 1% used [0x32770000, 0x327970a0, 0x32797200, 0x33370000)
ro space 10240K, 51% used [0x36770000, 0x36c9da30, 0x36c9dc00, 0x37170000)
rw space 12288K, 55% used [0x37170000, 0x37809b50, 0x37809c00, 0x37d70000)
Code Cache [0x00a00000, 0x00a70000, 0x02a00000)
total_blobs=136 nmethods=5 adapters=68 free_code_cache=33101824 largest_free_block=0
Dynamic libraries:
VM Arguments:
Environment Variables:
--------------- S Y S T E M ---------------
OS: Windows XP Build 2600 Service Pack 2
CPU:total 4 (2 cores per cpu, 2 threads per core) family 6 model 28 stepping 2, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, ht
Memory: 4k page, physical 1038156k(614332k free), swap 1713032k(1398020k free)
vm_info: Java HotSpot(TM) Client VM (20.5-b03) for windows-x86 JRE (1.6.0_30-b12), built on Nov 10 2011 01:51:00 by "java_re" with MS VC++ 7.1 (VS2003)
time: Thu Jan 05 15:06:54 2012
elapsed time: 0 seconds
guess its a typo in the above code snippet where getSession7 and getSession6 signatures are interchanged ? looking at the signature from the stack trace 'getSession7' seems to take only 2 arguments
getSession7(Ljava/lang/String;Ljava/lang/String;)
User contributions licensed under CC BY-SA 3.0