hotspot/src/share/vm/prims/whitebox.cpp
changeset 17134 d58219af8d68
parent 17083 14000894ef39
parent 17122 6ceb071b96de
child 17322 35c488005999
equal deleted inserted replaced
17120:f64c35530c30 17134:d58219af8d68
   437     if (WhiteBoxAPI) {
   437     if (WhiteBoxAPI) {
   438       // Make sure that wbclass is loaded by the null classloader
   438       // Make sure that wbclass is loaded by the null classloader
   439       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
   439       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
   440       Handle loader(ikh->class_loader());
   440       Handle loader(ikh->class_loader());
   441       if (loader.is_null()) {
   441       if (loader.is_null()) {
       
   442         ResourceMark rm;
   442         ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
   443         ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
   443         jint result = env->RegisterNatives(wbclass, methods, sizeof(methods)/sizeof(methods[0]));
   444         bool result = true;
   444         if (result == 0) {
   445         //  one by one registration natives for exception catching
       
   446         jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
       
   447         for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) {
       
   448           if (env->RegisterNatives(wbclass, methods + i, 1) != 0) {
       
   449             result = false;
       
   450             if (env->ExceptionCheck() && env->IsInstanceOf(env->ExceptionOccurred(), exceptionKlass)) {
       
   451               // j.l.NoSuchMethodError is thrown when a method can't be found or a method is not native
       
   452               // ignoring the exception
       
   453               tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", methods[i].name, methods[i].signature);
       
   454               env->ExceptionClear();
       
   455             } else {
       
   456               // register is failed w/o exception or w/ unexpected exception
       
   457               tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered", methods[i].name, methods[i].signature);
       
   458               env->UnregisterNatives(wbclass);
       
   459               break;
       
   460             }
       
   461           }
       
   462         }
       
   463 
       
   464         if (result) {
   445           WhiteBox::set_used();
   465           WhiteBox::set_used();
   446         }
   466         }
   447       }
   467       }
   448     }
   468     }
   449   }
   469   }