Exception_Access_Violation-外部设备API-JNI

2019年6月22日 27点热度 0条评论

我正在尝试通过JNI从c++项目调用本机方法。不幸的是,我得到了“EXCEPTION_ACCESS_VIOLATION” [1]。

我调试了代码,发现由于以下几行代码而引发了异常。具有注释/来自另一个类的调用方法的类(包括.header文件)。

JNIEXPORT void JNICALL Java_gwap_control_Coordinates_start_1tracking
(JNIEnv *, jclass){

char url[20] = "tet-tcp://127.0.0.1";
comp_error_code error_code;
comp_device* device;

// Create an device instance.
device = comp_create(url, &error_code);

// Start the event loop.
comp_run_event_loop_on_internal_thread(device, 0, 0);

[...]

// Track for a while
XSLEEP(20000);

[...]

将项目编译为.exe并在命令行中运行即可。当将其编译为.dll并将其包含到我的Java项目中时,将引发异常。如果上述代码行被注释掉,则不会引发异常。

由此我得出结论,我的cpp代码和Java代码都是正确的。我想问题可能是当编译成库文件(?)时,(完整的)本机代码未完全包含在(通常工作的)项目中。

代码本身是用于获取外围 Controller 的输出数据(坐标)的。因此,我编辑了一个现有的(c / cpp-)SDK以在Java应用程序中使用数据。

我正在使用的系统和软件在[1]的末尾指定,UAC已关闭。

对于解决问题的每一个提示或想法,我将不胜感激。

提前致谢!

[1]

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x000000000000c8fc, pid=2804, tid=4248
#
# JRE version: Java(TM) SE Runtime Environment (8.0_05-b13) (build 1.8.0_05-b13)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.5-b02 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  0x000000000000c8fc
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.sun.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#

---------------  T H R E A D  ---------------

Current thread (0x0000000001f8e800):  JavaThread "main" [_thread_in_native, id=4248, stack(0x0000000002090000,0x0000000002190000)]

siginfo: ExceptionCode=0xc0000005, ExceptionInformation=0x0000000000000008 0x000000000000c8fc

Registers:
RAX=0x000000000218f4e8, RBX=0x0000000016180850, RCX=0x0000000000004e20, RDX=0x000000000218f5b0
RSP=0x000000000218f4b8, RBP=0x000000000218f5a0, RSI=0x00007ff71f0e78ec, RDI=0x000000000218f4fc
R8 =0x0000000000000004, R9 =0x0000000001f885e0, R10=0x00000000022a4b42, R11=0x000000005b479df0
R12=0x0000000000000000, R13=0x0000000016180850, R14=0x000000000218f5b8, R15=0x0000000001f8e800
RIP=0x000000000000c8fc, EFLAGS=0x0000000000010202

Top of Stack: (sp=0x000000000218f4b8)
0x000000000218f4b8:   00007ff71f0e13ca cccccccccccccccc
0x000000000218f4c8:   cccccccccccccccc cccccccccccccccc
0x000000000218f4d8:   cccccccccccccccc cccccccccccccccc
0x000000000218f4e8:   3a7063742d746574 2e302e3732312f2f
0x000000000218f4f8:   cccccccc00312e30 cccccccccccccccc
0x000000000218f508:   cccccccccccccccc cccccccccccccccc
0x000000000218f518:   00002b992fc756f2 cccccccccccccccc
0x000000000218f528:   00000000ffffffff 0000000001f8e800
0x000000000218f538:   00000000022a4b6e 0000000001f8e9e0
0x000000000218f548:   000000000218f5b0 000000000218f610
0x000000000218f558:   00000000022a489c 000000000218f560
0x000000000218f568:   0000000016180850 000000000218f5b8
0x000000000218f578:   0000000016180b18 0000000000000000
0x000000000218f588:   0000000016180850 0000000000000000
0x000000000218f598:   000000000218f5c0 000000000218f600
0x000000000218f5a8:   0000000002297380 00000000d9b12f60 

Instructions: (pc=0x000000000000c8fc)
0x000000000000c8dc:   
[error occurred during error reporting (printing registers, top of stack, instructions near pc), id 0xc0000005]

Register to memory mapping:

RAX=0x000000000218f4e8 is pointing into the stack for thread: 0x0000000001f8e800
RBX=0x0000000016180850 is an unknown value
RCX=0x0000000000004e20 is an unknown value
RDX=0x000000000218f5b0 is pointing into the stack for thread: 0x0000000001f8e800
RSP=0x000000000218f4b8 is pointing into the stack for thread: 0x0000000001f8e800
RBP=0x000000000218f5a0 is pointing into the stack for thread: 0x0000000001f8e800
RSI=0x00007ff71f0e78ec is an unknown value
RDI=0x000000000218f4fc is pointing into the stack for thread: 0x0000000001f8e800
R8 =0x0000000000000004 is an unknown value
R9 =0x0000000001f885e0 is an unknown value
R10=0x00000000022a4b42 is at code_begin+834 in an Interpreter codelet
method entry point (kind = native)  [0x00000000022a4800, 0x00000000022a5140]  2368 bytes
R11=0x000000005b479df0 is an unknown value
R12=0x0000000000000000 is an unknown value
R13=0x0000000016180850 is an unknown value
R14=0x000000000218f5b8 is pointing into the stack for thread: 0x0000000001f8e800
R15=0x0000000001f8e800 is a thread


Stack: [0x0000000002090000,0x0000000002190000],  sp=0x000000000218f4b8,  free space=1021k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  0x000000000000c8fc

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  gwap.control.Coordinates.start_tracking()V+0
j  gwap.control.ControllerMain.main([Ljava/lang/String;)V+0
v  ~StubRoutines::call_stub

---------------  P R O C E S S  ---------------

Java Threads: ( => current thread )
  0x0000000017fa0800 JavaThread "Service Thread" daemon [_thread_blocked, id=4276, stack(0x0000000018380000,0x0000000018480000)]
  0x0000000016729000 JavaThread "C1 CompilerThread2" daemon [_thread_blocked, id=3340, stack(0x0000000017e80000,0x0000000017f80000)]
  0x0000000016720800 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=3296, stack(0x0000000017d80000,0x0000000017e80000)]
  0x000000001671e800 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=4208, stack(0x0000000017c80000,0x0000000017d80000)]
  0x000000001671d000 JavaThread "Attach Listener" daemon [_thread_blocked, id=4808, stack(0x0000000017b80000,0x0000000017c80000)]
  0x000000001671c800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=5960, stack(0x0000000017a80000,0x0000000017b80000)]
  0x0000000002284000 JavaThread "Finalizer" daemon [_thread_blocked, id=3288, stack(0x0000000017980000,0x0000000017a80000)]
  0x000000000227b000 JavaThread "Reference Handler" daemon [_thread_blocked, id=5664, stack(0x0000000017880000,0x0000000017980000)]
