hotspot/src/share/vm/prims/whitebox.cpp
changeset 26844 80398753ed99
parent 26183 bbe259d3c8bc
child 26846 7d4376f8560e
equal deleted inserted replaced
26843:1220c9e50fff 26844:80398753ed99
   711 WB_END
   711 WB_END
   712 
   712 
   713 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
   713 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o))
   714   Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
   714   Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true);
   715   Universe::heap()->collect(GCCause::_last_ditch_collection);
   715   Universe::heap()->collect(GCCause::_last_ditch_collection);
       
   716 #if INCLUDE_ALL_GCS
       
   717   if (UseG1GC) {
       
   718     // Needs to be cleared explicitly for G1
       
   719     Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(false);
       
   720   }
       
   721 #endif // INCLUDE_ALL_GCS
   716 WB_END
   722 WB_END
   717 
   723 
   718 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o))
   724 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o))
   719   Universe::heap()->collect(GCCause::_wb_young_gc);
   725   Universe::heap()->collect(GCCause::_wb_young_gc);
   720 WB_END
   726 WB_END
   862       offset_for_field(field_name, object, vmSymbols::bool_signature());
   868       offset_for_field(field_name, object, vmSymbols::bool_signature());
   863   bool ret = (object->bool_field(offset) == JNI_TRUE);
   869   bool ret = (object->bool_field(offset) == JNI_TRUE);
   864   return ret;
   870   return ret;
   865 }
   871 }
   866 
   872 
       
   873 void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) {
       
   874   ResourceMark rm;
       
   875   ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
       
   876 
       
   877   //  one by one registration natives for exception catching
       
   878   jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
       
   879   CHECK_JNI_EXCEPTION(env);
       
   880   for (int i = 0, n = method_count; i < n; ++i) {
       
   881     // Skip dummy entries
       
   882     if (method_array[i].fnPtr == NULL) continue;
       
   883     if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) {
       
   884       jthrowable throwable_obj = env->ExceptionOccurred();
       
   885       if (throwable_obj != NULL) {
       
   886         env->ExceptionClear();
       
   887         if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) {
       
   888           // NoSuchMethodError is thrown when a method can't be found or a method is not native.
       
   889           // Ignoring the exception since it is not preventing use of other WhiteBox methods.
       
   890           tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s",
       
   891               method_array[i].name, method_array[i].signature);
       
   892         }
       
   893       } else {
       
   894         // Registration failed unexpectedly.
       
   895         tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered",
       
   896             method_array[i].name, method_array[i].signature);
       
   897         env->UnregisterNatives(wbclass);
       
   898         break;
       
   899       }
       
   900     }
       
   901   }
       
   902 }
   867 
   903 
   868 #define CC (char*)
   904 #define CC (char*)
   869 
   905 
   870 static JNINativeMethod methods[] = {
   906 static JNINativeMethod methods[] = {
   871   {CC"getObjectAddress",   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
   907   {CC"getObjectAddress",   CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress  },
   969     if (WhiteBoxAPI) {
  1005     if (WhiteBoxAPI) {
   970       // Make sure that wbclass is loaded by the null classloader
  1006       // Make sure that wbclass is loaded by the null classloader
   971       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
  1007       instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass());
   972       Handle loader(ikh->class_loader());
  1008       Handle loader(ikh->class_loader());
   973       if (loader.is_null()) {
  1009       if (loader.is_null()) {
   974         ResourceMark rm;
  1010         WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0]));
   975         ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI
  1011         WhiteBox::register_extended(env, wbclass, thread);
   976         bool result = true;
  1012         WhiteBox::set_used();
   977         //  one by one registration natives for exception catching
       
   978         jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string());
       
   979         CHECK_JNI_EXCEPTION(env);
       
   980         for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) {
       
   981           if (env->RegisterNatives(wbclass, methods + i, 1) != 0) {
       
   982             result = false;
       
   983             jthrowable throwable_obj = env->ExceptionOccurred();
       
   984             if (throwable_obj != NULL) {
       
   985               env->ExceptionClear();
       
   986               if (env->IsInstanceOf(throwable_obj, exceptionKlass)) {
       
   987                 // j.l.NoSuchMethodError is thrown when a method can't be found or a method is not native
       
   988                 // ignoring the exception
       
   989                 tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", methods[i].name, methods[i].signature);
       
   990               }
       
   991             } else {
       
   992               // register is failed w/o exception or w/ unexpected exception
       
   993               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);
       
   994               env->UnregisterNatives(wbclass);
       
   995               break;
       
   996             }
       
   997           }
       
   998         }
       
   999 
       
  1000         if (result) {
       
  1001           WhiteBox::set_used();
       
  1002         }
       
  1003       }
  1013       }
  1004     }
  1014     }
  1005   }
  1015   }
  1006 JVM_END
  1016 JVM_END