< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page




1211     return NULL;
1212   }
1213 
1214   // Make sure we have an entry in the SystemDictionary on success
1215   debug_only( {
1216     MutexLocker mu(THREAD, SystemDictionary_lock);
1217 
1218     Klass* check = find_class(h_name, k->class_loader_data());
1219     assert(check == k, "should be present in the dictionary");
1220   } );
1221 
1222   return k;
1223 }
1224 
1225 #if INCLUDE_CDS
1226 // Load a class for boot loader from the shared spaces. This also
1227 // forces the super class and all interfaces to be loaded.
1228 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
1229                                                         PackageEntry* pkg_entry,
1230                                                         TRAPS) {

1231   InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1232   if (ik != NULL && ik->is_shared_boot_class()) {
1233     return load_shared_class(ik, Handle(), Handle(), NULL, pkg_entry, THREAD);
1234   }
1235   return NULL;
1236 }
1237 
1238 // Check if a shared class can be loaded by the specific classloader:
1239 //
1240 // NULL classloader:
1241 //   - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1242 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1243 //     be defined in an unnamed module.
1244 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1245                                                InstanceKlass* ik,
1246                                                PackageEntry* pkg_entry,
1247                                                Handle class_loader, TRAPS) {
1248   assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
1249          "Cannot use sharing if java.base is patched");
1250   ResourceMark rm(THREAD);
1251   int path_index = ik->shared_classpath_index();
1252   ClassLoaderData* loader_data = class_loader_data(class_loader);
1253   if (path_index < 0) {
1254     // path_index < 0 indicates that the class is intended for a custom loader
1255     // and should not be loaded by boot/platform/app loaders
1256     if (loader_data->is_builtin_class_loader_data()) {
1257       return false;
1258     } else {
1259       return true;
1260     }
1261   }








1262   SharedClassPathEntry* ent =
1263             (SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
1264   if (!Universe::is_module_initialized()) {
1265     assert(ent != NULL && ent->is_modules_image(),
1266            "Loading non-bootstrap classes before the module system is initialized");
1267     assert(class_loader.is_null(), "sanity");
1268     return true;
1269   }
1270   // Get the pkg_entry from the classloader
1271   ModuleEntry* mod_entry = NULL;
1272   TempNewSymbol pkg_name = pkg_entry != NULL ? pkg_entry->name() :
1273                                                ClassLoader::package_from_class_name(class_name);
1274   if (pkg_name != NULL) {
1275     if (loader_data != NULL) {
1276       if (pkg_entry != NULL) {
1277         mod_entry = pkg_entry->module();
1278         // If the archived class is from a module that has been patched at runtime,
1279         // the class cannot be loaded from the archive.
1280         if (mod_entry != NULL && mod_entry->is_patched()) {
1281           return false;


1539         // a named package within the unnamed module.  In all cases,
1540         // limit visibility to search for the class only in the boot
1541         // loader's append path.
1542         if (!ClassLoader::has_bootclasspath_append()) {
1543            // If there is no bootclasspath append entry, no need to continue
1544            // searching.
1545            return NULL;
1546         }
1547         search_only_bootloader_append = true;
1548       }
1549     }
1550 
1551     // Prior to bootstrapping's module initialization, never load a class outside
1552     // of the boot loader's module path
1553     assert(Universe::is_module_initialized() ||
1554            !search_only_bootloader_append,
1555            "Attempt to load a class outside of boot loader's module path");
1556 
1557     // Search for classes in the CDS archive.
1558     InstanceKlass* k = NULL;
1559     {
1560 #if INCLUDE_CDS


1561       PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1562       k = load_shared_boot_class(class_name, pkg_entry, THREAD);
1563 #endif
1564     }

1565 
1566     if (k == NULL) {
1567       // Use VM class loader
1568       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1569       k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
1570     }
1571 
1572     // find_or_define_instance_class may return a different InstanceKlass
1573     if (k != NULL) {
1574       InstanceKlass* defined_k =
1575         find_or_define_instance_class(class_name, class_loader, k, THREAD);
1576       if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1577         // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1578         assert(defined_k != NULL, "Should have a klass if there's no exception");
1579         loader_data->add_to_deallocate_list(k);
1580         k = defined_k;
1581       } else if (HAS_PENDING_EXCEPTION) {
1582         loader_data->add_to_deallocate_list(k);
1583         return NULL;
1584       }




1211     return NULL;
1212   }
1213 
1214   // Make sure we have an entry in the SystemDictionary on success
1215   debug_only( {
1216     MutexLocker mu(THREAD, SystemDictionary_lock);
1217 
1218     Klass* check = find_class(h_name, k->class_loader_data());
1219     assert(check == k, "should be present in the dictionary");
1220   } );
1221 
1222   return k;
1223 }
1224 
1225 #if INCLUDE_CDS
1226 // Load a class for boot loader from the shared spaces. This also
1227 // forces the super class and all interfaces to be loaded.
1228 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
1229                                                         PackageEntry* pkg_entry,
1230                                                         TRAPS) {
1231   assert(UseSharedSpaces, "Sanity check");
1232   InstanceKlass* ik = SystemDictionaryShared::find_builtin_class(class_name);
1233   if (ik != NULL && ik->is_shared_boot_class()) {
1234     return load_shared_class(ik, Handle(), Handle(), NULL, pkg_entry, THREAD);
1235   }
1236   return NULL;
1237 }
1238 
1239 // Check if a shared class can be loaded by the specific classloader:
1240 //
1241 // NULL classloader:
1242 //   - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1243 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1244 //     be defined in an unnamed module.
1245 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1246                                                InstanceKlass* ik,
1247                                                PackageEntry* pkg_entry,
1248                                                Handle class_loader, TRAPS) {
1249   assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
1250          "Cannot use sharing if java.base is patched");

