Java运行时环境-.EXCEPTION_ACCESS_VIOLATION检测到致命错误 [英] A fatal error has been detected by the Java Runtime Environment - .EXCEPTION_ACCESS_VIOLATION

查看:247
本文介绍了Java运行时环境-.EXCEPTION_ACCESS_VIOLATION检测到致命错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试加载JNI C / C ++ dll库时,出现此错误,并且我注意到它说崩溃发生在Java虚拟机外部,以本机代码显示。不确定那是什么意思?



Java源代码如下:

 软件包demojni; 
公共类Main {
静态{
System.load( C:\\Users\\Nicholas1\\Documents\\NetBeansProjects\\DemoJNI_Lib \\dist\\DemoJNI_Lib.dll); //在运行时加载本机库
// hello.dll(Windows)或libhello.so(Unixes)
}

//声明一个接收本机方法sayHello()什么也不会返回void


//测试驱动程序
public static void main(String [] args){
new Main()。sayHelloWorld(); //调用本地方法
}
private native void sayHelloWorld();
}

C源代码如下:

  #include DemoJNI_Lib.h 
#include< stdio.h>

JNIEXPORT void JNICALL Java_demojni_Main_sayHelloWorld
(JNIEnv * env,jobject obj){
printf( Hello World \n);
}

JNI C-header-源代码如下:

  / *不要编辑此文件-它是机器生成的* / 
#include< jni.h>
/ *类标题demojni_Main * /

#ifndef _Included_demojni_Main
#define _Included_demojni_Main
#ifdef __cplusplus
extern C {
#endif
/ *
*类:demojni_Main
*方法:sayHelloWorld
*签名:()V
* /
JNIEXPORT void JNICALL Java_demojni_Main_sayHelloWorld
(JNIEnv *,jobject);

#ifdef __cplusplus
}
#endif
#endif

运行Main.java文件时出错:

 #Java检测到致命错误运行时环境:

#EXCEPTION_ACCESS_VIOLATION(0xc0000005)at pc = 0x0000000002c2ed90,pid = 7552,tid = 0x0000000000001e2c

#JRE版本:Java(TM)SE运行时环境( 8.0_111-b14)(内部版本1.8.0_111-b14)
#Java虚拟机:Java HotSpot(TM)64位服务器VM(25.111-b14混合模式Windows-amd64压缩oops)
#有问题的框架:
#C 0x0000000002c2ed90

#无法写入核心转储。 Windows客户端版本上默认不启用小型转储

#包含更多信息的错误报告文件另存为:
#C:\Users\Nicholas1\Documents\ NetBeansProjects\DemoJNI\hs_err_pid7552.log

#如果您要​​提交错误报告,请访问:
#http://bugreport.java.com/bugreport/crash .jsp
#崩溃发生在Java虚拟机以外的本机代码中。
#请参阅有问题的框架以报告错误。

C:\Users\Nicholas1\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53:Java返回:1
建立失败(总时间:27秒)

错误日志(hs_err_pid7552.log):

 
#Java运行时环境检测到致命错误:

#EXCEPTION_ACCESS_VIOLATION(0xc0000005)at pc = 0x0000000002c2ed90,pid = 7552,tid = 0x0000000000001e2c

#JRE版本:Java(TM)SE运行时环境(8.0_111-b14)(内部版本1.8.0_111-b14 )
#Java VM:Java HotSpot(TM)64位服务器VM(25.111-b14混合模式Windows-amd64压缩的oops)
#有问题的帧:
#C 0x0000000002c2ed90

#无法写入核心转储。 Windows客户端版本上默认不启用小型转储

#如果您要​​提交错误报告,请访问:
#http://bugreport.java.com/bugreport /crash.jsp
#崩溃发生在Java虚拟机以外的本机代码中。
#请参阅有问题的框架以报告错误。


---------------线迹---------------

当前线程(0x00000000013dd800):JavaThread main [_thread_in_native,id = 7724,堆栈(0x0000000002b30000,0x0000000002c30000)]

siginfo:ExceptionCode = 0xc0000005,ExceptionInformation = 0x0000000000000008 0x0000000002c2ed90
b $ b寄存器:
RAX = 0x000000000000000a,RBX = 0x0000000014de0360,RCX = 0x00000001802e4ae0,RDX = 0x0000000000000000
RSP = 0x0000000002c2f140,RBP = 0x0000000002c2f160,RSI = 0x0000000020200021,RDI = 0x00000000bffc8,RDI = 0x00000000bffc R9 = 0x000000018013c900,R10 = 0x0000000002c30000,R11 = 0x0000000002c2ed90
R12 = 0x0000000000000000,R13 = 0x0000000014de0360,R14 = 0x0000000002c2f1f8,R15 = 0x00000000013dd800
RIP = 0x0000000002c2ed90,EFLAGSbb = 0堆栈数:(sp = 0x0000000002c2f140)
0x0000000002c2f140:0000000002c2f400 00000000013dd800
0x0000000002c2f150:0000000014de0360 0000000020200021
0x0000000002c2f160:0000000002c2f1 D8 0000000002d97f74
0x0000000002c2f170:00000000013dd9f8 0000000002c2f1f8
0x0000000002c2f180:0000000020200021 00000000013dd800
0x0000000002c2f190:0000000002d97ca2 0000000002c2f198
0x0000000002c2f1a0:0000000014de0360 0000000002c2f1f8
0x0000000002c2f1b0:0000000014de0460 0000000000000000
0x0000000002c2f1c0:0000000014de0360 0000000000000000
0x0000000002c2f1d0:0000000002c2f1f8 0000000002c2f240
0x0000000002c2f1e0:0000000002d8835d 0000000000000000
0x0000000002c2f1f0:0000000002d919d8 00000000eb26c8f8
0x0000000002c2f200:0000000002c2f200 0000000014de02bf
0x0000000002c2f210:0000000002c2f250 0000000014de0460
0x0000000002c2f220:0000000000000000 0000000014de02d8
0x0000000002c2f230:0000000002c2f1f8 0000000002c2f250

