Mercurial > hg > truffle
comparison src/share/vm/prims/whitebox.cpp @ 20451:e2452c3ff7fb
8057752: WhiteBox extension support for testing
Summary: Refactored parts of whitebox.cpp to enable registration of whitebox methods defined outside this file.
Reviewed-by: mikael, ctornqvi, jmasa
author | sjohanss |
---|---|
date | Mon, 08 Sep 2014 15:24:10 +0200 |
parents | 833b0f92429a |
children | 7301840ea20e |
comparison
equal
deleted
inserted
replaced
20450:fa6c442c59ee | 20451:e2452c3ff7fb |
---|---|
693 WB_END | 693 WB_END |
694 | 694 |
695 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) | 695 WB_ENTRY(void, WB_FullGC(JNIEnv* env, jobject o)) |
696 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true); | 696 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(true); |
697 Universe::heap()->collect(GCCause::_last_ditch_collection); | 697 Universe::heap()->collect(GCCause::_last_ditch_collection); |
698 #if INCLUDE_ALL_GCS | |
699 if (UseG1GC) { | |
700 // Needs to be cleared explicitly for G1 | |
701 Universe::heap()->collector_policy()->set_should_clear_all_soft_refs(false); | |
702 } | |
703 #endif // INCLUDE_ALL_GCS | |
698 WB_END | 704 WB_END |
699 | 705 |
700 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o)) | 706 WB_ENTRY(void, WB_YoungGC(JNIEnv* env, jobject o)) |
701 Universe::heap()->collect(GCCause::_wb_young_gc); | 707 Universe::heap()->collect(GCCause::_wb_young_gc); |
702 WB_END | 708 WB_END |
836 offset_for_field(field_name, object, vmSymbols::bool_signature()); | 842 offset_for_field(field_name, object, vmSymbols::bool_signature()); |
837 bool ret = (object->bool_field(offset) == JNI_TRUE); | 843 bool ret = (object->bool_field(offset) == JNI_TRUE); |
838 return ret; | 844 return ret; |
839 } | 845 } |
840 | 846 |
847 void WhiteBox::register_methods(JNIEnv* env, jclass wbclass, JavaThread* thread, JNINativeMethod* method_array, int method_count) { | |
848 ResourceMark rm; | |
849 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI | |
850 | |
851 // one by one registration natives for exception catching | |
852 jclass no_such_method_error_klass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); | |
853 CHECK_JNI_EXCEPTION(env); | |
854 for (int i = 0, n = method_count; i < n; ++i) { | |
855 // Skip dummy entries | |
856 if (method_array[i].fnPtr == NULL) continue; | |
857 if (env->RegisterNatives(wbclass, &method_array[i], 1) != 0) { | |
858 jthrowable throwable_obj = env->ExceptionOccurred(); | |
859 if (throwable_obj != NULL) { | |
860 env->ExceptionClear(); | |
861 if (env->IsInstanceOf(throwable_obj, no_such_method_error_klass)) { | |
862 // NoSuchMethodError is thrown when a method can't be found or a method is not native. | |
863 // Ignoring the exception since it is not preventing use of other WhiteBox methods. | |
864 tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", | |
865 method_array[i].name, method_array[i].signature); | |
866 } | |
867 } else { | |
868 // Registration failed unexpectedly. | |
869 tty->print_cr("Warning: unexpected error on register of sun.hotspot.WhiteBox::%s%s. All methods will be unregistered", | |
870 method_array[i].name, method_array[i].signature); | |
871 env->UnregisterNatives(wbclass); | |
872 break; | |
873 } | |
874 } | |
875 } | |
876 } | |
841 | 877 |
842 #define CC (char*) | 878 #define CC (char*) |
843 | 879 |
844 static JNINativeMethod methods[] = { | 880 static JNINativeMethod methods[] = { |
845 {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, | 881 {CC"getObjectAddress", CC"(Ljava/lang/Object;)J", (void*)&WB_GetObjectAddress }, |
938 if (WhiteBoxAPI) { | 974 if (WhiteBoxAPI) { |
939 // Make sure that wbclass is loaded by the null classloader | 975 // Make sure that wbclass is loaded by the null classloader |
940 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); | 976 instanceKlassHandle ikh = instanceKlassHandle(JNIHandles::resolve(wbclass)->klass()); |
941 Handle loader(ikh->class_loader()); | 977 Handle loader(ikh->class_loader()); |
942 if (loader.is_null()) { | 978 if (loader.is_null()) { |
943 ResourceMark rm; | 979 WhiteBox::register_methods(env, wbclass, thread, methods, sizeof(methods) / sizeof(methods[0])); |
944 ThreadToNativeFromVM ttnfv(thread); // can't be in VM when we call JNI | 980 WhiteBox::register_extended(env, wbclass, thread); |
945 bool result = true; | 981 WhiteBox::set_used(); |
946 // one by one registration natives for exception catching | |
947 jclass exceptionKlass = env->FindClass(vmSymbols::java_lang_NoSuchMethodError()->as_C_string()); | |
948 CHECK_JNI_EXCEPTION(env); | |
949 for (int i = 0, n = sizeof(methods) / sizeof(methods[0]); i < n; ++i) { | |
950 if (env->RegisterNatives(wbclass, methods + i, 1) != 0) { | |
951 result = false; | |
952 jthrowable throwable_obj = env->ExceptionOccurred(); | |
953 if (throwable_obj != NULL) { | |
954 env->ExceptionClear(); | |
955 if (env->IsInstanceOf(throwable_obj, exceptionKlass)) { | |
956 // j.l.NoSuchMethodError is thrown when a method can't be found or a method is not native | |
957 // ignoring the exception | |
958 tty->print_cr("Warning: 'NoSuchMethodError' on register of sun.hotspot.WhiteBox::%s%s", methods[i].name, methods[i].signature); | |
959 } | |
960 } else { | |
961 // register is failed w/o exception or w/ unexpected exception | |
962 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); | |
963 env->UnregisterNatives(wbclass); | |
964 break; | |
965 } | |
966 } | |
967 } | |
968 | |
969 if (result) { | |
970 WhiteBox::set_used(); | |
971 } | |
972 } | 982 } |
973 } | 983 } |
974 } | 984 } |
975 JVM_END | 985 JVM_END |