1251   int path_index = ik->shared_classpath_index();

1252   if (path_index < 0) {
1253     // path_index < 0 indicates that the class is intended for a custom loader
1254     // and should not be loaded by boot/platform/app loaders
1255     if (is_builtin_class_loader(class_loader())) {
1256       return false;
1257     } else {
1258       return true;
1259     }
1260   }
1261 
1262   // skip class visibility check
1263   if (MetaspaceShared::use_optimized_module_handling()) {
1264     log_info(cds)("Using optimized module handling");
1265     return true;
1266   }
1267 
1268   ClassLoaderData* loader_data = class_loader_data(class_loader);
1269   SharedClassPathEntry* ent =
1270             (SharedClassPathEntry*)FileMapInfo::shared_path(path_index);
1271   if (!Universe::is_module_initialized()) {
1272     assert(ent != NULL && ent->is_modules_image(),
1273            "Loading non-bootstrap classes before the module system is initialized");
1274     assert(class_loader.is_null(), "sanity");
1275     return true;
1276   }
1277   // Get the pkg_entry from the classloader
1278   ModuleEntry* mod_entry = NULL;
1279   TempNewSymbol pkg_name = pkg_entry != NULL ? pkg_entry->name() :
1280                                                ClassLoader::package_from_class_name(class_name);
1281   if (pkg_name != NULL) {
1282     if (loader_data != NULL) {
1283       if (pkg_entry != NULL) {
1284         mod_entry = pkg_entry->module();
1285         // If the archived class is from a module that has been patched at runtime,
1286         // the class cannot be loaded from the archive.
1287         if (mod_entry != NULL && mod_entry->is_patched()) {
1288           return false;


1546         // a named package within the unnamed module.  In all cases,
1547         // limit visibility to search for the class only in the boot
1548         // loader's append path.
1549         if (!ClassLoader::has_bootclasspath_append()) {
1550            // If there is no bootclasspath append entry, no need to continue
1551            // searching.
1552            return NULL;
1553         }
1554         search_only_bootloader_append = true;
1555       }
1556     }
1557 
1558     // Prior to bootstrapping's module initialization, never load a class outside
1559     // of the boot loader's module path
1560     assert(Universe::is_module_initialized() ||
1561            !search_only_bootloader_append,
1562            "Attempt to load a class outside of boot loader's module path");
1563 
1564     // Search for classes in the CDS archive.
1565     InstanceKlass* k = NULL;
1566 
1567 #if INCLUDE_CDS
1568     if (UseSharedSpaces) 
1569     {
1570       PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1571       k = load_shared_boot_class(class_name, pkg_entry, THREAD);

1572     }
1573 #endif
1574 
1575     if (k == NULL) {
1576       // Use VM class loader
1577       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1578       k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
1579     }
1580 
1581     // find_or_define_instance_class may return a different InstanceKlass
1582     if (k != NULL) {
1583       InstanceKlass* defined_k =
1584         find_or_define_instance_class(class_name, class_loader, k, THREAD);
1585       if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1586         // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1587         assert(defined_k != NULL, "Should have a klass if there's no exception");
1588         loader_data->add_to_deallocate_list(k);
1589         k = defined_k;
1590       } else if (HAS_PENDING_EXCEPTION) {
1591         loader_data->add_to_deallocate_list(k);
1592         return NULL;
1593       }


< prev index next >