=>0x0000000001f8e800 JavaThread "main" [_thread_in_native, id=4248, stack(0x0000000002090000,0x0000000002190000)]

Other Threads:
  0x00000000166e5800 VMThread [stack: 0x0000000017780000,0x0000000017880000] [id=1492]
  0x0000000017fad800 WatcherThread [stack: 0x0000000018480000,0x0000000018580000] [id=4744]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap:
 PSYoungGen      total 1024K, used 505K [0x00000000d9b00000, 0x00000000d9d00000, 0x0000000100000000)
  eden space 512K, 20% used [0x00000000d9b00000,0x00000000d9b1a4e8,0x00000000d9b80000)
  from space 512K, 78% used [0x00000000d9b80000,0x00000000d9be4010,0x00000000d9c00000)
  to   space 512K, 0% used [0x00000000d9c80000,0x00000000d9c80000,0x00000000d9d00000)
 ParOldGen       total 117248K, used 8K [0x000000008d000000, 0x0000000094280000, 0x00000000d9b00000)
  object space 117248K, 0% used [0x000000008d000000,0x000000008d002000,0x0000000094280000)
 Metaspace       used 2366K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 264K, capacity 386K, committed 512K, reserved 1048576K

Card table byte_map: [0x0000000011650000,0x00000000119f0000] byte_map_base: 0x00000000111e8000

Marking Bits: (ParMarkBitMap*) 0x000000005ba213b0
 Begin Bits: [0x0000000012060000, 0x0000000013d20000)
 End Bits:   [0x0000000013d20000, 0x00000000159e0000)

Polling page: 0x0000000000810000

CodeCache: size=245760Kb used=1103Kb max_used=1103Kb free=244656Kb
 bounds [0x0000000002290000, 0x0000000002500000, 0x0000000011290000]
 total_blobs=253 nmethods=29 adapters=140
 compilation: enabled

