132 InstanceKlass* class_loader_klass = SystemDictionary::ClassLoader_klass();
133 JavaCalls::call_static(&result,
134 class_loader_klass,
135 vmSymbols::getSystemClassLoader_name(),
136 vmSymbols::void_classloader_signature(),
137 CHECK);
138
139 _java_system_loader = (oop)result.get_jobject();
140
141 JavaCalls::call_static(&result,
142 class_loader_klass,
143 vmSymbols::getPlatformClassLoader_name(),
144 vmSymbols::void_classloader_signature(),
145 CHECK);
146
147 _java_platform_loader = (oop)result.get_jobject();
148
149 CDS_ONLY(SystemDictionaryShared::initialize(CHECK);)
150 }
151
152 ClassLoaderData* SystemDictionary::register_loader(Handle class_loader, TRAPS) {
153 if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data();
154 return ClassLoaderDataGraph::find_or_create(class_loader, THREAD);
155 }
156
157 // ----------------------------------------------------------------------------
158 // Parallel class loading check
159
160 bool SystemDictionary::is_parallelCapable(Handle class_loader) {
161 if (class_loader.is_null()) return true;
162 if (AlwaysLockClassLoader) return false;
163 return java_lang_ClassLoader::parallelCapable(class_loader());
164 }
165 // ----------------------------------------------------------------------------
166 // ParallelDefineClass flag does not apply to bootclass loader
167 bool SystemDictionary::is_parallelDefine(Handle class_loader) {
168 if (class_loader.is_null()) return false;
169 if (AllowParallelDefineClass && java_lang_ClassLoader::parallelCapable(class_loader())) {
170 return true;
171 }
172 return false;
173 }
174
646 #endif // INCLUDE_TRACE
647 }
648
649 // Be careful when modifying this code: once you have run
650 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
651 // you need to find_and_remove it before returning.
652 // So be careful to not exit with a CHECK_ macro betweeen these calls.
653 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
654 Handle class_loader,
655 Handle protection_domain,
656 TRAPS) {
657 assert(name != NULL && !FieldType::is_array(name) &&
658 !FieldType::is_obj(name), "invalid class name");
659
660 EventClassLoad class_load_start_event;
661
662 HandleMark hm(THREAD);
663
664 // Fix for 4474172; see evaluation for more details
665 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
666 ClassLoaderData *loader_data = register_loader(class_loader, CHECK_NULL);
667 Dictionary* dictionary = loader_data->dictionary();
668 unsigned int d_hash = dictionary->compute_hash(name);
669
670 // Do lookup to see if class already exist and the protection domain
671 // has the right access
672 // This call uses find which checks protection domain already matches
673 // All subsequent calls use find_class, and set has_loaded_class so that
674 // before we return a result we call out to java to check for valid protection domain
675 // to allow returning the Klass* and add it to the pd_set if it is valid
676 {
677 Klass* probe = dictionary->find(d_hash, name, protection_domain);
678 if (probe != NULL) return probe;
679 }
680
681 // Non-bootstrap class loaders will call out to class loader and
682 // define via jvm/jni_DefineClass which will acquire the
683 // class loader object lock to protect against multiple threads
684 // defining the class in parallel by accident.
685 // This lock must be acquired here so the waiter will find
686 // any successful result in the SystemDictionary and not attempt
971
972 // Note: this method is much like resolve_from_stream, but
973 // does not publish the classes via the SystemDictionary.
974 // Handles unsafe_DefineAnonymousClass and redefineclasses
975 // RedefinedClasses do not add to the class hierarchy
976 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
977 Handle class_loader,
978 Handle protection_domain,
979 ClassFileStream* st,
980 const InstanceKlass* host_klass,
981 GrowableArray<Handle>* cp_patches,
982 TRAPS) {
983
984 EventClassLoad class_load_start_event;
985
986 ClassLoaderData* loader_data;
987 if (host_klass != NULL) {
988 // Create a new CLD for anonymous class, that uses the same class loader
989 // as the host_klass
990 guarantee(host_klass->class_loader() == class_loader(), "should be the same");
991 loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader(), CHECK_NULL);
992 } else {
993 loader_data = ClassLoaderData::class_loader_data(class_loader());
994 }
995
996 assert(st != NULL, "invariant");
997 assert(st->need_verify(), "invariant");
998
999 // Parse stream and create a klass.
1000 // Note that we do this even though this klass might
1001 // already be present in the SystemDictionary, otherwise we would not
1002 // throw potential ClassFormatErrors.
1003
1004 InstanceKlass* k = KlassFactory::create_from_stream(st,
1005 class_name,
1006 loader_data,
1007 protection_domain,
1008 host_klass,
1009 cp_patches,
1010 CHECK_NULL);
1011
1058 TRAPS) {
1059 #if INCLUDE_CDS
1060 ResourceMark rm(THREAD);
1061 if (DumpSharedSpaces && !class_loader.is_null() &&
1062 !UseAppCDS && strcmp(class_name->as_C_string(), "Unnamed") != 0) {
1063 // If AppCDS is not enabled, don't define the class at dump time (except for the "Unnamed"
1064 // class, which is used by MethodHandles).
1065 THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
1066 }
1067 #endif
1068
1069 HandleMark hm(THREAD);
1070
1071 // Classloaders that support parallelism, e.g. bootstrap classloader,
1072 // do not acquire lock here
1073 bool DoObjectLock = true;
1074 if (is_parallelCapable(class_loader)) {
1075 DoObjectLock = false;
1076 }
1077
1078 ClassLoaderData* loader_data = register_loader(class_loader, CHECK_NULL);
1079
1080 // Make sure we are synchronized on the class loader before we proceed
1081 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1082 check_loader_lock_contention(lockObject, THREAD);
1083 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
1084
1085 assert(st != NULL, "invariant");
1086
1087 // Parse the stream and create a klass.
1088 // Note that we do this even though this klass might
1089 // already be present in the SystemDictionary, otherwise we would not
1090 // throw potential ClassFormatErrors.
1091 InstanceKlass* k = NULL;
1092
1093 #if INCLUDE_CDS
1094 if (!DumpSharedSpaces) {
1095 k = SystemDictionaryShared::lookup_from_stream(class_name,
1096 class_loader,
1097 protection_domain,
1098 st,
2496 Klass* accessing_klass,
2497 objArrayHandle appendix_box,
2498 Handle* appendix_result,
2499 TRAPS) {
2500 methodHandle empty;
2501 if (mname.not_null()) {
2502 Method* m = java_lang_invoke_MemberName::vmtarget(mname());
2503 if (m != NULL) {
2504 oop appendix = appendix_box->obj_at(0);
2505 if (TraceMethodHandles) {
2506 #ifndef PRODUCT
2507 ttyLocker ttyl;
2508 tty->print("Linked method=" INTPTR_FORMAT ": ", p2i(m));
2509 m->print();
2510 if (appendix != NULL) { tty->print("appendix = "); appendix->print(); }
2511 tty->cr();
2512 #endif //PRODUCT
2513 }
2514 (*appendix_result) = Handle(THREAD, appendix);
2515 // the target is stored in the cpCache and if a reference to this
2516 // MethodName is dropped we need a way to make sure the
2517 // class_loader containing this method is kept alive.
2518 // FIXME: the appendix might also preserve this dependency.
2519 ClassLoaderData* this_key = accessing_klass->class_loader_data();
2520 this_key->record_dependency(m->method_holder(), CHECK_NULL); // Can throw OOM
2521 return methodHandle(THREAD, m);
2522 }
2523 }
2524 THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty);
2525 return empty;
2526 }
2527
2528 methodHandle SystemDictionary::find_method_handle_invoker(Klass* klass,
2529 Symbol* name,
2530 Symbol* signature,
2531 Klass* accessing_klass,
2532 Handle *appendix_result,
2533 Handle *method_type_result,
2534 TRAPS) {
2535 methodHandle empty;
2536 assert(THREAD->can_call_java() ,"");
2537 Handle method_type =
2538 SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
2539
2540 int ref_kind = JVM_REF_invokeVirtual;
|
132 InstanceKlass* class_loader_klass = SystemDictionary::ClassLoader_klass();
133 JavaCalls::call_static(&result,
134 class_loader_klass,
135 vmSymbols::getSystemClassLoader_name(),
136 vmSymbols::void_classloader_signature(),
137 CHECK);
138
139 _java_system_loader = (oop)result.get_jobject();
140
141 JavaCalls::call_static(&result,
142 class_loader_klass,
143 vmSymbols::getPlatformClassLoader_name(),
144 vmSymbols::void_classloader_signature(),
145 CHECK);
146
147 _java_platform_loader = (oop)result.get_jobject();
148
149 CDS_ONLY(SystemDictionaryShared::initialize(CHECK);)
150 }
151
152 ClassLoaderData* SystemDictionary::register_loader(Handle class_loader) {
153 if (class_loader() == NULL) return ClassLoaderData::the_null_class_loader_data();
154 return ClassLoaderDataGraph::find_or_create(class_loader);
155 }
156
157 // ----------------------------------------------------------------------------
158 // Parallel class loading check
159
160 bool SystemDictionary::is_parallelCapable(Handle class_loader) {
161 if (class_loader.is_null()) return true;
162 if (AlwaysLockClassLoader) return false;
163 return java_lang_ClassLoader::parallelCapable(class_loader());
164 }
165 // ----------------------------------------------------------------------------
166 // ParallelDefineClass flag does not apply to bootclass loader
167 bool SystemDictionary::is_parallelDefine(Handle class_loader) {
168 if (class_loader.is_null()) return false;
169 if (AllowParallelDefineClass && java_lang_ClassLoader::parallelCapable(class_loader())) {
170 return true;
171 }
172 return false;
173 }
174
646 #endif // INCLUDE_TRACE
647 }
648
649 // Be careful when modifying this code: once you have run
650 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
651 // you need to find_and_remove it before returning.
652 // So be careful to not exit with a CHECK_ macro betweeen these calls.
653 Klass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
654 Handle class_loader,
655 Handle protection_domain,
656 TRAPS) {
657 assert(name != NULL && !FieldType::is_array(name) &&
658 !FieldType::is_obj(name), "invalid class name");
659
660 EventClassLoad class_load_start_event;
661
662 HandleMark hm(THREAD);
663
664 // Fix for 4474172; see evaluation for more details
665 class_loader = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
666 ClassLoaderData* loader_data = register_loader(class_loader);
667 Dictionary* dictionary = loader_data->dictionary();
668 unsigned int d_hash = dictionary->compute_hash(name);
669
670 // Do lookup to see if class already exist and the protection domain
671 // has the right access
672 // This call uses find which checks protection domain already matches
673 // All subsequent calls use find_class, and set has_loaded_class so that
674 // before we return a result we call out to java to check for valid protection domain
675 // to allow returning the Klass* and add it to the pd_set if it is valid
676 {
677 Klass* probe = dictionary->find(d_hash, name, protection_domain);
678 if (probe != NULL) return probe;
679 }
680
681 // Non-bootstrap class loaders will call out to class loader and
682 // define via jvm/jni_DefineClass which will acquire the
683 // class loader object lock to protect against multiple threads
684 // defining the class in parallel by accident.
685 // This lock must be acquired here so the waiter will find
686 // any successful result in the SystemDictionary and not attempt
971
972 // Note: this method is much like resolve_from_stream, but
973 // does not publish the classes via the SystemDictionary.
974 // Handles unsafe_DefineAnonymousClass and redefineclasses
975 // RedefinedClasses do not add to the class hierarchy
976 InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
977 Handle class_loader,
978 Handle protection_domain,
979 ClassFileStream* st,
980 const InstanceKlass* host_klass,
981 GrowableArray<Handle>* cp_patches,
982 TRAPS) {
983
984 EventClassLoad class_load_start_event;
985
986 ClassLoaderData* loader_data;
987 if (host_klass != NULL) {
988 // Create a new CLD for anonymous class, that uses the same class loader
989 // as the host_klass
990 guarantee(host_klass->class_loader() == class_loader(), "should be the same");
991 loader_data = ClassLoaderData::anonymous_class_loader_data(class_loader);
992 } else {
993 loader_data = ClassLoaderData::class_loader_data(class_loader());
994 }
995
996 assert(st != NULL, "invariant");
997 assert(st->need_verify(), "invariant");
998
999 // Parse stream and create a klass.
1000 // Note that we do this even though this klass might
1001 // already be present in the SystemDictionary, otherwise we would not
1002 // throw potential ClassFormatErrors.
1003
1004 InstanceKlass* k = KlassFactory::create_from_stream(st,
1005 class_name,
1006 loader_data,
1007 protection_domain,
1008 host_klass,
1009 cp_patches,
1010 CHECK_NULL);
1011
1058 TRAPS) {
1059 #if INCLUDE_CDS
1060 ResourceMark rm(THREAD);
1061 if (DumpSharedSpaces && !class_loader.is_null() &&
1062 !UseAppCDS && strcmp(class_name->as_C_string(), "Unnamed") != 0) {
1063 // If AppCDS is not enabled, don't define the class at dump time (except for the "Unnamed"
1064 // class, which is used by MethodHandles).
1065 THROW_MSG_NULL(vmSymbols::java_lang_ClassNotFoundException(), class_name->as_C_string());
1066 }
1067 #endif
1068
1069 HandleMark hm(THREAD);
1070
1071 // Classloaders that support parallelism, e.g. bootstrap classloader,
1072 // do not acquire lock here
1073 bool DoObjectLock = true;
1074 if (is_parallelCapable(class_loader)) {
1075 DoObjectLock = false;
1076 }
1077
1078 ClassLoaderData* loader_data = register_loader(class_loader);
1079
1080 // Make sure we are synchronized on the class loader before we proceed
1081 Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1082 check_loader_lock_contention(lockObject, THREAD);
1083 ObjectLocker ol(lockObject, THREAD, DoObjectLock);
1084
1085 assert(st != NULL, "invariant");
1086
1087 // Parse the stream and create a klass.
1088 // Note that we do this even though this klass might
1089 // already be present in the SystemDictionary, otherwise we would not
1090 // throw potential ClassFormatErrors.
1091 InstanceKlass* k = NULL;
1092
1093 #if INCLUDE_CDS
1094 if (!DumpSharedSpaces) {
1095 k = SystemDictionaryShared::lookup_from_stream(class_name,
1096 class_loader,
1097 protection_domain,
1098 st,
2496 Klass* accessing_klass,
2497 objArrayHandle appendix_box,
2498 Handle* appendix_result,
2499 TRAPS) {
2500 methodHandle empty;
2501 if (mname.not_null()) {
2502 Method* m = java_lang_invoke_MemberName::vmtarget(mname());
2503 if (m != NULL) {
2504 oop appendix = appendix_box->obj_at(0);
2505 if (TraceMethodHandles) {
2506 #ifndef PRODUCT
2507 ttyLocker ttyl;
2508 tty->print("Linked method=" INTPTR_FORMAT ": ", p2i(m));
2509 m->print();
2510 if (appendix != NULL) { tty->print("appendix = "); appendix->print(); }
2511 tty->cr();
2512 #endif //PRODUCT
2513 }
2514 (*appendix_result) = Handle(THREAD, appendix);
2515 // the target is stored in the cpCache and if a reference to this
2516 // MemberName is dropped we need a way to make sure the
2517 // class_loader containing this method is kept alive.
2518 ClassLoaderData* this_key = accessing_klass->class_loader_data();
2519 this_key->record_dependency(m->method_holder());
2520 return methodHandle(THREAD, m);
2521 }
2522 }
2523 THROW_MSG_(vmSymbols::java_lang_LinkageError(), "bad value from MethodHandleNatives", empty);
2524 return empty;
2525 }
2526
2527 methodHandle SystemDictionary::find_method_handle_invoker(Klass* klass,
2528 Symbol* name,
2529 Symbol* signature,
2530 Klass* accessing_klass,
2531 Handle *appendix_result,
2532 Handle *method_type_result,
2533 TRAPS) {
2534 methodHandle empty;
2535 assert(THREAD->can_call_java() ,"");
2536 Handle method_type =
2537 SystemDictionary::find_method_handle_type(signature, accessing_klass, CHECK_(empty));
2538
2539 int ref_kind = JVM_REF_invokeVirtual;
|