src/share/vm/prims/whitebox.cpp

Print this page
rev 6629 : 8057752: WhiteBox extension support for testing
Summary: Refactored parts of whitebox.cpp to enable registration of whitebox methods defined outside this file.
Reviewed-by:
rev 6630 : [mq]: 8057752-wb-testing-review

*** 847,872 **** void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) { ResourceMark rm; ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI bool result = true; // one by one registration natives for exception catching ! jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); CHECK_JNI_EXCEPTION(env); for (int i = 0, n = method_count; i < n; ++i) { if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) { result = false; jthrowable throwable_obj = env->ExceptionOccurred(); if (throwable_obj != NULL) { env->ExceptionClear(); ! if (env->IsInstanceOf(throwable_obj, exceptionKlass)) { ! // j.l.NoSuchMethodError is thrown when a method can't be found or a method is not native ! // ignoring the exception tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", method_array[i].name, method_array[i].signature); } } else { ! // register is failed w/o exception or w/ unexpected exception tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered", method_array[i].name, method_array[i].signature); env->UnregisterNatives(wbclass); break; } --- 847,874 ---- void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) { ResourceMark rm; ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI bool result = true; // one by one registration natives for exception catching ! jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); CHECK_JNI_EXCEPTION(env); for (int i = 0, n = method_count; i < n; ++i) { + // Skip dummy entries + if (method_array[i].fnPtr == NULL) continue; if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) { result = false; jthrowable throwable_obj = env->ExceptionOccurred(); if (throwable_obj != NULL) { env->ExceptionClear(); ! if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) { ! // NoSuchMethodError is thrown when a method can't be found or a method is not native. ! // Ignoring the exception since it is not preventing use of other WhiteBox methods. tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", method_array[i].name, method_array[i].signature); } } else { ! // Registration failed unexpectedly. tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered", method_array[i].name, method_array[i].signature); env->UnregisterNatives(wbclass); break; }