Compilation events (10 events):
Event: 0.091 Thread 0x0000000016729000   25       3       java.lang.String::startsWith (72 bytes)
Event: 0.091 Thread 0x0000000016729000 nmethod 25 0x00000000023a11d0 code [0x00000000023a1340, 0x00000000023a1670]
Event: 0.091 Thread 0x0000000016729000   26       3       java.lang.String::indexOf (7 bytes)
Event: 0.091 Thread 0x0000000016729000 nmethod 26 0x00000000023a1850 code [0x00000000023a19c0, 0x00000000023a1bc8]
Event: 0.092 Thread 0x0000000016729000   27       3       java.io.WinNTFileSystem::normalize (143 bytes)
Event: 0.092 Thread 0x0000000016729000 nmethod 27 0x00000000023a1c50 code [0x00000000023a1e40, 0x00000000023a2648]
Event: 0.092 Thread 0x0000000016729000   28       3       java.util.HashMap::getNode (148 bytes)
Event: 0.093 Thread 0x0000000016729000 nmethod 28 0x00000000023a29d0 code [0x00000000023a2ba0, 0x00000000023a3528]
Event: 0.093 Thread 0x0000000016729000   29       3       java.lang.String::equals (81 bytes)
Event: 0.093 Thread 0x0000000016729000 nmethod 29 0x00000000023a3810 code [0x00000000023a39a0, 0x00000000023a3ef0]

GC Heap History (2 events):
Event: 0.083 GC heap before
{Heap before GC invocations=1 (full 0):
 PSYoungGen      total 1024K, used 512K [0x00000000d9b00000, 0x00000000d9c80000, 0x0000000100000000)
  eden space 512K, 100% used [0x00000000d9b00000,0x00000000d9b80000,0x00000000d9b80000)
  from space 512K, 0% used [0x00000000d9c00000,0x00000000d9c00000,0x00000000d9c80000)
  to   space 512K, 0% used [0x00000000d9b80000,0x00000000d9b80000,0x00000000d9c00000)
 ParOldGen       total 117248K, used 0K [0x000000008d000000, 0x0000000094280000, 0x00000000d9b00000)
  object space 117248K, 0% used [0x000000008d000000,0x000000008d000000,0x0000000094280000)
 Metaspace       used 2170K, capacity 4480K, committed 4480K, reserved 1056768K
  class space    used 244K, capacity 384K, committed 384K, reserved 1048576K
Event: 0.084 GC heap after
Heap after GC invocations=1 (full 0):
 PSYoungGen      total 1024K, used 400K [0x00000000d9b00000, 0x00000000d9d00000, 0x0000000100000000)
  eden space 512K, 0% used [0x00000000d9b00000,0x00000000d9b00000,0x00000000d9b80000)
  from space 512K, 78% used [0x00000000d9b80000,0x00000000d9be4010,0x00000000d9c00000)
  to   space 512K, 0% used [0x00000000d9c80000,0x00000000d9c80000,0x00000000d9d00000)
 ParOldGen       total 117248K, used 8K [0x000000008d000000, 0x0000000094280000, 0x00000000d9b00000)
  object space 117248K, 0% used [0x000000008d000000,0x000000008d002000,0x0000000094280000)
 Metaspace       used 2170K, capacity 4480K, committed 4480K, reserved 1056768K
  class space    used 244K, capacity 384K, committed 384K, reserved 1048576K
}

Deoptimization events (0 events):
No events

