< prev index next >

src/share/vm/classfile/systemDictionary.cpp

Print this page




1205                  Symbol* class_name, Handle class_loader, TRAPS) {
1206   instanceKlassHandle ik (THREAD, find_shared_class(class_name));
1207   // Make sure we only return the boot class for the NULL classloader.
1208   if (ik.not_null() &&
1209       ik->is_shared_boot_class() && class_loader.is_null()) {
1210     Handle protection_domain;
1211     return load_shared_class(ik, class_loader, protection_domain, THREAD);
1212   }
1213   return instanceKlassHandle();
1214 }
1215 
1216 // Check if a shared class can be loaded by the specific classloader:
1217 //
1218 // NULL classloader:
1219 //   - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1220 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1221 //     be defined in an unnamed module.
1222 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1223                                                instanceKlassHandle ik,
1224                                                Handle class_loader, TRAPS) {


1225   ResourceMark rm;
1226   int path_index = ik->shared_classpath_index();
1227   SharedClassPathEntry* ent =
1228             (SharedClassPathEntry*)FileMapInfo::shared_classpath(path_index);
1229   if (!Universe::is_module_initialized()) {
1230     assert(ent != NULL && ent->is_jrt(),
1231            "Loading non-bootstrap classes before the module system is initialized");
1232     assert(class_loader.is_null(), "sanity");
1233     return true;
1234   }
1235   // Get the pkg_entry from the classloader
1236   TempNewSymbol pkg_name = NULL;
1237   PackageEntry* pkg_entry = NULL;
1238   ModuleEntry* mod_entry = NULL;
1239   const char* pkg_string = NULL;
1240   ClassLoaderData* loader_data = class_loader_data(class_loader);
1241   pkg_name = InstanceKlass::package_from_name(class_name, CHECK_false);
1242   if (pkg_name != NULL) {
1243     pkg_string = pkg_name->as_C_string();
1244     if (loader_data != NULL) {
1245       pkg_entry = loader_data->packages()->lookup_only(pkg_name);
1246     }
1247     if (pkg_entry != NULL) {
1248       mod_entry = pkg_entry->module();
1249     }






1250   }
1251 
1252   if (class_loader.is_null()) {
1253     assert(ent != NULL, "Shared class for NULL classloader must have valid SharedClassPathEntry");
1254     // The NULL classloader can load archived class originated from the
1255     // "modules" jimage and the -Xbootclasspath/a. For class from the
1256     // "modules" jimage, the PackageEntry/ModuleEntry must be defined
1257     // by the NULL classloader.
1258     if (mod_entry != NULL) {
1259       // PackageEntry/ModuleEntry is found in the classloader. Check if the
1260       // ModuleEntry's location agrees with the archived class' origination.
1261       if (ent->is_jrt() && mod_entry->location()->starts_with("jrt:")) {
1262         return true; // Module class from the "module" jimage
1263       }
1264     }
1265 
1266     // If the archived class is not from the "module" jimage, the class can be
1267     // loaded by the NULL classloader if
1268     //
1269     // 1. the class is from the unamed package




1205                  Symbol* class_name, Handle class_loader, TRAPS) {
1206   instanceKlassHandle ik (THREAD, find_shared_class(class_name));
1207   // Make sure we only return the boot class for the NULL classloader.
1208   if (ik.not_null() &&
1209       ik->is_shared_boot_class() && class_loader.is_null()) {
1210     Handle protection_domain;
1211     return load_shared_class(ik, class_loader, protection_domain, THREAD);
1212   }
1213   return instanceKlassHandle();
1214 }
1215 
1216 // Check if a shared class can be loaded by the specific classloader:
1217 //
1218 // NULL classloader:
1219 //   - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1220 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1221 //     be defined in an unnamed module.
1222 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1223                                                instanceKlassHandle ik,
1224                                                Handle class_loader, TRAPS) {
1225   assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
1226          "Cannot use sharing if java.base is patched");
1227   ResourceMark rm;
1228   int path_index = ik->shared_classpath_index();
1229   SharedClassPathEntry* ent =
1230             (SharedClassPathEntry*)FileMapInfo::shared_classpath(path_index);
1231   if (!Universe::is_module_initialized()) {
1232     assert(ent != NULL && ent->is_jrt(),
1233            "Loading non-bootstrap classes before the module system is initialized");
1234     assert(class_loader.is_null(), "sanity");
1235     return true;
1236   }
1237   // Get the pkg_entry from the classloader
1238   TempNewSymbol pkg_name = NULL;
1239   PackageEntry* pkg_entry = NULL;
1240   ModuleEntry* mod_entry = NULL;
1241   const char* pkg_string = NULL;
1242   ClassLoaderData* loader_data = class_loader_data(class_loader);
1243   pkg_name = InstanceKlass::package_from_name(class_name, CHECK_false);
1244   if (pkg_name != NULL) {
1245     pkg_string = pkg_name->as_C_string();
1246     if (loader_data != NULL) {
1247       pkg_entry = loader_data->packages()->lookup_only(pkg_name);
1248     }
1249     if (pkg_entry != NULL) {
1250       mod_entry = pkg_entry->module();
1251     }
1252   }
1253 
1254   // If the archived class is from a module that has been patched at runtime,
1255   // the class cannot be loaded from the archive.
1256   if (mod_entry != NULL && mod_entry->is_patched()) {
1257     return false;
1258   }
1259 
1260   if (class_loader.is_null()) {
1261     assert(ent != NULL, "Shared class for NULL classloader must have valid SharedClassPathEntry");
1262     // The NULL classloader can load archived class originated from the
1263     // "modules" jimage and the -Xbootclasspath/a. For class from the
1264     // "modules" jimage, the PackageEntry/ModuleEntry must be defined
1265     // by the NULL classloader.
1266     if (mod_entry != NULL) {
1267       // PackageEntry/ModuleEntry is found in the classloader. Check if the
1268       // ModuleEntry's location agrees with the archived class' origination.
1269       if (ent->is_jrt() && mod_entry->location()->starts_with("jrt:")) {
1270         return true; // Module class from the "module" jimage
1271       }
1272     }
1273 
1274     // If the archived class is not from the "module" jimage, the class can be
1275     // loaded by the NULL classloader if
1276     //
1277     // 1. the class is from the unamed package


< prev index next >