基于jni调用时,jvm报错问题的深入分析
程序员文章站
2023-12-17 14:03:58
执行如下的jni调用:复制代码 代码如下:package jni;public class jnitransobject { public native test...
执行如下的jni调用:
package jni;
public class jnitransobject {
public native testjni[] objectmethod(string text);
static {
system.loadlibrary("jnitransobject");
}
public static void main(string args[]) {
jnitransobject jnitransobject = new jnitransobject();
testjni[] testjnis = jnitransobject.objectmethod("jni trans object");
for (int i = 0; i < testjnis.length; i++) {
system.out.println(testjnis[i].gettopic());
}
}
}
时,报如下的错误:
#
# a fatal error has been detected by the java runtime environment:
#
# exception_access_violation (0xc0000005) at pc=0x6d91c1db, pid=3544, tid=5408
#
# jre version: 6.0_21-b06
# java vm: java hotspot(tm) client vm (17.0-b16 mixed mode, sharing windows-x86 )
# problematic frame:
# v [jvm.dll+0x11c1db]
#
# if you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
--------------- t h r e a d ---------------
current thread (0x01aa6400): javathread "main" [_thread_in_vm, id=5408, stack(0x00160000,0x001b0000)]
siginfo: exceptioncode=0xc0000005, reading address 0x00000009
registers:
eax=0x00000005, ebx=0x00002000, ecx=0x00000006, edx=0x23b47f28
esp=0x001afa9c, ebp=0x001afaa8, esi=0x01aa6400, edi=0x01aa6400
eip=0x6d91c1db, eflags=0x00010202
top of stack: (sp=0x001afa9c)
0x001afa9c: 01aa6400 37b19738 3851d3b8 001afaf8
0x001afaac: 01b89f47 01aa6518 001afb00 001afb18
0x001afabc: 23b23bc0 001afb10 00000000 00002000
0x001afacc: 6d8f1751 01aa6400 00000006 001afad8
0x001afadc: 00000000 001afb18 3851ca08 00000000
0x001afaec: 3851d3b8 00000000 001afb08 001afb3c
0x001afafc: 01b82da1 38b317c8 01b88269 00002000
0x001afb0c: 00000000 23b47f28 23b23bc0 00000005
instructions: (pc=0x6d91c1db)
0x6d91c1cb: 74 5f 8b 55 18 85 d2 74 58 8b 5d 20 8b 12 8b 00
0x6d91c1db: 8b 48 04 8b 79 08 56 53 8b 5d 1c 53 52 8b 55 14
stack: [0x00160000,0x001b0000], sp=0x001afa9c, free space=13e001af45ck
native frames: (j=compiled java code, j=interpreted, vv=vm code, c=native code)
v [jvm.dll+0x11c1db]
j java.lang.system.arraycopy(ljava/lang/object;iljava/lang/object;ii)v+0
j java.lang.string.getchars(ii[ci)v+62
j java.io.bufferedwriter.write(ljava/lang/string;ii)v+63
j java.io.writer.write(ljava/lang/string;)v+7
j java.io.printstream.write(ljava/lang/string;)v+13
j java.io.printstream.print(ljava/lang/string;)v+9
j java.io.printstream.println(ljava/lang/string;)v+6
j jni.jnitransobject.main([ljava/lang/string;)v+29
v ~stubroutines::call_stub
v [jvm.dll+0xf3abc]
v [jvm.dll+0x1865b1]
v [jvm.dll+0xf3b3d]
v [jvm.dll+0xfd385]
v [jvm.dll+0x104fdd]
c [javaw.exe+0x2155]
c [javaw.exe+0x8614]
c [kernel32.dll+0x4ed6c]
c [ntdll.dll+0x637f5]
c [ntdll.dll+0x637c8]
java frames: (j=compiled java code, j=interpreted, vv=vm code)
j java.lang.system.arraycopy(ljava/lang/object;iljava/lang/object;ii)v+0
j java.lang.string.getchars(ii[ci)v+62
j java.io.bufferedwriter.write(ljava/lang/string;ii)v+63
j java.io.writer.write(ljava/lang/string;)v+7
j java.io.printstream.write(ljava/lang/string;)v+13
j java.io.printstream.print(ljava/lang/string;)v+9
j java.io.printstream.println(ljava/lang/string;)v+6
j jni.jnitransobject.main([ljava/lang/string;)v+29
v ~stubroutines::call_stub
--------------- p r o c e s s ---------------
java threads: ( => current thread )
0x01b2e800 javathread "low memory detector" daemon [_thread_blocked, id=7580, stack(0x03e10000,0x03e60000)]
0x01b21800 javathread "compilerthread0" daemon [_thread_blocked, id=6392, stack(0x03dc0000,0x03e10000)]
0x01b19800 javathread "attach listener" daemon [_thread_blocked, id=6364, stack(0x03d70000,0x03dc0000)]
0x01b16c00 javathread "signal dispatcher" daemon [_thread_blocked, id=6360, stack(0x03d20000,0x03d70000)]
0x01acd000 javathread "finalizer" daemon [_thread_blocked, id=6348, stack(0x03cd0000,0x03d20000)]
0x01acb800 javathread "reference handler" daemon [_thread_blocked, id=6316, stack(0x03c80000,0x03cd0000)]
=>0x01aa6400 javathread "main" [_thread_in_vm, id=5408, stack(0x00160000,0x001b0000)]
other threads:
0x01aca400 vmthread [stack: 0x03c30000,0x03c80000] [id=6320]
0x01b2f400 watcherthread [stack: 0x03e60000,0x03eb0000] [id=4824]
vm state:not at safepoint (normal execution)
vm mutex/monitor currently owned by a thread: none
heap
def new generation total 4928k, used 1479k [0x23b10000, 0x24060000, 0x29060000)
eden space 4416k, 33% used [0x23b10000, 0x23c81ef8, 0x23f60000)
from space 512k, 0% used [0x23f60000, 0x23f60000, 0x23fe0000)
to space 512k, 0% used [0x23fe0000, 0x23fe0000, 0x24060000)
tenured generation total 10944k, used 0k [0x29060000, 0x29b10000, 0x33b10000)
the space 10944k, 0% used [0x29060000, 0x29060000, 0x29060200, 0x29b10000)
compacting perm gen total 12288k, used 368k [0x33b10000, 0x34710000, 0x37b10000)
the space 12288k, 2% used [0x33b10000, 0x33b6c1d0, 0x33b6c200, 0x34710000)
ro space 10240k, 51% used [0x37b10000, 0x3803b700, 0x3803b800, 0x38510000)
rw space 12288k, 54% used [0x38510000, 0x38ba76c0, 0x38ba7800, 0x39110000)
dynamic libraries:
0x00400000 - 0x00424000 c:\program files\java\jre6\bin\javaw.exe
0x77720000 - 0x7785c000 c:\windows\system32\ntdll.dll
0x75b10000 - 0x75be4000 c:\windows\system32\kernel32.dll
0x75830000 - 0x7587a000 c:\windows\system32\kernelbase.dll
0x774c0000 - 0x77560000 c:\windows\system32\advapi32.dll
0x77340000 - 0x773ec000 c:\windows\system32\msvcrt.dll
0x77870000 - 0x77889000 c:\windows\system32\sechost.dll
0x760b0000 - 0x76151000 c:\windows\system32\rpcrt4.dll
0x75ec0000 - 0x75f89000 c:\windows\system32\user32.dll
0x76010000 - 0x7605e000 c:\windows\system32\gdi32.dll
0x75b00000 - 0x75b0a000 c:\windows\system32\lpk.dll
0x75a50000 - 0x75aed000 c:\windows\system32\usp10.dll
0x77030000 - 0x7704f000 c:\windows\system32\imm32.dll
0x76db0000 - 0x76e7c000 c:\windows\system32\msctf.dll
0x7c340000 - 0x7c396000 c:\program files\java\jre6\bin\msvcr71.dll
0x6d800000 - 0x6daa7000 c:\program files\java\jre6\bin\client\jvm.dll
0x755f0000 - 0x75622000 c:\windows\system32\winmm.dll
0x754a0000 - 0x754ec000 c:\windows\system32\apphelp.dll
0x6d7b0000 - 0x6d7bc000 c:\program files\java\jre6\bin\verify.dll
0x6d330000 - 0x6d34f000 c:\program files\java\jre6\bin\java.dll
0x6d290000 - 0x6d298000 c:\program files\java\jre6\bin\hpi.dll
0x76e80000 - 0x76e85000 c:\windows\system32\psapi.dll
0x6d7f0000 - 0x6d7ff000 c:\program files\java\jre6\bin\zip.dll
0x10000000 - 0x10039000 e:\workspace\zhy\jnitransobject.dll
vm arguments:
jvm_args: -dfile.encoding=gbk
java_command: jni.jnitransobject
launcher type: sun_standard
environment variables:
java_home=c:\program files\java\jdk1.6.0_21
classpath=.;c:\program files\java\jdk1.6.0_21\lib\dt.jar;c:\program files\java\jdk1.6.0_21\lib\tools.jar
path=c:/program files/java/jre6/bin/client;c:/program files/java/jre6/bin;c:/program files/java/jre6/lib/i386;c:\program files\common files\microsoft shared\windows live;c:\program files\amd app\bin\x86;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\program files\ati technologies\ati.ace\core-static;c:\program files\common files\lenovo;c:\program files\common files\ulead systems\mpeg;c:\program files\windows live\shared;c:\swtools\readyapps;c:\program files\intel\services\ipt\;c:\program files\symantec\vip access client\;c:\program files\java\jdk1.6.0_21\bin;c:\program files\java\jdk1.6.0_21\jre6\bin;c:\program files\tortoisesvn\bin;c:\program files\common files\thunder network\kankan\codecs
username=think
os=windows_nt
processor_identifier=x86 family 6 model 42 stepping 7, genuineintel
--------------- s y s t e m ---------------
os: windows 7 build 7601 service pack 1
cpu:total 4 (8 cores per cpu, 2 threads per core) family 6 model 42 stepping 7, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, ht
memory: 4k page, physical 3056880k(1883100k free), swap 6112004k(3307764k free)
vm_info: java hotspot(tm) client vm (17.0-b16) for windows-x86 jre (1.6.0_21-b06), built on jun 22 2010 00:56:49 by "java_re" with ms vc++ 7.1 (vs2003)
time: wed apr 11 09:46:47 2012
elapsed time: 0 seconds
发生这样的错误,大多是jni端代码有问题,如:不恰当的 printf 及 cout 调用,方法调用类型不兼容,调用被销毁的对象等。
复制代码 代码如下:
package jni;
public class jnitransobject {
public native testjni[] objectmethod(string text);
static {
system.loadlibrary("jnitransobject");
}
public static void main(string args[]) {
jnitransobject jnitransobject = new jnitransobject();
testjni[] testjnis = jnitransobject.objectmethod("jni trans object");
for (int i = 0; i < testjnis.length; i++) {
system.out.println(testjnis[i].gettopic());
}
}
}
时,报如下的错误:
#
# a fatal error has been detected by the java runtime environment:
#
# exception_access_violation (0xc0000005) at pc=0x6d91c1db, pid=3544, tid=5408
#
# jre version: 6.0_21-b06
# java vm: java hotspot(tm) client vm (17.0-b16 mixed mode, sharing windows-x86 )
# problematic frame:
# v [jvm.dll+0x11c1db]
#
# if you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
--------------- t h r e a d ---------------
current thread (0x01aa6400): javathread "main" [_thread_in_vm, id=5408, stack(0x00160000,0x001b0000)]
siginfo: exceptioncode=0xc0000005, reading address 0x00000009
registers:
eax=0x00000005, ebx=0x00002000, ecx=0x00000006, edx=0x23b47f28
esp=0x001afa9c, ebp=0x001afaa8, esi=0x01aa6400, edi=0x01aa6400
eip=0x6d91c1db, eflags=0x00010202
top of stack: (sp=0x001afa9c)
0x001afa9c: 01aa6400 37b19738 3851d3b8 001afaf8
0x001afaac: 01b89f47 01aa6518 001afb00 001afb18
0x001afabc: 23b23bc0 001afb10 00000000 00002000
0x001afacc: 6d8f1751 01aa6400 00000006 001afad8
0x001afadc: 00000000 001afb18 3851ca08 00000000
0x001afaec: 3851d3b8 00000000 001afb08 001afb3c
0x001afafc: 01b82da1 38b317c8 01b88269 00002000
0x001afb0c: 00000000 23b47f28 23b23bc0 00000005
instructions: (pc=0x6d91c1db)
0x6d91c1cb: 74 5f 8b 55 18 85 d2 74 58 8b 5d 20 8b 12 8b 00
0x6d91c1db: 8b 48 04 8b 79 08 56 53 8b 5d 1c 53 52 8b 55 14
stack: [0x00160000,0x001b0000], sp=0x001afa9c, free space=13e001af45ck
native frames: (j=compiled java code, j=interpreted, vv=vm code, c=native code)
v [jvm.dll+0x11c1db]
j java.lang.system.arraycopy(ljava/lang/object;iljava/lang/object;ii)v+0
j java.lang.string.getchars(ii[ci)v+62
j java.io.bufferedwriter.write(ljava/lang/string;ii)v+63
j java.io.writer.write(ljava/lang/string;)v+7
j java.io.printstream.write(ljava/lang/string;)v+13
j java.io.printstream.print(ljava/lang/string;)v+9
j java.io.printstream.println(ljava/lang/string;)v+6
j jni.jnitransobject.main([ljava/lang/string;)v+29
v ~stubroutines::call_stub
v [jvm.dll+0xf3abc]
v [jvm.dll+0x1865b1]
v [jvm.dll+0xf3b3d]
v [jvm.dll+0xfd385]
v [jvm.dll+0x104fdd]
c [javaw.exe+0x2155]
c [javaw.exe+0x8614]
c [kernel32.dll+0x4ed6c]
c [ntdll.dll+0x637f5]
c [ntdll.dll+0x637c8]
java frames: (j=compiled java code, j=interpreted, vv=vm code)
j java.lang.system.arraycopy(ljava/lang/object;iljava/lang/object;ii)v+0
j java.lang.string.getchars(ii[ci)v+62
j java.io.bufferedwriter.write(ljava/lang/string;ii)v+63
j java.io.writer.write(ljava/lang/string;)v+7
j java.io.printstream.write(ljava/lang/string;)v+13
j java.io.printstream.print(ljava/lang/string;)v+9
j java.io.printstream.println(ljava/lang/string;)v+6
j jni.jnitransobject.main([ljava/lang/string;)v+29
v ~stubroutines::call_stub
--------------- p r o c e s s ---------------
java threads: ( => current thread )
0x01b2e800 javathread "low memory detector" daemon [_thread_blocked, id=7580, stack(0x03e10000,0x03e60000)]
0x01b21800 javathread "compilerthread0" daemon [_thread_blocked, id=6392, stack(0x03dc0000,0x03e10000)]
0x01b19800 javathread "attach listener" daemon [_thread_blocked, id=6364, stack(0x03d70000,0x03dc0000)]
0x01b16c00 javathread "signal dispatcher" daemon [_thread_blocked, id=6360, stack(0x03d20000,0x03d70000)]
0x01acd000 javathread "finalizer" daemon [_thread_blocked, id=6348, stack(0x03cd0000,0x03d20000)]
0x01acb800 javathread "reference handler" daemon [_thread_blocked, id=6316, stack(0x03c80000,0x03cd0000)]
=>0x01aa6400 javathread "main" [_thread_in_vm, id=5408, stack(0x00160000,0x001b0000)]
other threads:
0x01aca400 vmthread [stack: 0x03c30000,0x03c80000] [id=6320]
0x01b2f400 watcherthread [stack: 0x03e60000,0x03eb0000] [id=4824]
vm state:not at safepoint (normal execution)
vm mutex/monitor currently owned by a thread: none
heap
def new generation total 4928k, used 1479k [0x23b10000, 0x24060000, 0x29060000)
eden space 4416k, 33% used [0x23b10000, 0x23c81ef8, 0x23f60000)
from space 512k, 0% used [0x23f60000, 0x23f60000, 0x23fe0000)
to space 512k, 0% used [0x23fe0000, 0x23fe0000, 0x24060000)
tenured generation total 10944k, used 0k [0x29060000, 0x29b10000, 0x33b10000)
the space 10944k, 0% used [0x29060000, 0x29060000, 0x29060200, 0x29b10000)
compacting perm gen total 12288k, used 368k [0x33b10000, 0x34710000, 0x37b10000)
the space 12288k, 2% used [0x33b10000, 0x33b6c1d0, 0x33b6c200, 0x34710000)
ro space 10240k, 51% used [0x37b10000, 0x3803b700, 0x3803b800, 0x38510000)
rw space 12288k, 54% used [0x38510000, 0x38ba76c0, 0x38ba7800, 0x39110000)
dynamic libraries:
0x00400000 - 0x00424000 c:\program files\java\jre6\bin\javaw.exe
0x77720000 - 0x7785c000 c:\windows\system32\ntdll.dll
0x75b10000 - 0x75be4000 c:\windows\system32\kernel32.dll
0x75830000 - 0x7587a000 c:\windows\system32\kernelbase.dll
0x774c0000 - 0x77560000 c:\windows\system32\advapi32.dll
0x77340000 - 0x773ec000 c:\windows\system32\msvcrt.dll
0x77870000 - 0x77889000 c:\windows\system32\sechost.dll
0x760b0000 - 0x76151000 c:\windows\system32\rpcrt4.dll
0x75ec0000 - 0x75f89000 c:\windows\system32\user32.dll
0x76010000 - 0x7605e000 c:\windows\system32\gdi32.dll
0x75b00000 - 0x75b0a000 c:\windows\system32\lpk.dll
0x75a50000 - 0x75aed000 c:\windows\system32\usp10.dll
0x77030000 - 0x7704f000 c:\windows\system32\imm32.dll
0x76db0000 - 0x76e7c000 c:\windows\system32\msctf.dll
0x7c340000 - 0x7c396000 c:\program files\java\jre6\bin\msvcr71.dll
0x6d800000 - 0x6daa7000 c:\program files\java\jre6\bin\client\jvm.dll
0x755f0000 - 0x75622000 c:\windows\system32\winmm.dll
0x754a0000 - 0x754ec000 c:\windows\system32\apphelp.dll
0x6d7b0000 - 0x6d7bc000 c:\program files\java\jre6\bin\verify.dll
0x6d330000 - 0x6d34f000 c:\program files\java\jre6\bin\java.dll
0x6d290000 - 0x6d298000 c:\program files\java\jre6\bin\hpi.dll
0x76e80000 - 0x76e85000 c:\windows\system32\psapi.dll
0x6d7f0000 - 0x6d7ff000 c:\program files\java\jre6\bin\zip.dll
0x10000000 - 0x10039000 e:\workspace\zhy\jnitransobject.dll
vm arguments:
jvm_args: -dfile.encoding=gbk
java_command: jni.jnitransobject
launcher type: sun_standard
environment variables:
java_home=c:\program files\java\jdk1.6.0_21
classpath=.;c:\program files\java\jdk1.6.0_21\lib\dt.jar;c:\program files\java\jdk1.6.0_21\lib\tools.jar
path=c:/program files/java/jre6/bin/client;c:/program files/java/jre6/bin;c:/program files/java/jre6/lib/i386;c:\program files\common files\microsoft shared\windows live;c:\program files\amd app\bin\x86;c:\windows\system32;c:\windows;c:\windows\system32\wbem;c:\windows\system32\windowspowershell\v1.0\;c:\program files\ati technologies\ati.ace\core-static;c:\program files\common files\lenovo;c:\program files\common files\ulead systems\mpeg;c:\program files\windows live\shared;c:\swtools\readyapps;c:\program files\intel\services\ipt\;c:\program files\symantec\vip access client\;c:\program files\java\jdk1.6.0_21\bin;c:\program files\java\jdk1.6.0_21\jre6\bin;c:\program files\tortoisesvn\bin;c:\program files\common files\thunder network\kankan\codecs
username=think
os=windows_nt
processor_identifier=x86 family 6 model 42 stepping 7, genuineintel
--------------- s y s t e m ---------------
os: windows 7 build 7601 service pack 1
cpu:total 4 (8 cores per cpu, 2 threads per core) family 6 model 42 stepping 7, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, ht
memory: 4k page, physical 3056880k(1883100k free), swap 6112004k(3307764k free)
vm_info: java hotspot(tm) client vm (17.0-b16) for windows-x86 jre (1.6.0_21-b06), built on jun 22 2010 00:56:49 by "java_re" with ms vc++ 7.1 (vs2003)
time: wed apr 11 09:46:47 2012
elapsed time: 0 seconds
发生这样的错误,大多是jni端代码有问题,如:不恰当的 printf 及 cout 调用,方法调用类型不兼容,调用被销毁的对象等。