src/share/vm/prims/whitebox.cpp

Print this page

        

@@ -432,12 +432,29 @@
       // Make sure that wbclass is loaded by the null classloader
       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
       Handle loader(ikh->class_loader());
       if (loader.is_null()) {
         ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
-        jint result = env->RegisterNatives(wbclass, methods, sizeof(methods)/sizeof(methods[0]));
-        if (result == 0) {
+        bool result = true;
+        //  one by one registration natives for exception catching
+        for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) {
+          if (env->RegisterNatives(wbclass, methods + i, 1) != 0) {
+            result &= false;
+            if (env->ExceptionCheck()) {
+              tty->print_cr("Warning: exception on register of sun.hotspot.WhiteBox::%s%s", methods[i].name, methods[i].signature);
+              env->ExceptionClear();
+              result &= false;
+            } else {
+              // register is failed w/o exception
+              env->UnregisterNatives(wbclass);
+              result &= false;
+              break;
+            }
+          }
+        }
+
+        if (result) {
           WhiteBox::set_used();
         }
       }
     }
   }