我正在测试我的JNI dll,并且在执行对基于C的函数的某些调用时遇到系统崩溃。有些调用工作(见下面的getSession 1-5),有些调用会导致崩溃(见下面的getSession 6-8)。以下是我的测试结果列表。我从C函数中删除了所有逻辑,只返回一个int。有关如何进一步排除故障的任何想法?
我的JNI和C库dll正在Linux 32位上进行交叉编译,使用这些 make file contents。 Linux,Windows XP上不会出现这些问题。我正在使用SWIG生成我的JNI。
创建崩溃的模式似乎是拥有一个C函数,它具有比非指针参数更多的指针参数。如果指针参数比率的非指针相等或非指针参数> 1,则不会发生崩溃。指针参数或只有一个指针参数,没有任何其他参数。
Java JNI签名:
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函数标题签名:
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系统失败日志(为清晰起见,删除了一些内容):
#
# 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
答案 0 :(得分:1)
在上面的代码片段中猜测它是一个拼写错误,其中getSession7和getSession6签名是互换的?查看堆栈跟踪'getSession7'中的签名似乎只需要2个参数
getSession7(Ljava/lang/String;Ljava/lang/String;)