Internal exceptions (4 events):
Event: 0.039 Thread 0x0000000001f8e800 Exception <a 'java/lang/NoSuchMethodError': Method sun.misc.Unsafe.defineClass(Ljava/lang/String;[BII)Ljava/lang/Class; name or signature does not match> (0x00000000d9b10868) thrown at [D:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u5\2488\hotspot\src\çò;Ô¤?
Event: 0.039 Thread 0x0000000001f8e800 Exception <a 'java/lang/NoSuchMethodError': Method sun.misc.Unsafe.prefetchRead(Ljava/lang/Object;J)V name or signature does not match> (0x00000000d9b10af8) thrown at [D:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u5\2488\hotspot\src\share\vm\prims\jnì¨!'×µ?
Event: 0.085 Thread 0x0000000001f8e800 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d9b096c0) thrown at [D:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u5\2488\hotspot\src\share\vm\prims\jvm.cpp, line 1248]
Event: 0.091 Thread 0x0000000001f8e800 Exception <a 'java/security/PrivilegedActionException'> (0x00000000d9b11e08) thrown at [D:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u5\2488\hotspot\src\share\vm\prims\jvm.cpp, line 1248]

Events (10 events):
Event: 0.090 loading class java/security/UnresolvedPermission
Event: 0.090 loading class java/security/UnresolvedPermission done
Event: 0.090 loading class java/security/BasicPermissionCollection
Event: 0.090 loading class java/security/BasicPermissionCollection done
Event: 0.090 loading class sun/launcher/LauncherHelper$FXHelper
Event: 0.091 loading class sun/launcher/LauncherHelper$FXHelper done
Event: 0.091 loading class gwap/control/Coordinates
Event: 0.091 loading class gwap/control/Coordinates done
Event: 0.091 loading class java/lang/ClassLoaderHelper
Event: 0.091 loading class java/lang/ClassLoaderHelper done


Dynamic libraries:
0x00007ff6ba360000 - 0x00007ff6ba394000     C:\Program Files\Java\jre8\bin\javaw.exe
0x00007fff97cb0000 - 0x00007fff97e5a000     C:\Windows\SYSTEM32\ntdll.dll
0x00007fff96080000 - 0x00007fff961ba000     C:\Windows\system32\KERNEL32.DLL
0x00007fff95420000 - 0x00007fff9552f000     C:\Windows\system32\KERNELBASE.dll
0x00007fff93c30000 - 0x00007fff93cb8000     C:\Windows\system32\apphelp.dll
0x00007fff90800000 - 0x00007fff9084f000     C:\Windows\AppPatch\AppPatch64\AcGenral.DLL
0x00007fff96580000 - 0x00007fff96627000     C:\Windows\system32\msvcrt.dll
0x00007fff94e00000 - 0x00007fff94e2b000     C:\Windows\SYSTEM32\SspiCli.dll
0x00007fff962e0000 - 0x00007fff96331000     C:\Windows\system32\SHLWAPI.dll
0x00007fff95880000 - 0x00007fff959f1000     C:\Windows\system32\USER32.dll
0x00007fff96340000 - 0x00007fff964b8000     C:\Windows\system32\ole32.dll
0x00007fff96890000 - 0x00007fff97cb0000     C:\Windows\system32\SHELL32.dll
0x00007fff94a00000 - 0x00007fff94a1e000     C:\Windows\SYSTEM32\USERENV.dll
0x00007fff95fd0000 - 0x00007fff96075000     C:\Windows\system32\ADVAPI32.dll
0x00007fff91bb0000 - 0x00007fff91bcb000     C:\Windows\SYSTEM32\MPR.dll
0x00007fff95ba0000 - 0x00007fff95cd6000     C:\Windows\system32\RPCRT4.dll
0x00007fff95ce0000 - 0x00007fff95d37000     C:\Windows\SYSTEM32\sechost.dll
0x00007fff95550000 - 0x00007fff95726000     C:\Windows\SYSTEM32\combase.dll
0x00007fff95730000 - 0x00007fff95874000     C:\Windows\system32\GDI32.dll
0x00007fff95020000 - 0x00007fff95034000     C:\Windows\SYSTEM32\profapi.dll
0x00007fff93660000 - 0x00007fff936ff000     C:\Windows\SYSTEM32\SHCORE.dll
0x00007fff96520000 - 0x00007fff96554000     C:\Windows\system32\IMM32.DLL
0x00007fff95a00000 - 0x00007fff95b39000     C:\Windows\system32\MSCTF.dll
0x00007fff929a0000 - 0x00007fff92bfa000     C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9600.17031_none_6242a4b3ecbb55a1\COMCTL32.dll
0x000000005cd60000 - 0x000000005ce32000     C:\Program Files\Java\jre8\bin\msvcr100.dll
0x000000005b270000 - 0x000000005ba9a000     C:\Program Files\Java\jre8\bin\server\jvm.dll
0x00007fff93270000 - 0x00007fff93279000     C:\Windows\SYSTEM32\WSOCK32.dll
0x00007fff91dd0000 - 0x00007fff91def000     C:\Windows\SYSTEM32\WINMM.dll
0x00007fff96560000 - 0x00007fff96567000     C:\Windows\system32\PSAPI.DLL
0x00007fff961c0000 - 0x00007fff96218000     C:\Windows\system32\WS2_32.dll
0x00007fff91da0000 - 0x00007fff91dca000     C:\Windows\SYSTEM32\WINMMBASE.dll
0x00007fff96570000 - 0x00007fff96579000     C:\Windows\system32\NSI.dll
0x00007fff953d0000 - 0x00007fff9541a000     C:\Windows\SYSTEM32\cfgmgr32.dll
0x00007fff93eb0000 - 0x00007fff93ed6000     C:\Windows\SYSTEM32\DEVOBJ.dll
0x000000005cd50000 - 0x000000005cd5f000     C:\Program Files\Java\jre8\bin\verify.dll
0x000000005cd20000 - 0x000000005cd48000     C:\Program Files\Java\jre8\bin\java.dll
0x000000005cd00000 - 0x000000005cd16000     C:\Program Files\Java\jre8\bin\zip.dll
0x00007ff71f0e0000 - 0x00007ff71f0ef000     C:\Users\...\workspace\...\TrackingAPI.dll
0x00007fff74360000 - 0x00007fff743f6000     C:\Users\...\workspace\...\CompCore64.dll
0x00007fff8ecc0000 - 0x00007fff8ed67000     C:\Windows\SYSTEM32\MSVCP110.dll
0x00007fff8ebe0000 - 0x00007fff8ecb4000     C:\Windows\SYSTEM32\MSVCR110.dll
0x00007fff925c0000 - 0x00007fff92748000     C:\Windows\SYSTEM32\dbghelp.dll

VM Arguments:
jvm_args: -Dfile.encoding=UTF-8 
java_command: gwap.control.ControllerMain
java_class_path (initial): C:\Users\...\workspace\...\bin;C:\Users\...\workspace\...\lib\eventbus.jar;C:\Users\..\workspace\...\lib\gluegen-rt.jar;C:\Users\...\workspace\...\lib\j-ogg-oggd.jar;C:\Users\...\workspace\...\lib\j-ogg-vorbisd.jar;C:\Users\...\workspace\...\lib\jbullet.jar;C:\Users\...\workspace\...\lib\jglfont-core.jar;C:\Users\...\workspace\...\lib\jinput.jar;C:\Users\...\workspace\...\lib\jME3-blender.jar;C:\Users\...\workspace\...\lib\jME3-core.jar;C:\Users\...\workspace\...\lib\jME3-desktop.jar;C:\Users\...\workspace\...\lib\jME3-effects.jar;C:\Users\...\workspace\...\lib\jME3-jbullet.jar;C:\Users\...\workspace\...\lib\jME3-jogg.jar;C:\Users\...\workspace\...\lib\jME3-lwjgl-natives.jar;C:\Users\...\workspace\...\lib\jME3-lwjgl.jar;C:\Users\...\workspace\...\lib\jME3-networking.jar;C:\Users\...\workspace\...\lib\jME3-niftygui.jar;C:\Users\...\workspace\...\lib\jME3-openal-soft-natives-android.jar;C:\Users\...\workspace\...\lib\jME3-plugins.jar;C:\Users\...\workspace\...\lib\jME3-terrain.jar;C:\Users\...\workspace\...\lib\jME3-testdata.jar;C:\Users\...\workspace\...\lib\joal.jar;C:\Users\...\workspace\...\lib\jogl-all.jar;C:\Users\...\workspace\...\lib\lwjgl.jar;C:\Users\...\workspace\...\lib\nifty-default-controls.jar;C:\Users\...\workspace\...\lib\nifty-examples.jar;C:\Users\...\workspace\...\lib\nifty-style-black.jar;C:\Users\...\workspace\...\lib\nifty.jar;C:\Users\...\
Launcher Type: SUN_STANDARD

Environment Variables:
PATH=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files (x86)\Comp\Comp Device Controller\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.0\
USERNAME=...
OS=Windows_NT
PROCESSOR_IDENTIFIER=AMD64 Family 21 Model 19 Stepping 1, AuthenticAMD



---------------  S Y S T E M  ---------------

OS: Windows 8.1 , 64 bit Build 9600 

CPU:total 4 (4 cores per cpu, 1 threads per core) family 21 model 19 stepping 1, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, aes, clmul, mmxext, 3dnowpref, lzcnt, sse4a, tsc, tscinvbit

Memory: 4k page, physical 7535300k(5091636k free), swap 8714948k(5116720k free)

vm_info: Java HotSpot(TM) 64-Bit Server VM (25.5-b02) for windows-amd64 JRE (1.8.0_05-b13), built on Mar 18 2014 01:08:39 by "java_re" with MS VC++ 10.0 (VS2010)

time: Tue Jul 01 13:41:40 2014
elapsed time: 0 seconds

解决方案如下:

发现了问题:VisualStudio(或I)没有将配置类型正确更改为.dll。可以在项目首选项的projectstandards选项卡中进行检查。