指令:(pc = 0x0000000002c2ed90)
0x0000000002c2ed70:1e 00 1f 00 00 00 00 00 00 1d fc 1e 80 01 00 00 00
0x0000000002c2ed80:00 00 00 00 00 00 00 00 cb 17 2a 47 f8 7f 00 00
0x0000000002c2ed90:00 d8 3d 01 00 00 00 00 f8 f1 c2 02 00 00 00 00
0x0000000002c2eda0:60 03 de 14 00 00 00 00 00 00 00 00 00 00 00


寄存器到内存的映射:

RAX = 0x000000000000000a是一个未知值
RBX = {method} {0x0000000014de0368}'sayHelloWorld''()V'在'demojni / Main'中
RCX = 0x00000001802e4ae0是一个未知值
RDX = 0x0000000000000000是一个未知值
RSP = 0x0000000002c2f140指向线程堆栈:0x00000000013dd800
RBP = 0x0000000002c2f160指向线程堆栈:0x00000000013dd800
RSI = 0x0000000020200021是一个未知值
RDI = 0x00000000ffffffff是堆中未分配的位置
R8 = 0x0000000002c2f0dc指向线程堆栈: 0x00000000013dd800
R9 = 0x000000018013c900是一个未知值
R10 = 0x0000000002c30000指向堆栈的线程:0x00000000013dd800
R11 = 0x0000000002c2ed90指向堆栈对于线程:0x00000000013dd800
R12 = 0x0000000000000000是一个未知值
R13 = {method} {0x0000000014de0368}'demojni / Main'中的'sayHelloWorld''()V'
R14 = 0x0000000002c2f1f8指向进入线程堆栈:0x00000000013dd800
R15 = 0x00000000013dd800是线程


堆栈:[0x0000000002b30000,0x0000000002c30000],sp = 0x0000000002c2f140,可用空间= 1020k
本机框架:(J =编译Java代码,j =解释,Vv = VM代码,C =本机代码)
C 0x0000000002c2ed90

Java框架:(J =编译Java代码,j =解释,Vv = VM代码)
j demojni.Main.sayHelloWorld()V + 0
j demojni.Main.main([Ljava / lang / String;)V + 7
v〜StubRoutines :: call_stub

---------------过程---------------

Java线程: (=>当前线程)
0x00000000153de000 JavaThread服务线程守护程序[_thread_blocked,id = 6960,堆栈(0x0000000017200000,0x0000000017300000)]
0x000000001538c000 JavaThread C1 CompilerThread2守护程序[_thread_blocked,id = 5380,stack(0x0000000016d 0x0000000016e00000)]
0x0000000015383000 JavaThread C2 CompilerThread1守护进程[_thread_blocked,id = 10140,堆栈(0x0000000016c00000,0x0000000016d00000)]
0x000000001537d800 JavaThread C2 CompilerThread0守护进程[_thread_block16,stack(0,00,00x16,00 0x0000000016c00000)]
0x000000001537c000 JavaThread Attach Listener守护程序[_thread_blocked,id = 10072,堆栈(0x0000000016a00000,0x0000000016b00000)]
0x000000001537a800 JavaThread Signal Dispatcher守护程序[_thread_blocked,id = 5612,169 0x0000000016a00000)]
0x000000001536a800 JavaThread Finalizer守护程序[_thread_blocked,id = 6568,stack(0x00000000165f0000,0x00000000166f0000)]
0x0000000002d6f000 JavaTh读取引用处理程序守护程序[_thread_blocked,id = 9964,stack(0x00000000164f0000,0x00000000165f0000)]
=> 0x00000000013dd800 JavaThread main [_thread_in_native,id = 7724,stack(0x0000000002b30000,0x0000000002c30000)]
b
其他线程:
0x0000000015346800 VMThread [stack:0x00000000163f0000,0x00000000164f0000] [id = 7392]
0x0000000016e48000 WatcherThread [stack:0x0000000017300000,0x0000000017400000] [id = 9832]

b VM状态:未处于安全点(正常执行)

VM线程当前拥有的Mutex /监视器:无

