Hello Everyone.
I need someone's help that I have a problem with JNI.
I got an error as below when a Java program calls JNI function that I created with VC++.
JNI functions are called not once and got an error not first call.
First of all, The JNI function is called at Main function.
then, Main function create another thread.
and next JNI function is called in another thread.
when the JNI function is called first time is suceeded.
but, second time is always failed.
I wrote down some of detail in source code's comment.
// ErrorLog is from here ------------------------------------------------------
#
# An unexpected error has been detected by HotSpot Virtual Machine:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x6d7c7c5f, pid=2460, tid=3144
#
# Java VM: Java HotSpot(TM) Client VM (1.5.0_14-b03 mixed mode)
# Problematic frame:
# V [jvm.dll+0x87c5f]
#
--------------- T H R E A D ---------------
Current thread (0x00843650): JavaThread "Thread-0" [_thread_in_vm, id=3144]
siginfo: ExceptionCode=0xc0000005, reading address 0x00000009
Registers:
EAX=0x00000001, EBX=0x06d77d40, ECX=0x00000008, EDX=0x00843710
ESP=0x0afaf4a8, EBP=0x0afaf4d8, ESI=0x0afaf4ec, EDI=0x0afaf53c
EIP=0x6d7c7c5f, EFLAGS=0x00010246
Top of Stack: (sp=0x0afaf4a8)
0x0afaf4a8: 0afaf4ec 06d77d40 6d7cfa7e 00000001
0x0afaf4b8: 0afaf53c 0afaf4ec 06d77d40 00843070
0x0afaf4c8: 00841a10 00841a18 00841e04 00843650
0x0afaf4d8: 0afaf53c 100020a6 00843710 0082f3d0
0x0afaf4e8: 0afaf5a0 0afaf5a4 06d77d40 06d77d40
0x0afaf4f8: cccccccc cccccccc cccccccc cccccccc
0x0afaf508: cccccccc cccccccc cccccccc cccccccc
0x0afaf518: cccccccc cccccccc cccccccc cccccccc
Instructions: (pc=0x6d7c7c5f)
0x6d7c7c4f: 5f 5e 5b c3 8b 44 24 04 8b 0d 14 e2 8b 6d 53 56
0x6d7c7c5f: 8b 34 01 8b 0d 10 e2 8b 6d 57 8b 3c 01 8b 0d 0c
Stack: [0x0af70000,0x0afb0000), sp=0x0afaf4a8, free space=253k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [jvm.dll+0x87c5f]
C [FilterDriver.dll+0x20a6]
C [FilterDriver.dll+0x16c7]
C [FilterDriver.dll+0x1c59]
C [FilterDriver.dll+0x22b3]
j xx.xx.xx.xx.xx.TestClass.get(Ljava/lang/String;)Z+0
j xx.xx.xx.xx.xx.ClassExtendedThread.run()V+24
v ~StubRoutines::call_stub
V [jvm.dll+0x875dd]
V [jvm.dll+0xdfd96]
V [jvm.dll+0x874ae]
V [jvm.dll+0x8720b]
V [jvm.dll+0xa2089]
V [jvm.dll+0x1112e8]
V [jvm.dll+0x1112b6]
C [MSVCRT.dll+0x2a3b0]
C [kernel32.dll+0xb683]
Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j xx.xx.xx.xx.xx.TestClass.get(Ljava/lang/String;)Z+0
j xx.xx.xx.xx.xx.ClassExtendedThread.run()V+24
v ~StubRoutines::call_stub
--------------- P R O C E S S ---------------
Java Threads: ( => current thread )
0x008433b0 JavaThread "DestroyJavaVM" [_thread_blocked, id=2676]
=>0x00843650 JavaThread "Thread-0" [_thread_in_vm, id=3144]
0x0083d5f0 JavaThread "Low Memory Detector" daemon [_thread_blocked, id=2024]
0x0083c730 JavaThread "CompilerThread0" daemon [_thread_blocked, id=3444]
0x0083b560 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=2784]
0x00839970 JavaThread "JDWP Command Reader" daemon [_thread_in_native, id=2876]
0x00838c60 JavaThread "JDWP Event Helper Thread" daemon [_thread_blocked, id=2980]
0x00836250 JavaThread "JDWP Transport Listener: dt_socket" daemon [_thread_blocked, id=536]
0x0082e410 JavaThread "Finalizer" daemon [_thread_blocked, id=2100]
0x0082d190 JavaThread "Reference Handler" daemon [_thread_blocked, id=1968]
Other Threads:
0x0082c470 VMThread [id=296]
0x0083fd50 WatcherThread [id=464]
VM state:not at safepoint (normal execution)
VM Mutex/Monitor currently owned by a thread: None
Heap
def new generation total 576K, used 300K [0x02bd0000, 0x02c70000, 0x030b0000)
eden space 512K, 58% used [0x02bd0000, 0x02c1b200, 0x02c50000)
from space 64K, 0% used [0x02c50000, 0x02c50000, 0x02c60000)
to space 64K, 0% used [0x02c60000, 0x02c60000, 0x02c70000)
tenured generation total 1408K, used 0K [0x030b0000, 0x03210000, 0x06bd0000)
the space 1408K, 0% used [0x030b0000, 0x030b0000, 0x030b0200, 0x03210000)
compacting perm gen total 8192K, used 1711K [0x06bd0000, 0x073d0000, 0x0abd0000)
the space 8192K, 20% used [0x06bd0000, 0x06d7bf00, 0x06d7c000, 0x073d0000)
No shared spaces configured.
Dynamic libraries:
0x00400000 - 0x0040d000 C:\Program Files\Java\jdk1.5.0_14\bin\javaw.exe
0x7c940000 - 0x7c9dd000 C:\WINDOWS\system32\ntdll.dll
0x7c800000 - 0x7c932000 C:\WINDOWS\system32\kernel32.dll
0x77d80000 - 0x77e29000 C:\WINDOWS\system32\ADVAPI32.dll
0x77e30000 - 0x77ec1000 C:\WINDOWS\system32\RPCRT4.dll
0x77cf0000 - 0x77d7f000 C:\WINDOWS\system32\USER32.dll
0x77ed0000 - 0x77f17000 C:\WINDOWS\system32\GDI32.dll
0x77bc0000 - 0x77c18000 C:\WINDOWS\system32\MSVCRT.dll
0x762e0000 - 0x762fd000 C:\WINDOWS\system32\IMM32.DLL
0x60740000 - 0x60749000 C:\WINDOWS\system32\LPK.DLL
0x73f80000 - 0x73feb000 C:\WINDOWS\system32\USP10.dll
0x6d740000 - 0x6d8de000 C:\Program Files\Java\jdk1.5.0_14\jre\bin\client\jvm.dll
0x76af0000 - 0x76b1b000 C:\WINDOWS\system32\WINMM.dll
0x6d300000 - 0x6d308000 C:\Program Files\Java\jdk1.5.0_14\jre\bin\hpi.dll
0x76ba0000 - 0x76bab000 C:\WINDOWS\system32\PSAPI.DLL
0x6d400000 - 0x6d435000 C:\Program Files\Java\jdk1.5.0_14\jre\bin\jdwp.dll
0x6d710000 - 0x6d71c000 C:\Program Files\Java\jdk1.5.0_14\jre\bin\verify.dll
0x6d380000 - 0x6d39d000 C:\Program Files\Java\jdk1.5.0_14\jre\bin\java.dll
0x6d730000 - 0x6d73f000 C:\Program Files\Java\jdk1.5.0_14\jre\bin\zip.dll
0x6d290000 - 0x6d297000 C:\Program Files\Java\jdk1.5.0_14\jre\bin\dt_socket.dll
0x719e0000 - 0x719f7000 C:\WINDOWS\system32\WS2_32.dll
0x719d0000 - 0x719d8000 C:\WINDOWS\system32\WS2HELP.dll
0x71980000 - 0x719bf000 C:\WINDOWS\System32\mswsock.dll
0x76ed0000 - 0x76ef7000 C:\WINDOWS\system32\DNSAPI.dll
0x76f60000 - 0x76f68000 C:\WINDOWS\System32\winrnr.dll
0x76f10000 - 0x76f3c000 C:\WINDOWS\system32\WLDAP32.dll
0x76f70000 - 0x76f76000 C:\WINDOWS\system32\rasadhlp.dll
0x607c0000 - 0x60816000 C:\WINDOWS\system32\hnetcfg.dll
0x719c0000 - 0x719c8000 C:\WINDOWS\System32\wshtcpip.dll
0x10000000 - 0x10076000 C:\xx\whaticreated.dll
0x71a50000 - 0x71a62000 C:\WINDOWS\system32\MPR.dll
VM Arguments:
jvm_args: -agentlib:jdwp=transport=dt_socket,suspend=y,address=localhost:1759
java_command: xx.xx.xx.xx.xx.Sample start
Launcher Type: SUN_STANDARD
Environment Variables:
JAVA_HOME=C:\Program Files\Java\jdk1.5.0_14
PATH=C:\WINDOWS\system32;C:\WINDOWS;D:\tools\apache-ant-1.7.0\bin;C:\Program Files\Microsoft SQL Server\90\Tools\binn\;D:\PROGRA~1\ATT\Graphviz\bin;D:\Program Files\doxygen\bin;D:\Program Files\Microsoft SDK\Bin\.;D:\Program Files\Microsoft SDK\Bin\WinNT\.;C:\Program Files\Java\jdk1.5.0_14\bin;C:\Program Files\Microsoft Visual Studio\Common\Tools\WinNT;C:\Program Files\Microsoft Visual Studio\Common\MSDev98\Bin;C:\Program Files\Microsoft Visual Studio\Common\Tools;C:\Program Files\Microsoft Visual Studio\VC98\bin;D:\Program Files\Microsoft SDK\Bin\.;D:\Program Files\Microsoft SDK\Bin\WinNT\.
USERNAME=xxx
OS=Windows_NT
PROCESSOR_IDENTIFIER=x86 Family 6 Model 15 Stepping 2, GenuineIntel
--------------- S Y S T E M ---------------
OS: Windows XP Build 2600 Service Pack 2
CPU:total 2 (cores per cpu 2, threads per core 1) family 6 model 15 stepping 2, cmov, cx8, fxsr, mmx, sse, sse2
Memory: 4k page, physical 1038124k(270512k free), swap 1711740k(953716k free)
vm_info: Java HotSpot(TM) Client VM (1.5.0_14-b03) for windows-x86, built on Oct 5 2007 01:21:52 by "java_re" with MS VC++ 6.0
// The end of ErrorLog --------------------------------------------------------
and the codes are below.
// TestClass.java
public class TestClass {
// Load native library
static{
System.loadLibrary("DLLName");
}
public native int start(String str, int count);
public native int end();
public native boolean get(String str);
}
// ClassExtendedThread.java
public class ClassExtendedThread extends Thread {
private TestClass tc;
// Constructor
public ClassExtendedThread(TestClass in_tc)
{
ts = in_tc;
}
// This will be executing in another thread
public void run()
{
while( true )
{
if( !false )
{
String str = new String();
// get function returns false means nothing to catch event.
if( false == ts.get( str ) ) // calling first time is suceed. but, I got an error second time.
{
// Set Interval for loop.
}
}
}
}
}
// Sample.java
public class Sample {
public static void main(String[] args) {
TestClass tc = null;
ClassExtendedThread cet = null;
tc = new TestClass();
// Init something
if(0 != TestClass.start(xxx, xxx)) // First JNI function suceeds.
{
System.out.println("start error.");
return;
}
// Starting Thread
cet = new ClassExtendedThread(tc);
cet.start();
}
Have anyone got any idea to resolve this problem?
Edited by: fc3srx7m on Apr 25, 2008 3:56 AM