来自 JNI_CreateJavaVM (jvm.dll) 的异常 0xC0000005 [英] Exception 0xC0000005 from JNI_CreateJavaVM (jvm.dll)

查看:58
本文介绍了来自 JNI_CreateJavaVM (jvm.dll) 的异常 0xC0000005的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下 C++ 代码初始化 Java VM.JNI_CreateJavaVM 抛出一个 0xC0000005 异常,但如果我忽略它,它仍然会成功.

I am initializing the Java VM using the following C++ code. JNI_CreateJavaVM throws a 0xC0000005 exception but succeeds none the less if I ignore it.

'Jni.exe' (Win32):加载'C:ToolsJavaJdk8.77x86jreinzip.dll'.无法找到或打开 PDB 文件.

'Jni.exe' (Win32): Loaded 'C:ToolsJavaJdk8.77x86jreinzip.dll'. Cannot find or open the PDB file.

Jni.exe 中 0x02900282 处抛出异常:0xC0000005:访问冲突读取位置 0x00000000.

Exception thrown at 0x02900282 in Jni.exe: 0xC0000005: Access violation reading location 0x00000000.

'Jni.exe' (Win32): 加载 'C:WindowsSysWOW64shell32.dll'.无法找到或打开 PDB 文件.

'Jni.exe' (Win32): Loaded 'C:WindowsSysWOW64shell32.dll'. Cannot find or open the PDB file.

我是忘记设置或做某事还是这是正常"行为?

Am I forgetting to set or do something or is this 'normal' behaviour?

#include <array>
#include "jni.h"

int main( int argc, char const* args[])
{
    JavaVM* jvm;
    JNIEnv* env;
    
    std::array<JavaVMOption,1> options;
    options[0].optionString = "-Djava.class.path=C:/Users/Thomas/Documents/Visual Studio 2015/Projects/Jni/x64/Debug";
    options[0].extraInfo = nullptr;

    JavaVMInitArgs vm_args;
    vm_args.version = JNI_VERSION_1_8;
    vm_args.options = options.data();
    vm_args.nOptions = options.size();
    vm_args.ignoreUnrecognized = false;

    auto rc = JNI_CreateJavaVM( &jvm, reinterpret_cast<void**>(&env), &vm_args );
    if( rc == JNI_OK )
    {
        jvm->DestroyJavaVM();        
    }
}

这对于发布和调试以及 x86 和 x64 版本都会发生.

This happens for both Release and Debug and for both x86 and x64 builds.

推荐答案

JVM 出于自身目的积极使用操作系统信号(或 Windows 术语中的异常):

JVM actively uses OS signals (or exceptions in Windows terminology) for its own purposes:

  • 用于隐式空指针检查和堆栈溢出检查;
  • 用于安全点轮询;
  • 用于远程内存屏障;

SEGV(或异常 0xC0000005)也在 JVM 启动时有意生成,以验证某些 CPU/OS 功能.一些操作系统或管理程序存在一个错误,即信号处理后 AVX 寄存器未恢复.所以JVM需要检查是否是这种情况(来源).所以它通过写入零地址产生一个异常然后处理它.

SEGV (or exception 0xC0000005) is also generated intentionally on JVM startup to verify certain CPU/OS features. Some OSes or hypervisors had a bug that AVX registers are not restored after signal processing. Therefore, JVM needs to check whether this is the case (the source). So it generates an exception by writing to zero address and then handles it.

这就是你的情况.是的,这是正常的.

This is what happens in your case. And yes, it is normal.

这篇关于来自 JNI_CreateJavaVM (jvm.dll) 的异常 0xC0000005的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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