堆:
PSYoungGen总计18944K,已用983K [0x00000000eb200000,0x00000000ec700000,0x0000000100000000)
伊甸空间16384K,已使用6%[0x00000000eb200000,0x00000000eb2f5c90,0x00000000ec200000)
来自空间2560K,已使用0%[0x00000000ec480000,0x00000000ec60000,0x00000000b $ 600000,000 ,已使用0%[0x00000000ec200000,0x00000000ec200000,0x00000000ec480000)
ParOldGen总计44032K,使用d 0K [0x00000000c1600000,0x00000000c4100000,0x00000000eb200000)
对象空间44032K,已使用0%[0x00000000c1600000,0x00000000c1600000,0x00000000c4100000)
已使用元空间2593K,容量4486K,已提交4864K,已保留1056768K
$ 282K,容量386K,已提交512K,保留1048576K

卡表byte_map:[0x0000000012140000,0x0000000012340000] byte_map_base:0x0000000011b35000

标记位:(ParMarkBitMap *)0x00000000774aa6c0
起始位:[0x0000000012890000,0x0000000013838000)
结束位:[0x0000000013838000,0x00000000147e0000)

轮询页面:0x0000000001210000

CodeCache:size = 245760Kb used = 1104Kb max_used = 1105Kb空闲= 244655Kb
范围[0x0000000002d80000,0x0000000002ff0000,0x0000000011d80000]
total_blobs = 255 nmethods = 24适配器= 145
编译:启用

编译事件(10个事件) :
事件:0.123线程0x000000001538c000 20 s 3 java.lang.S tringBuffer :: append(13个字节)
事件:0.124线程0x0000000015383000 22 4 java.lang.String :: charAt(29个字节)
事件:0.124线程0x000000001538c000 nmethod 20 0x0000000002e90510代码[0x0000000002e906c0,0x0000000002e90dd8]
事件:0.124线程0x000000001538c000 21 3 java.lang.String ::等于(81字节)
事件:0.125线程0x000000001538c000 nmethod 21 0x0000000002e91190代码[0x0000000002e91320,0x0000000002e91870]
事件:0.125线程0x000000001538c000 23 3 java.lang.AbstractStringBuilder :: append(50个字节)
事件:0.125线程0x0000000015383000 nmethod 22 0x0000000002e94710代码[0x0000000002e94860,0x0000000002e94918]
事件:0.126线程0x000000001538c000 nmethod 23 0x0000000002e93ad0代码[0x0000000002 b $ b事件:0.126线程0x000000001538c000 24 3 java.util.Arrays :: copyOfRange(63字节)
事件:0.127线程0x000000001538c000 nmethod 24 0x0000000002e92850代码[0x0000000002e92a60,0x0000000002e93598]

GC堆历史记录(0个事件):
无事件

反优化事件(0个事件):
无事件

内部异常(2个事件):
事件:0.050线程0x00000000013dd800异常< a'java / lang / NoSuchMethodError':方法sun.misc.Unsafe.defineClass(Ljava / lang / String; [BII)Ljava / lang / Class;名称或签名不匹配> (0x00000000eb207c78)在[C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u111\7883\hotspot\
事件中抛出:0.050线程0x00000000013dd800异常< java / lang / NoSuchMethodError:方法sun.misc.Unsafe.prefetchRead(Ljava / lang / Object; J)V名称或签名不匹配> (0x00000000eb207f60)投向[C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u111\7883\hotspot\src\share\vm\prims

事件(10个事件):
事件:0.275加载类java / security / BasicPermissionCollection
事件:0.275加载类java / security / BasicPermissionCollection完成
事件:0.276加载类sun / launcher / LauncherHelper $ FXHelper
事件:0.276加载类sun / launcher / LauncherHelper $ FXHelper完成
事件:0.276加载类java / lang / Class $ MethodArray
事件:0.276加载类java / lang / Class $ MethodArray完成
事件:0.276加载类java / lang / Void
事件:0.276加载类java / lang / Void完成
事件:4.121执行VM操作:EnableBiasedLocking
事件:4.121执行VM操作:EnableBiasedLocking完成


动态库:
0x00007ff6ddee0000-0x00007ff6ddf17000 C:\Program Files\Java\jdk1.8.0_111\ bin\java.exe
0x00007ff84a010000-0x00007ff84a1bc000 C:\Win dows\SYSTEM32\ntdll.dll
0x00007ff849bf0000-0x00007ff849d2e000 C:\Windows\system32\KERNEL32.DLL
0x00007ff8472a0000-0x00007ff8473b5000 C:\Windows\system32\KERNELBASE.dll
0x00007ff845af0000-0x00007ff845b7e000 C:\Windows\system32\apphelp.dll
0x00007ff822700000-0x00007ff822753000 C:\Windows\AppPatch\AppPatch64\AcGenral.DLL
0x00007ff849b40000-0x00007ff849bea000 :\Windows\system32\msvcrt.dll
0x00007ff846f40000-0x00007ff846f6e000 C:\Windows\SYSTEM32\SspiCli.dll
0x00007ff8478a0000-0x00007ff8478f4000 C:\Windows\system32\SHLWAPI .dll
0x00007ff847b00000-0x00007ff847c77000 C:\Windows\system32\USER32.dll
0x00007ff8499a0000-0x00007ff849b34000 C:\Windows\system32\ole32.dll
0x00007ff848020000-0x00007ff849539000 C :\Windows\system32\SHELL32.dll
0x00007ff846710000-0x00007ff846731000 C:\Windows\SYSTEM32\USERENV.dll
0x00007ff849760000-0x00007ff84 980a000 C:\Windows\system32\ADVAPI32.dll
0x00007ff832a20000-0x00007ff832a3e000 C:\Windows\SYSTEM32\MPR.dll
0x00007ff849540000-0x00007ff849681000 C:\Windows\system32\ \RPCRT4.dll
0x00007ff8476b0000-0x00007ff847709000 C:\Windows\SYSTEM32\sechost.dll
0x00007ff849df0000-0x00007ff84a001000 C:\Windows\SYSTEM32\combase.dll
0x00007ff847750000- 0x00007ff8478a0000 C:\Windows\system32\GDI32.dll
0x00007ff847170000-0x00007ff847185000 C:\Windows\SYSTEM32\profapi.dll
0x00007ff845220000-0x00007ff8452d2000 C:\Windows\SYSTEM32\ \SHCORE.dll
0x00007ff847710000-0x00007ff847746000 C:\Windows\system32\IMM32.DLL
0x00007ff849810000-0x00007ff849962000 C:\Windows\system32\MSCTF.dll
0x00007ff8448c0000- 0x00007ff844b3a000 C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9600.17810_none_6240b9c7ecbd0bda\COMCTL32.dll
0x00000000505e0000-0x00 000000506b2000 C:\Program Files\Java\jdk1.8.0_111\jre\bin\msvcr100.dll
0x0000000076c90000-0x000000007752a000 C:\Program Files\Java\jdk1.8.0_111\ \jre\bin\server\jvm.dll
0x00007ff83c9a0000-0x00007ff83c9a9000 C:\Windows\SYSTEM32\WSOCK32.dll
0x00007ff844140000-0x00007ff844162000 C:\Windows\SYSTEM32\ WINMM.dll
0x00007ff83fad0000-0x00007ff83fada000 C:\Windows\SYSTEM32\VERSION.dll
0x00007ff847900000-0x00007ff847907000 C:\Windows\system32\PSAPI.DLL
0x00007ff847a40000-0x00007ff847a9a C:\Windows\system32\WS2_32.dll
0x00007ff843cf0000-0x00007ff843d1a000 C:\Windows\SYSTEM32\WINMMBASE.dll
0x00007ff847c80000-0x00007ff847c89000 C:\Windows\system32\ NSI.dll
0x00007ff8475a0000-0x00007ff8475ef000 C:\Windows\SYSTEM32\cfgmgr32.dll
0x00007ff845f60000-0x00007ff845f88000 C:\Windows\SYSTEM32\DEVOBJ.dll
0x0000000050950000-0x000000005095000 C:\专业gram Files\Java\jdk1.8.0_111\jre\bin\verify.dll
0x0000000050570000-0x0000000050599000 C:\Program Files\Java\jdk1.8.0_111\jre\bin \java.dll
0x0000000050550000-0x0000000050566000 C:\程序文件\Java\jdk1.8.0_111\jre\bin\zip.dll
0x00000004a4640000-0x00000004a465a000 C:\用户\Nicholas1\文档\NetBeansProjects\DemoJNI_Lib\dist\DemoJNI_Lib.dll
0x0000000180040000-0x0000000180610000 C:\cygwin64\bin\cygwin1.dll
0x00007ff83ca70000-0x00007ff83cbf9000 C:\ \Windows\SYSTEM32\dbghelp.dll

VM参数:
jvm_args:-Dfile.encoding = UTF-8 -Djava.library.path = C:\Users\Nicholas1 \文档\NetBeansProjects\DemoJNI_Lib\dist\
java_command:demojni.Main
java_class_path(initial):C:\Users\Nicholas1\文档\NetBeansProjects\DemoJNI_Lib\ \dist; C:\Users\Nicholas1\Documents\NetBeansProjects\DemoJNI\build\classes
启动程序类型:SUN_STANDARD

环境变量:
J AVA_HOME = C:\Program Files\Java\jdk1.8.0_111
PATH = C:\ProgramData\Oracle\Java\javapath; C:\Program Files(x86)\SN系统\PS3\bin; C:\Program Files\Dell\DW WLAN卡; c:\Program Files(x86)\Intel\iCLS Client\c:\Program Files\ Intel\iCLS客户端\; C:\Windows\system32; C:\Windows; C:\Windows\System32\Wbem; C:\Windows\System32\WindowsPowerShell\v1。 0\; C:\程序文件\英特尔\英特尔(R)管理引擎组件\DAL; C:\程序文件\英特尔\英特尔®Intel®管理引擎组件\IPT; C: \程序文件(x86)\英特尔\英特尔(R)管理引擎组件\DAL; C:\程序文件(x86)\英特尔\英特尔(R)管理引擎组件\IPT; c: \程序文件\WIDCOMM\蓝牙软件\; c:\程序文件\WIDCOMM\蓝牙软件\syswow64; C:\程序文件(x86)\Skype\Phone\%M2_HOME %\bin; C:\程序文件(x86)\GtkSharp\2.12\bin; C:\程序文件(x86)\Skype\Phone\; C:\程序文件(x86 )\公用文件\Ulead Systems\MPEG; C:\程序文件\MySQL\MySQ L实用程序1.6\; C:\程序文件(x86)\QuickTime\QTSystem\; C:\程序文件(x86)\nodejs\; C:\cygwin64\bin; C: \程序文件\Java\jdk1.8.0_111\bin; C:\用户\Nicholas1\AppData\漫游\npm; C:\程序文件(x86)\FAHClient
USERNAME = Nicholas1
OS = Windows_NT
PROCESSOR_IDENTIFIER = Intel64 Family 6 Model 69 Steping 1,GenuineIntel



-------- -------系统---------------

操作系统:Windows 8.1,64 bit Build 9600(6.3.9600.17415)

CPU:总共4个(每个cpu 2个内核,每个内核2个线程)6类模型69步进1,cmov,cx8,fxsr,mmx,sse,sse2,sse3,ssse3,sse4.1,sse4.2,popcnt ,avx,avx2,aes,clmul,erms,lzcnt,ht,tsc,tscinvbit,bmi1,bmi2

内存:4k页面,物理4096180k(免费828828k),交换9339060k(免费3424740k)

vm_info:适用于Windows-amd64 JRE(1.8.0_111-b14)的Java HotSpot(TM)64位服务器VM(25.111-b14),由 java_re构建于2016年9月22日使用MS VC ++ 10.0(VS2010)

tim e:Sun Apr 09 21:29:25 2017
经过的时间:27秒(0d 0h 0m 27s)

以下是我进行编译,链接和运行的步骤:



创建/编译头文件:

  1。在 C:\Users\Nicholas1\Documents\NetBeansProjects中打开cmd提示符。
2.运行 javah –o DemoJNI_Lib / DemoJNI_Lib.h –classpath DemoJNI / src demojni.Main,其中;
- DemoJNI_Lib是您的C ++动态库项目。
-C类文件的Java / C标头中的DemoJNI_Lib.h声明。
-DemoJNI是带有src文件夹的Java项目的名称。
-demojni是您的Java项目包名称
-Main是您的主要Java文件。

C / C ++项目的构建/链接器选项:

  1。右键单击DemoJNI_Lib项目,然后选择属性。转到Build / C编译器,然后在常规/包含目录下查看并单击目录按钮(…),然后选择添加按钮。现在,从 C:\Program Files\Java\jdk1.8.0_111\include中选择include文件夹,然后选择添加按钮,并从 C:\Program Files\Java\jdk1中选择win32文件夹。 .8.0_111\include / win32,最后选择确定按钮。 
2.右键单击DemoJNI_Lib项目,然后选择属性。转到Build / C-Compiler,找到命令行 /其他选项,然后键入 -shared –m32
3.右键单击DemoJNI_Lib项目,然后选择属性 Build / Linker,找到常规 /输出,然后键入dist / DemoJNI_Lib.dll
4.可选:添加typedef long long __int64;或#define __int64 long到DemoJNI_Lib.h文件的顶部。应该高于#include< jni.h>。
5.生成.dll库文件:在Netbeans中找到带有c文件和头文件的C / C ++项目,然后找到Project->(右键单击)-> Clean and Build。

正在运行的Java文件:

  1。在Netbeans Select DemoJNI Java项目中,Main.java->(右键单击)->运行


解决方案

尚未找到Cygwin C / C ++编译器对崩溃错误的确切解决方案,但是该错误的替代解决方案是使用Microsoft Visual Studios C / C ++编译器。 / p>

以下是使用Microsoft Visual Studios C / C ++编译器的JNI解决方案的链接: https://www.youtube.com/watch?v=tDhOPYi-rYE&spfreload=1



注意:如果使用Microsoft Visual Studio C / C ++编译器进行JNI开发,则




  • 对于32位dll使用 vsvars32.bat,位于 C:\程序文件(x86)\ Microsoft Visual Studio 14.0\Common7\Tools。


  • 对于我的安装程序,我需要一个64位dll文件,因此我使用在 C:\Program Files(x86)\Microsoft Visual Studio 14.0\VC\bin\am中找到的 vcvars64.bat d64



This error appears when I try to load a JNI C/C++ dll library, and I noticed it says "The crash happened outside the Java Virtual Machine in native code." Not sure what that means? Any help will be greatly appreciated!

Java-Source code follows:

package demojni;
public class Main {
   static {
      System.load("C:\\Users\\Nicholas1\\Documents\\NetBeansProjects\\DemoJNI_Lib\\dist\\DemoJNI_Lib.dll"); // Load native library at runtime
                                   // hello.dll (Windows) or libhello.so (Unixes)
   }

   // Declare a native method sayHello() that receives nothing and returns void


   // Test Driver
   public static void main(String[] args) {
      new Main().sayHelloWorld();  // invoke the native method
   }
   private native void sayHelloWorld();
}

C-Source code follows:

#include "DemoJNI_Lib.h"
#include <stdio.h>

JNIEXPORT void JNICALL Java_demojni_Main_sayHelloWorld
  (JNIEnv * env, jobject obj){
    printf("Hello World \n");
}

JNI C-header-Source code follows:

/* DO NOT EDIT THIS FILE - it is machine generated */
#include <jni.h>
/* Header for class demojni_Main */

#ifndef _Included_demojni_Main
#define _Included_demojni_Main
#ifdef __cplusplus
extern "C" {
#endif
/*
 * Class:     demojni_Main
 * Method:    sayHelloWorld
 * Signature: ()V
 */
JNIEXPORT void JNICALL Java_demojni_Main_sayHelloWorld
  (JNIEnv *, jobject);

#ifdef __cplusplus
}
#endif
#endif

Error when I run Main.java file:

# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000002c2ed90, pid=7552, tid=0x0000000000001e2c
#
# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  0x0000000002c2ed90
#
# Failed to write core dump. Minidumps are not enabled by default on client versions of Windows
#
# An error report file with more information is saved as:
# C:\Users\Nicholas1\Documents\NetBeansProjects\DemoJNI\hs_err_pid7552.log
#
# If you would like to submit a bug report, please visit:
#   http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
C:\Users\Nicholas1\AppData\Local\NetBeans\Cache\8.2\executor-snippets\run.xml:53: Java returned: 1
BUILD FAILED (total time: 27 seconds)

Error Log (hs_err_pid7552.log):

#
# A fatal error has been detected by the Java Runtime Environment:
#
#  EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x0000000002c2ed90, pid=7552, tid=0x0000000000001e2c
#
# JRE version: Java(TM) SE Runtime Environment (8.0_111-b14) (build 1.8.0_111-b14)
# Java VM: Java HotSpot(TM) 64-Bit Server VM (25.111-b14 mixed mode windows-amd64 compressed oops)
# Problematic frame:
# C  0x0000000002c2ed90
#
# 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.java.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 (0x00000000013dd800):  JavaThread "main" [_thread_in_native, id=7724, stack(0x0000000002b30000,0x0000000002c30000)]

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

Registers:
RAX=0x000000000000000a, RBX=0x0000000014de0360, RCX=0x00000001802e4ae0, RDX=0x0000000000000000
RSP=0x0000000002c2f140, RBP=0x0000000002c2f160, RSI=0x0000000020200021, RDI=0x00000000ffffffff
R8 =0x0000000002c2f0dc, R9 =0x000000018013c900, R10=0x0000000002c30000, R11=0x0000000002c2ed90
R12=0x0000000000000000, R13=0x0000000014de0360, R14=0x0000000002c2f1f8, R15=0x00000000013dd800
RIP=0x0000000002c2ed90, EFLAGS=0x0000000000010247

Top of Stack: (sp=0x0000000002c2f140)
0x0000000002c2f140:   0000000002c2f400 00000000013dd800
0x0000000002c2f150:   0000000014de0360 0000000020200021
0x0000000002c2f160:   0000000002c2f1d8 0000000002d97f74
0x0000000002c2f170:   00000000013dd9f8 0000000002c2f1f8
0x0000000002c2f180:   0000000020200021 00000000013dd800
0x0000000002c2f190:   0000000002d97ca2 0000000002c2f198
0x0000000002c2f1a0:   0000000014de0360 0000000002c2f1f8
0x0000000002c2f1b0:   0000000014de0460 0000000000000000
0x0000000002c2f1c0:   0000000014de0360 0000000000000000
0x0000000002c2f1d0:   0000000002c2f1f8 0000000002c2f240
0x0000000002c2f1e0:   0000000002d8835d 0000000000000000
0x0000000002c2f1f0:   0000000002d919d8 00000000eb26c8f8
0x0000000002c2f200:   0000000002c2f200 0000000014de02bf
0x0000000002c2f210:   0000000002c2f250 0000000014de0460
0x0000000002c2f220:   0000000000000000 0000000014de02d8
0x0000000002c2f230:   0000000002c2f1f8 0000000002c2f250 

Instructions: (pc=0x0000000002c2ed90)
0x0000000002c2ed70:   1e 00 1f 00 00 00 00 00 1d fc 1e 80 01 00 00 00
0x0000000002c2ed80:   00 00 00 00 00 00 00 00 cb 17 2a 47 f8 7f 00 00
0x0000000002c2ed90:   00 d8 3d 01 00 00 00 00 f8 f1 c2 02 00 00 00 00
0x0000000002c2eda0:   60 03 de 14 00 00 00 00 00 00 00 00 00 00 00 00 


Register to memory mapping:

RAX=0x000000000000000a is an unknown value
RBX={method} {0x0000000014de0368} 'sayHelloWorld' '()V' in 'demojni/Main'
RCX=0x00000001802e4ae0 is an unknown value
RDX=0x0000000000000000 is an unknown value
RSP=0x0000000002c2f140 is pointing into the stack for thread: 0x00000000013dd800
RBP=0x0000000002c2f160 is pointing into the stack for thread: 0x00000000013dd800
RSI=0x0000000020200021 is an unknown value
RDI=0x00000000ffffffff is an unallocated location in the heap
R8 =0x0000000002c2f0dc is pointing into the stack for thread: 0x00000000013dd800
R9 =0x000000018013c900 is an unknown value
R10=0x0000000002c30000 is pointing into the stack for thread: 0x00000000013dd800
R11=0x0000000002c2ed90 is pointing into the stack for thread: 0x00000000013dd800
R12=0x0000000000000000 is an unknown value
R13={method} {0x0000000014de0368} 'sayHelloWorld' '()V' in 'demojni/Main'
R14=0x0000000002c2f1f8 is pointing into the stack for thread: 0x00000000013dd800
R15=0x00000000013dd800 is a thread


Stack: [0x0000000002b30000,0x0000000002c30000],  sp=0x0000000002c2f140,  free space=1020k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  0x0000000002c2ed90

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  demojni.Main.sayHelloWorld()V+0
j  demojni.Main.main([Ljava/lang/String;)V+7
v  ~StubRoutines::call_stub

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

Java Threads: ( => current thread )
  0x00000000153de000 JavaThread "Service Thread" daemon [_thread_blocked, id=6960, stack(0x0000000017200000,0x0000000017300000)]
  0x000000001538c000 JavaThread "C1 CompilerThread2" daemon [_thread_blocked, id=5380, stack(0x0000000016d00000,0x0000000016e00000)]
  0x0000000015383000 JavaThread "C2 CompilerThread1" daemon [_thread_blocked, id=10140, stack(0x0000000016c00000,0x0000000016d00000)]
  0x000000001537d800 JavaThread "C2 CompilerThread0" daemon [_thread_blocked, id=6316, stack(0x0000000016b00000,0x0000000016c00000)]
  0x000000001537c000 JavaThread "Attach Listener" daemon [_thread_blocked, id=10072, stack(0x0000000016a00000,0x0000000016b00000)]
  0x000000001537a800 JavaThread "Signal Dispatcher" daemon [_thread_blocked, id=5612, stack(0x0000000016900000,0x0000000016a00000)]
  0x000000001536a800 JavaThread "Finalizer" daemon [_thread_blocked, id=6568, stack(0x00000000165f0000,0x00000000166f0000)]
  0x0000000002d6f000 JavaThread "Reference Handler" daemon [_thread_blocked, id=9964, stack(0x00000000164f0000,0x00000000165f0000)]
=>0x00000000013dd800 JavaThread "main" [_thread_in_native, id=7724, stack(0x0000000002b30000,0x0000000002c30000)]

Other Threads:
  0x0000000015346800 VMThread [stack: 0x00000000163f0000,0x00000000164f0000] [id=7392]
  0x0000000016e48000 WatcherThread [stack: 0x0000000017300000,0x0000000017400000] [id=9832]

VM state:not at safepoint (normal execution)

VM Mutex/Monitor currently owned by a thread: None

Heap:
 PSYoungGen      total 18944K, used 983K [0x00000000eb200000, 0x00000000ec700000, 0x0000000100000000)
  eden space 16384K, 6% used [0x00000000eb200000,0x00000000eb2f5c90,0x00000000ec200000)
  from space 2560K, 0% used [0x00000000ec480000,0x00000000ec480000,0x00000000ec700000)
  to   space 2560K, 0% used [0x00000000ec200000,0x00000000ec200000,0x00000000ec480000)
 ParOldGen       total 44032K, used 0K [0x00000000c1600000, 0x00000000c4100000, 0x00000000eb200000)
  object space 44032K, 0% used [0x00000000c1600000,0x00000000c1600000,0x00000000c4100000)
 Metaspace       used 2593K, capacity 4486K, committed 4864K, reserved 1056768K
  class space    used 282K, capacity 386K, committed 512K, reserved 1048576K

Card table byte_map: [0x0000000012140000,0x0000000012340000] byte_map_base: 0x0000000011b35000

Marking Bits: (ParMarkBitMap*) 0x00000000774aa6c0
 Begin Bits: [0x0000000012890000, 0x0000000013838000)
 End Bits:   [0x0000000013838000, 0x00000000147e0000)

Polling page: 0x0000000001210000

CodeCache: size=245760Kb used=1104Kb max_used=1105Kb free=244655Kb
 bounds [0x0000000002d80000, 0x0000000002ff0000, 0x0000000011d80000]
 total_blobs=255 nmethods=24 adapters=145
 compilation: enabled

Compilation events (10 events):
Event: 0.123 Thread 0x000000001538c000   20  s    3       java.lang.StringBuffer::append (13 bytes)
Event: 0.124 Thread 0x0000000015383000   22       4       java.lang.String::charAt (29 bytes)
Event: 0.124 Thread 0x000000001538c000 nmethod 20 0x0000000002e90510 code [0x0000000002e906c0, 0x0000000002e90dd8]
Event: 0.124 Thread 0x000000001538c000   21       3       java.lang.String::equals (81 bytes)
Event: 0.125 Thread 0x000000001538c000 nmethod 21 0x0000000002e91190 code [0x0000000002e91320, 0x0000000002e91870]
Event: 0.125 Thread 0x000000001538c000   23       3       java.lang.AbstractStringBuilder::append (50 bytes)
Event: 0.125 Thread 0x0000000015383000 nmethod 22 0x0000000002e94710 code [0x0000000002e94860, 0x0000000002e94918]
Event: 0.126 Thread 0x000000001538c000 nmethod 23 0x0000000002e93ad0 code [0x0000000002e93ca0, 0x0000000002e943f8]
Event: 0.126 Thread 0x000000001538c000   24       3       java.util.Arrays::copyOfRange (63 bytes)
Event: 0.127 Thread 0x000000001538c000 nmethod 24 0x0000000002e92850 code [0x0000000002e92a60, 0x0000000002e93598]

GC Heap History (0 events):
No events

Deoptimization events (0 events):
No events

Internal exceptions (2 events):
Event: 0.050 Thread 0x00000000013dd800 Exception <a 'java/lang/NoSuchMethodError': Method sun.misc.Unsafe.defineClass(Ljava/lang/String;[BII)Ljava/lang/Class; name or signature does not match> (0x00000000eb207c78) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u111\7883\hotspot\
Event: 0.050 Thread 0x00000000013dd800 Exception <a 'java/lang/NoSuchMethodError': Method sun.misc.Unsafe.prefetchRead(Ljava/lang/Object;J)V name or signature does not match> (0x00000000eb207f60) thrown at [C:\re\workspace\8-2-build-windows-amd64-cygwin\jdk8u111\7883\hotspot\src\share\vm\prims

Events (10 events):
Event: 0.275 loading class java/security/BasicPermissionCollection
Event: 0.275 loading class java/security/BasicPermissionCollection done
Event: 0.276 loading class sun/launcher/LauncherHelper$FXHelper
Event: 0.276 loading class sun/launcher/LauncherHelper$FXHelper done
Event: 0.276 loading class java/lang/Class$MethodArray
Event: 0.276 loading class java/lang/Class$MethodArray done
Event: 0.276 loading class java/lang/Void
Event: 0.276 loading class java/lang/Void done
Event: 4.121 Executing VM operation: EnableBiasedLocking
Event: 4.121 Executing VM operation: EnableBiasedLocking done


Dynamic libraries:
0x00007ff6ddee0000 - 0x00007ff6ddf17000     C:\Program Files\Java\jdk1.8.0_111\bin\java.exe
0x00007ff84a010000 - 0x00007ff84a1bc000     C:\Windows\SYSTEM32\ntdll.dll
0x00007ff849bf0000 - 0x00007ff849d2e000     C:\Windows\system32\KERNEL32.DLL
0x00007ff8472a0000 - 0x00007ff8473b5000     C:\Windows\system32\KERNELBASE.dll
0x00007ff845af0000 - 0x00007ff845b7e000     C:\Windows\system32\apphelp.dll
0x00007ff822700000 - 0x00007ff822753000     C:\Windows\AppPatch\AppPatch64\AcGenral.DLL
0x00007ff849b40000 - 0x00007ff849bea000     C:\Windows\system32\msvcrt.dll
0x00007ff846f40000 - 0x00007ff846f6e000     C:\Windows\SYSTEM32\SspiCli.dll
0x00007ff8478a0000 - 0x00007ff8478f4000     C:\Windows\system32\SHLWAPI.dll
0x00007ff847b00000 - 0x00007ff847c77000     C:\Windows\system32\USER32.dll
0x00007ff8499a0000 - 0x00007ff849b34000     C:\Windows\system32\ole32.dll
0x00007ff848020000 - 0x00007ff849539000     C:\Windows\system32\SHELL32.dll
0x00007ff846710000 - 0x00007ff846731000     C:\Windows\SYSTEM32\USERENV.dll
0x00007ff849760000 - 0x00007ff84980a000     C:\Windows\system32\ADVAPI32.dll
0x00007ff832a20000 - 0x00007ff832a3e000     C:\Windows\SYSTEM32\MPR.dll
0x00007ff849540000 - 0x00007ff849681000     C:\Windows\system32\RPCRT4.dll
0x00007ff8476b0000 - 0x00007ff847709000     C:\Windows\SYSTEM32\sechost.dll
0x00007ff849df0000 - 0x00007ff84a001000     C:\Windows\SYSTEM32\combase.dll
0x00007ff847750000 - 0x00007ff8478a0000     C:\Windows\system32\GDI32.dll
0x00007ff847170000 - 0x00007ff847185000     C:\Windows\SYSTEM32\profapi.dll
0x00007ff845220000 - 0x00007ff8452d2000     C:\Windows\SYSTEM32\SHCORE.dll
0x00007ff847710000 - 0x00007ff847746000     C:\Windows\system32\IMM32.DLL
0x00007ff849810000 - 0x00007ff849962000     C:\Windows\system32\MSCTF.dll
0x00007ff8448c0000 - 0x00007ff844b3a000     C:\Windows\WinSxS\amd64_microsoft.windows.common-controls_6595b64144ccf1df_6.0.9600.17810_none_6240b9c7ecbd0bda\COMCTL32.dll
0x00000000505e0000 - 0x00000000506b2000     C:\Program Files\Java\jdk1.8.0_111\jre\bin\msvcr100.dll
0x0000000076c90000 - 0x000000007752a000     C:\Program Files\Java\jdk1.8.0_111\jre\bin\server\jvm.dll
0x00007ff83c9a0000 - 0x00007ff83c9a9000     C:\Windows\SYSTEM32\WSOCK32.dll
0x00007ff844140000 - 0x00007ff844162000     C:\Windows\SYSTEM32\WINMM.dll
0x00007ff83fad0000 - 0x00007ff83fada000     C:\Windows\SYSTEM32\VERSION.dll
0x00007ff847900000 - 0x00007ff847907000     C:\Windows\system32\PSAPI.DLL
0x00007ff847a40000 - 0x00007ff847a9a000     C:\Windows\system32\WS2_32.dll
0x00007ff843cf0000 - 0x00007ff843d1a000     C:\Windows\SYSTEM32\WINMMBASE.dll
0x00007ff847c80000 - 0x00007ff847c89000     C:\Windows\system32\NSI.dll
0x00007ff8475a0000 - 0x00007ff8475ef000     C:\Windows\SYSTEM32\cfgmgr32.dll
0x00007ff845f60000 - 0x00007ff845f88000     C:\Windows\SYSTEM32\DEVOBJ.dll
0x0000000050950000 - 0x000000005095f000     C:\Program Files\Java\jdk1.8.0_111\jre\bin\verify.dll
0x0000000050570000 - 0x0000000050599000     C:\Program Files\Java\jdk1.8.0_111\jre\bin\java.dll
0x0000000050550000 - 0x0000000050566000     C:\Program Files\Java\jdk1.8.0_111\jre\bin\zip.dll
0x00000004a4640000 - 0x00000004a465a000     C:\Users\Nicholas1\Documents\NetBeansProjects\DemoJNI_Lib\dist\DemoJNI_Lib.dll
0x0000000180040000 - 0x0000000180610000     C:\cygwin64\bin\cygwin1.dll
0x00007ff83ca70000 - 0x00007ff83cbf9000     C:\Windows\SYSTEM32\dbghelp.dll

VM Arguments:
jvm_args: -Dfile.encoding=UTF-8 -Djava.library.path=C:\Users\Nicholas1\Documents\NetBeansProjects\DemoJNI_Lib\dist\ 
java_command: demojni.Main
java_class_path (initial): C:\Users\Nicholas1\Documents\NetBeansProjects\DemoJNI_Lib\dist;C:\Users\Nicholas1\Documents\NetBeansProjects\DemoJNI\build\classes
Launcher Type: SUN_STANDARD

Environment Variables:
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_111
PATH=C:\ProgramData\Oracle\Java\javapath;C:\Program Files (x86)\SN Systems\PS3\bin;C:\Program Files\Dell\DW WLAN Card;c:\Program Files (x86)\Intel\iCLS Client\;c:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;c:\Program Files\WIDCOMM\Bluetooth Software\;c:\Program Files\WIDCOMM\Bluetooth Software\syswow64;C:\Program Files (x86)\Skype\Phone\%M2_HOME%\bin;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\Skype\Phone\;C:\Program Files (x86)\Common Files\Ulead Systems\MPEG;C:\Program Files\MySQL\MySQL Utilities 1.6\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files (x86)\nodejs\;C:\cygwin64\bin;C:\Program Files\Java\jdk1.8.0_111\bin;C:\Users\Nicholas1\AppData\Roaming\npm;C:\Program Files (x86)\FAHClient
USERNAME=Nicholas1
OS=Windows_NT
PROCESSOR_IDENTIFIER=Intel64 Family 6 Model 69 Stepping 1, GenuineIntel



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

OS: Windows 8.1 , 64 bit Build 9600 (6.3.9600.17415)

CPU:total 4 (2 cores per cpu, 2 threads per core) family 6 model 69 stepping 1, cmov, cx8, fxsr, mmx, sse, sse2, sse3, ssse3, sse4.1, sse4.2, popcnt, avx, avx2, aes, clmul, erms, lzcnt, ht, tsc, tscinvbit, bmi1, bmi2

Memory: 4k page, physical 4096180k(552828k free), swap 9339060k(3424740k free)

vm_info: Java HotSpot(TM) 64-Bit Server VM (25.111-b14) for windows-amd64 JRE (1.8.0_111-b14), built on Sep 22 2016 19:24:05 by "java_re" with MS VC++ 10.0 (VS2010)

time: Sun Apr 09 21:29:25 2017
elapsed time: 27 seconds (0d 0h 0m 27s)

The Following are my Steps I followed for Compilation, Linking and Running:

Creating/Compilation Header file:

1.  Open cmd prompt in "C:\Users\Nicholas1\Documents\NetBeansProjects"
2.  Run "javah –o DemoJNI_Lib/DemoJNI_Lib.h –classpath DemoJNI/src demojni.Main", where;
-   "DemoJNI_Lib" is your C++ dynamic library project.
-   DemoJNI_Lib.h declaration for your Java/C header for the C-class file.
-   DemoJNI is the name of your java project with src folder.
-   demojni is your java project package name
-   Main is your main java file.

Build/Linker options for C/C++ Project:

1.  Right-click on DemoJNI_Lib project and select properties. Go to Build/C Compiler then look under General/Include Directories and click on directories button(…), then select Add button. Now select the include folder from "C:\Program Files\Java\jdk1.8.0_111\include", then select Add button and select the win32 folder from "C:\Program Files\Java\jdk1.8.0_111\include/win32", finally choose OK-button.
2.  Right-click on DemoJNI_Lib project and select properties. Go to Build/C-Compiler find "Command Line"/"Additional Options", then type "-shared –m32"
3.  Right-click on DemoJNI_Lib project and select properties "Build"/"Linker", find "General"/"Output", then type dist/DemoJNI_Lib.dll
4.  Optional:Add typedef long long __int64; or #define __int64 long long to top of DemoJNI_Lib.h file. Should be above #include <jni.h>.
5.  Build .dll library file: in Netbeans find C/C++ project with c-file and header-file, then Project->(right click)->Clean and Build.

Running Java file:

1.  In Netbeans Select DemoJNI java project, Main.java->(Right-click)->Run

解决方案

Have not figured out the exact solution to the crash error with the Cygwin C/C++ Compiler, But the alternative solution to this error is to use the Microsoft Visual Studios C/C++ Compiler.

Here's a link to a JNI solution that uses the Microsoft Visual Studios C/C++ Compiler: https://www.youtube.com/watch?v=tDhOPYi-rYE&spfreload=1

Note: If you use Microsoft Visual Studios C/C++ Compiler for JNI development,

  • For a 32-bit dll use "vsvars32.bat" found at "C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\Tools".

  • For my setup I needed a 64-bit dll file so I used "vcvars64.bat" found at "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64"

这篇关于Java运行时环境-.EXCEPTION_ACCESS_VIOLATION检测到致命错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