Exception 0xC0000005 from JNI_CreateJavaVM (jvm.dll)

I initialize the Java VM with the following C ++ code. JNI_CreateJavaVM throws an exception 0xC0000005 , but still succeeds if I ignore it.

'Jni.exe' (Win32): Loaded 'C: \ Tools \ Java \ Jdk8.77x86 \ jre \ bin \ zip.dll'. Cannot find or open the PDB file.

An exception was thrown at 0x02900282 in Jni.exe: 0xC0000005: read access violation location 0x00000000.

'Jni.exe' (Win32): loaded 'C: \ Windows \ SysWOW64 \ shell32.dll'. Cannot find or open the PDB file.

Am I forgetting to install or do something, or is this "normal" behavior?

 #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(); } } 

This happens for both Release and Debug, and for building x86 and x64.

+7
source share
2 answers

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

  • for implicit null pointer checks and checks;
  • for safe polling;
  • for remote memory barriers;
  • and etc.

SEGV (or exception 0xC0000005) is also generated intentionally when starting the JVM to test some CPU / OS functions. Some operating systems or hypervisors had an error that the AVX registers are not restored after signal processing. Therefore, the JVM needs to check if this matters (source) . Thus, it throws an exception by writing a null address and then handles it.

This is what happens in your case. And yes, that's fine.

+10
source

This is normal, as @apangin said. If you want to disable all 0xC0000005 exceptions in VisualStudio (2017), you can do this:

  1. Exception Settings - Ctrl + Alt + E
  2. Uncheck: "0xc0000005 Access Violation" in Win32 Exceptions
0
source

All Articles