682 // This logic has the current thread wait once it has done
683 // all the superclass/superinterface loading it can, until
684 // the original thread completes the class loading or fails
685 // If it completes we will use the resulting InstanceKlass
686 // which we will find below in the systemDictionary.
687 // We also get here for parallel bootstrap classloader
688 if (class_loader.is_null()) {
689 SystemDictionary_lock->wait();
690 } else {
691 double_lock_wait(lockObject, THREAD);
692 }
693 } else {
694 // If not in SD and not in PH, other thread's load must have failed
695 super_load_in_progress = false;
696 }
697 }
698 }
699 return NULL;
700 }
701
702 static void post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld) {
703 assert(event != NULL, "invariant");
704 assert(k != NULL, "invariant");
705 assert(event->should_commit(), "invariant");
706 event->set_loadedClass(k);
707 event->set_definingClassLoader(k->class_loader_data());
708 event->set_initiatingClassLoader(init_cld);
709 event->commit();
710 }
711
712
713 // Be careful when modifying this code: once you have run
714 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
715 // you need to find_and_remove it before returning.
716 // So be careful to not exit with a CHECK_ macro betweeen these calls.
717 //
718 // name must be in the form of "java/lang/Object" -- cannot be "Ljava/lang/Object;"
719 InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
720 Handle class_loader,
721 Handle protection_domain,
722 TRAPS) {
1358 !check_shared_class_super_type(ik, InstanceKlass::cast(ik->super()),
1359 class_loader, protection_domain, true, THREAD)) {
1360 return false;
1361 }
1362
1363 Array<InstanceKlass*>* interfaces = ik->local_interfaces();
1364 int num_interfaces = interfaces->length();
1365 for (int index = 0; index < num_interfaces; index++) {
1366 if (!check_shared_class_super_type(ik, interfaces->at(index), class_loader, protection_domain, false, THREAD)) {
1367 return false;
1368 }
1369 }
1370
1371 return true;
1372 }
1373
1374 InstanceKlass* SystemDictionary::load_shared_lambda_proxy_class(InstanceKlass* ik,
1375 Handle class_loader,
1376 Handle protection_domain,
1377 PackageEntry* pkg_entry,
1378 bool initialize,
1379 TRAPS) {
1380 InstanceKlass* shared_nest_host = SystemDictionaryShared::get_shared_nest_host(ik);
1381 assert(shared_nest_host->is_shared(), "nest host must be in CDS archive");
1382 Symbol* cn = shared_nest_host->name();
1383 Klass *s = resolve_or_fail(cn, class_loader, protection_domain, true, CHECK_NULL);
1384 if (s != shared_nest_host) {
1385 // The dynamically resolved nest_host is not the same as the one we used during dump time,
1386 // so we cannot use ik.
1387 return NULL;
1388 } else {
1389 assert(s->is_shared(), "must be");
1390 }
1391
1392 // The lambda proxy class and its nest host have the same class loader and class loader data,
1393 // as verified in SystemDictionaryShared::add_lambda_proxy_class()
1394 assert(shared_nest_host->class_loader() == class_loader(), "mismatched class loader");
1395 assert(shared_nest_host->class_loader_data() == ClassLoaderData::class_loader_data(class_loader()), "mismatched class loader data");
1396 ik->set_nest_host(shared_nest_host, THREAD);
1397
1398 InstanceKlass* loaded_ik = load_shared_class(ik, class_loader, protection_domain, NULL, pkg_entry, CHECK_NULL);
1399
1400 assert(shared_nest_host->is_same_class_package(ik),
1401 "lambda proxy class and its nest host must be in the same package");
1402
1403 EventClassLoad class_load_start_event;
1404 {
1405 MutexLocker mu_r(THREAD, Compile_lock);
1406
1407 // Add to class hierarchy, initialize vtables, and do possible
1408 // deoptimizations.
1409 SystemDictionary::add_to_hierarchy(loaded_ik, CHECK_NULL); // No exception, but can block
1410 // But, do not add to dictionary.
1411 }
1412 loaded_ik->link_class(CHECK_NULL);
1413 // notify jvmti
1414 if (JvmtiExport::should_post_class_load()) {
1415 assert(THREAD->is_Java_thread(), "thread->is_Java_thread()");
1416 JvmtiExport::post_class_load((JavaThread *) THREAD, loaded_ik);
1417 }
1418 if (class_load_start_event.should_commit()) {
1419 post_class_load_event(&class_load_start_event, loaded_ik, ClassLoaderData::class_loader_data(class_loader()));
1420 }
1421
1422 if (initialize) {
1423 loaded_ik->initialize(CHECK_NULL);
1424 }
1425 return loaded_ik;
1426 }
1427
1428 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1429 Handle class_loader,
1430 Handle protection_domain,
1431 const ClassFileStream *cfs,
1432 PackageEntry* pkg_entry,
1433 TRAPS) {
1434 assert(ik != NULL, "sanity");
1435 assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1436 Symbol* class_name = ik->name();
1437
1438 bool visible = is_shared_class_visible(
1439 class_name, ik, pkg_entry, class_loader, CHECK_NULL);
1440 if (!visible) {
1441 return NULL;
1442 }
1443
1444 if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) {
|
682 // This logic has the current thread wait once it has done
683 // all the superclass/superinterface loading it can, until
684 // the original thread completes the class loading or fails
685 // If it completes we will use the resulting InstanceKlass
686 // which we will find below in the systemDictionary.
687 // We also get here for parallel bootstrap classloader
688 if (class_loader.is_null()) {
689 SystemDictionary_lock->wait();
690 } else {
691 double_lock_wait(lockObject, THREAD);
692 }
693 } else {
694 // If not in SD and not in PH, other thread's load must have failed
695 super_load_in_progress = false;
696 }
697 }
698 }
699 return NULL;
700 }
701
702 void SystemDictionary::post_class_load_event(EventClassLoad* event, const InstanceKlass* k, const ClassLoaderData* init_cld) {
703 assert(event != NULL, "invariant");
704 assert(k != NULL, "invariant");
705 assert(event->should_commit(), "invariant");
706 event->set_loadedClass(k);
707 event->set_definingClassLoader(k->class_loader_data());
708 event->set_initiatingClassLoader(init_cld);
709 event->commit();
710 }
711
712
713 // Be careful when modifying this code: once you have run
714 // placeholders()->find_and_add(PlaceholderTable::LOAD_INSTANCE),
715 // you need to find_and_remove it before returning.
716 // So be careful to not exit with a CHECK_ macro betweeen these calls.
717 //
718 // name must be in the form of "java/lang/Object" -- cannot be "Ljava/lang/Object;"
719 InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
720 Handle class_loader,
721 Handle protection_domain,
722 TRAPS) {
1358 !check_shared_class_super_type(ik, InstanceKlass::cast(ik->super()),
1359 class_loader, protection_domain, true, THREAD)) {
1360 return false;
1361 }
1362
1363 Array<InstanceKlass*>* interfaces = ik->local_interfaces();
1364 int num_interfaces = interfaces->length();
1365 for (int index = 0; index < num_interfaces; index++) {
1366 if (!check_shared_class_super_type(ik, interfaces->at(index), class_loader, protection_domain, false, THREAD)) {
1367 return false;
1368 }
1369 }
1370
1371 return true;
1372 }
1373
1374 InstanceKlass* SystemDictionary::load_shared_lambda_proxy_class(InstanceKlass* ik,
1375 Handle class_loader,
1376 Handle protection_domain,
1377 PackageEntry* pkg_entry,
1378 TRAPS) {
1379 InstanceKlass* shared_nest_host = SystemDictionaryShared::get_shared_nest_host(ik);
1380 assert(shared_nest_host->is_shared(), "nest host must be in CDS archive");
1381 Symbol* cn = shared_nest_host->name();
1382 Klass *s = resolve_or_fail(cn, class_loader, protection_domain, true, CHECK_NULL);
1383 if (s != shared_nest_host) {
1384 // The dynamically resolved nest_host is not the same as the one we used during dump time,
1385 // so we cannot use ik.
1386 return NULL;
1387 } else {
1388 assert(s->is_shared(), "must be");
1389 }
1390
1391 // The lambda proxy class and its nest host have the same class loader and class loader data,
1392 // as verified in SystemDictionaryShared::add_lambda_proxy_class()
1393 assert(shared_nest_host->class_loader() == class_loader(), "mismatched class loader");
1394 assert(shared_nest_host->class_loader_data() == ClassLoaderData::class_loader_data(class_loader()), "mismatched class loader data");
1395 ik->set_nest_host(shared_nest_host, THREAD);
1396
1397 InstanceKlass* loaded_ik = load_shared_class(ik, class_loader, protection_domain, NULL, pkg_entry, CHECK_NULL);
1398
1399 assert(shared_nest_host->is_same_class_package(ik),
1400 "lambda proxy class and its nest host must be in the same package");
1401
1402 return loaded_ik;
1403 }
1404
1405 InstanceKlass* SystemDictionary::load_shared_class(InstanceKlass* ik,
1406 Handle class_loader,
1407 Handle protection_domain,
1408 const ClassFileStream *cfs,
1409 PackageEntry* pkg_entry,
1410 TRAPS) {
1411 assert(ik != NULL, "sanity");
1412 assert(!ik->is_unshareable_info_restored(), "shared class can be loaded only once");
1413 Symbol* class_name = ik->name();
1414
1415 bool visible = is_shared_class_visible(
1416 class_name, ik, pkg_entry, class_loader, CHECK_NULL);
1417 if (!visible) {
1418 return NULL;
1419 }
1420
1421 if (!check_shared_class_super_types(ik, class_loader, protection_domain, THREAD)) {
|