8074860: Structured Exception Catcher missing around CreateJavaVM on Windows
authorstuefe
Fri, 03 Apr 2015 05:55:33 -0400
changeset 30143 7e99f2b4bae5
parent 30142 0ee0d7d0ee80
child 30145 fbacd4d2936c
8074860: Structured Exception Catcher missing around CreateJavaVM on Windows Summary: add __try/__except around JNI_CreateJavaVM Reviewed-by: mgronlun, dcubed
hotspot/src/cpu/x86/vm/vm_version_x86.cpp
hotspot/src/os/windows/vm/os_windows.cpp
hotspot/src/os/windows/vm/os_windows.hpp
hotspot/src/os/windows/vm/os_windows.inline.hpp
hotspot/src/share/vm/prims/jni.cpp
--- a/hotspot/src/cpu/x86/vm/vm_version_x86.cpp	Thu Apr 02 20:51:24 2015 +0000
+++ b/hotspot/src/cpu/x86/vm/vm_version_x86.cpp	Fri Apr 03 05:55:33 2015 -0400
@@ -379,15 +379,6 @@
   };
 };
 
-
-void VM_Version::get_cpu_info_wrapper() {
-  get_cpu_info_stub(&_cpuid_info);
-}
-
-#ifndef CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED
-  #define CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(f) f()
-#endif
-
 void VM_Version::get_processor_features() {
 
   _cpu = 4; // 486 by default
@@ -401,9 +392,7 @@
   if (!Use486InstrsOnly) {
     // Get raw processor info
 
-    // Some platforms (like Win*) need a wrapper around here
-    // in order to properly handle SEGV for YMM registers test.
-    CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(get_cpu_info_wrapper);
+    get_cpu_info_stub(&_cpuid_info);
 
     assert_is_initialized();
     _cpu = extended_cpu_family();
--- a/hotspot/src/os/windows/vm/os_windows.cpp	Thu Apr 02 20:51:24 2015 +0000
+++ b/hotspot/src/os/windows/vm/os_windows.cpp	Fri Apr 03 05:55:33 2015 -0400
@@ -2695,17 +2695,6 @@
 }
 #endif
 
-void os::win32::call_test_func_with_wrapper(void (*funcPtr)(void)) {
-  // Install a win32 structured exception handler around the test
-  // function call so the VM can generate an error dump if needed.
-  __try {
-    (*funcPtr)();
-  } __except(topLevelExceptionFilter(
-                                     (_EXCEPTION_POINTERS*)_exception_info())) {
-    // Nothing to do.
-  }
-}
-
 // Virtual Memory
 
 int os::vm_page_size() { return os::win32::vm_page_size(); }
--- a/hotspot/src/os/windows/vm/os_windows.hpp	Thu Apr 02 20:51:24 2015 +0000
+++ b/hotspot/src/os/windows/vm/os_windows.hpp	Fri Apr 03 05:55:33 2015 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -115,8 +115,6 @@
   static address fast_jni_accessor_wrapper(BasicType);
 #endif
 
-  static void call_test_func_with_wrapper(void (*funcPtr)(void));
-
   // filter function to ignore faults on serializations page
   static LONG WINAPI serialize_fault_filter(struct _EXCEPTION_POINTERS* e);
 };
--- a/hotspot/src/os/windows/vm/os_windows.inline.hpp	Thu Apr 02 20:51:24 2015 +0000
+++ b/hotspot/src/os/windows/vm/os_windows.inline.hpp	Fri Apr 03 05:55:33 2015 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -104,7 +104,4 @@
   win32::exit_process_or_thread(win32::EPT_PROCESS, num);
 }
 
-#define CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(f) \
-        os::win32::call_test_func_with_wrapper(f)
-
 #endif // OS_WINDOWS_VM_OS_WINDOWS_INLINE_HPP
--- a/hotspot/src/share/vm/prims/jni.cpp	Thu Apr 02 20:51:24 2015 +0000
+++ b/hotspot/src/share/vm/prims/jni.cpp	Fri Apr 03 05:55:33 2015 -0400
@@ -84,6 +84,9 @@
 
 static jint CurrentVersion = JNI_VERSION_1_8;
 
+#ifdef _WIN32
+extern LONG WINAPI topLevelExceptionFilter(_EXCEPTION_POINTERS* );
+#endif
 
 // The DT_RETURN_MARK macros create a scoped object to fire the dtrace
 // '-return' probe regardless of the return path is taken out of the function.
@@ -3924,7 +3927,7 @@
 DT_RETURN_MARK_DECL(CreateJavaVM, jint
                     , HOTSPOT_JNI_CREATEJAVAVM_RETURN(_ret_ref));
 
-_JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) {
+static jint JNI_CreateJavaVM_inner(JavaVM **vm, void **penv, void *args) {
   HOTSPOT_JNI_CREATEJAVAVM_ENTRY((void **) vm, penv, args);
 
   jint result = JNI_ERR;
@@ -4001,18 +4004,14 @@
     }
 
 #ifndef PRODUCT
-  #ifndef CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED
-    #define CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(f) f()
-  #endif
-
     // Check if we should compile all classes on bootclasspath
     if (CompileTheWorld) ClassLoader::compile_the_world();
     if (ReplayCompiles) ciReplay::replay(thread);
 
     // Some platforms (like Win*) need a wrapper around these test
     // functions in order to properly handle error conditions.
-    CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(test_error_handler);
-    CALL_TEST_FUNC_WITH_WRAPPER_IF_NEEDED(execute_internal_vm_tests);
+    test_error_handler();
+    execute_internal_vm_tests();
 #endif
 
     // Since this is not a JVM_ENTRY we have to set the thread state manually before leaving.
@@ -4045,8 +4044,23 @@
   }
 
   return result;
+
 }
 
+_JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_CreateJavaVM(JavaVM **vm, void **penv, void *args) {
+  jint result = 0;
+  // On Windows, let CreateJavaVM run with SEH protection
+#ifdef _WIN32
+  __try {
+#endif
+    result = JNI_CreateJavaVM_inner(vm, penv, args);
+#ifdef _WIN32
+  } __except(topLevelExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) {
+    // Nothing to do.
+  }
+#endif
+  return result;
+}
 
 _JNI_IMPORT_OR_EXPORT_ jint JNICALL JNI_GetCreatedJavaVMs(JavaVM **vm_buf, jsize bufLen, jsize *numVMs) {
   // See bug 4367188, the wrapper can sometimes cause VM crashes