< prev index next >

src/share/vm/classfile/systemDictionary.cpp

Print this page




1193 Klass* SystemDictionary::find_shared_class(Symbol* class_name) {
1194   if (shared_dictionary() != NULL) {
1195     unsigned int d_hash = shared_dictionary()->compute_hash(class_name, NULL);
1196     int d_index = shared_dictionary()->hash_to_index(d_hash);
1197 
1198     return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
1199   } else {
1200     return NULL;
1201   }
1202 }
1203 
1204 
1205 // Load a class from the shared spaces (found through the shared system
1206 // dictionary).  Force the superclass and all interfaces to be loaded.
1207 // Update the class definition to include sibling classes and no
1208 // subclasses (yet).  [Classes in the shared space are not part of the
1209 // object hierarchy until loaded.]
1210 
1211 instanceKlassHandle SystemDictionary::load_shared_class(
1212                  Symbol* class_name, Handle class_loader, TRAPS) {
1213   // Don't load shared class when JvmtiExport::should_post_class_file_load_hook()
1214   // is enabled since posting CFLH is not supported when loading shared class.
1215   if (!JvmtiExport::should_post_class_file_load_hook()) {
1216     instanceKlassHandle ik (THREAD, find_shared_class(class_name));
1217     // Make sure we only return the boot class for the NULL classloader.
1218     if (ik.not_null() &&
1219         ik->is_shared_boot_class() && class_loader.is_null()) {
1220       Handle protection_domain;
1221       return load_shared_class(ik, class_loader, protection_domain, THREAD);
1222     }
1223   }
1224   return instanceKlassHandle();
1225 }
1226 
1227 // Check if a shared class can be loaded by the specific classloader:
1228 //
1229 // NULL classloader:
1230 //   - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1231 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1232 //     be defined in an unnamed module.
1233 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1234                                                instanceKlassHandle ik,
1235                                                Handle class_loader, TRAPS) {
1236   ResourceMark rm;
1237   int path_index = ik->shared_classpath_index();
1238   SharedClassPathEntry* ent =
1239             (SharedClassPathEntry*)FileMapInfo::shared_classpath(path_index);
1240   if (!Universe::is_module_initialized()) {
1241     assert(ent->is_jrt(),
1242            "Loading non-bootstrap classes before the module system is initialized");
1243     assert(class_loader.is_null(), "sanity");


1286           pkg_entry->in_unnamed_module()) {
1287         assert(mod_entry == NULL ||
1288                mod_entry == loader_data->modules()->unnamed_module(),
1289                "the unnamed module is not defined in the classloader");
1290         return true;
1291       }
1292     }
1293     return false;
1294   } else {
1295     bool res = SystemDictionaryShared::is_shared_class_visible_for_classloader(
1296               ik, class_loader, pkg_string, pkg_name,
1297               pkg_entry, mod_entry, CHECK_(false));
1298     return res;
1299   }
1300 }
1301 
1302 instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
1303                                                         Handle class_loader,
1304                                                         Handle protection_domain, TRAPS) {
1305   instanceKlassHandle nh = instanceKlassHandle(); // null Handle
1306   if (JvmtiExport::should_post_class_file_load_hook()) {
1307     // Don't load shared class when JvmtiExport::should_post_class_file_load_hook()
1308     // is enabled since posting CFLH is not supported when loading shared class.
1309     return nh;
1310   }
1311 
1312   if (ik.not_null()) {
1313     Symbol* class_name = ik->name();
1314 
1315     bool visible = is_shared_class_visible(
1316                             class_name, ik, class_loader, CHECK_(nh));
1317     if (!visible) {
1318       return nh;
1319     }
1320 
1321     // Resolve the superclass and interfaces. They must be the same
1322     // as in dump time, because the layout of <ik> depends on
1323     // the specific layout of ik->super() and ik->local_interfaces().
1324     //
1325     // If unexpected superclass or interfaces are found, we cannot
1326     // load <ik> from the shared archive.
1327 
1328     if (ik->super() != NULL) {
1329       Symbol*  cn = ik->super()->name();
1330       Klass *s = resolve_super_or_fail(class_name, cn,


1339     }
1340 
1341     Array<Klass*>* interfaces = ik->local_interfaces();
1342     int num_interfaces = interfaces->length();
1343     for (int index = 0; index < num_interfaces; index++) {
1344       Klass* k = interfaces->at(index);
1345 
1346       // Note: can not use InstanceKlass::cast here because
1347       // interfaces' InstanceKlass's C++ vtbls haven't been
1348       // reinitialized yet (they will be once the interface classes
1349       // are loaded)
1350       Symbol*  name  = k->name();
1351       Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh));
1352       if (k != i) {
1353         // The dynamically resolved interface class is not the same as the one we used during dump time,
1354         // so we cannot use ik.
1355         return nh;
1356       } else {
1357         assert(i->is_shared(), "must be");
1358       }








1359     }
1360 
1361     // Adjust methods to recover missing data.  They need addresses for
1362     // interpreter entry points and their default native method address
1363     // must be reset.
1364 
1365     // Updating methods must be done under a lock so multiple
1366     // threads don't update these in parallel
1367     //
1368     // Shared classes are all currently loaded by either the bootstrap or
1369     // internal parallel class loaders, so this will never cause a deadlock
1370     // on a custom class loader lock.
1371 
1372     ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1373     {
1374       Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1375       check_loader_lock_contention(lockObject, THREAD);
1376       ObjectLocker ol(lockObject, THREAD, true);
1377       // prohibited package check assumes all classes loaded from archive call
1378       // restore_unshareable_info which calls ik->set_package()




1193 Klass* SystemDictionary::find_shared_class(Symbol* class_name) {
1194   if (shared_dictionary() != NULL) {
1195     unsigned int d_hash = shared_dictionary()->compute_hash(class_name, NULL);
1196     int d_index = shared_dictionary()->hash_to_index(d_hash);
1197 
1198     return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
1199   } else {
1200     return NULL;
1201   }
1202 }
1203 
1204 
1205 // Load a class from the shared spaces (found through the shared system
1206 // dictionary).  Force the superclass and all interfaces to be loaded.
1207 // Update the class definition to include sibling classes and no
1208 // subclasses (yet).  [Classes in the shared space are not part of the
1209 // object hierarchy until loaded.]
1210 
1211 instanceKlassHandle SystemDictionary::load_shared_class(
1212                  Symbol* class_name, Handle class_loader, TRAPS) {



1213   instanceKlassHandle ik (THREAD, find_shared_class(class_name));
1214   // Make sure we only return the boot class for the NULL classloader.
1215   if (ik.not_null() &&
1216       ik->is_shared_boot_class() && class_loader.is_null()) {
1217     Handle protection_domain;
1218     return load_shared_class(ik, class_loader, protection_domain, THREAD);
1219   }

1220   return instanceKlassHandle();
1221 }
1222 
1223 // Check if a shared class can be loaded by the specific classloader:
1224 //
1225 // NULL classloader:
1226 //   - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1227 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1228 //     be defined in an unnamed module.
1229 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1230                                                instanceKlassHandle ik,
1231                                                Handle class_loader, TRAPS) {
1232   ResourceMark rm;
1233   int path_index = ik->shared_classpath_index();
1234   SharedClassPathEntry* ent =
1235             (SharedClassPathEntry*)FileMapInfo::shared_classpath(path_index);
1236   if (!Universe::is_module_initialized()) {
1237     assert(ent->is_jrt(),
1238            "Loading non-bootstrap classes before the module system is initialized");
1239     assert(class_loader.is_null(), "sanity");


1282           pkg_entry->in_unnamed_module()) {
1283         assert(mod_entry == NULL ||
1284                mod_entry == loader_data->modules()->unnamed_module(),
1285                "the unnamed module is not defined in the classloader");
1286         return true;
1287       }
1288     }
1289     return false;
1290   } else {
1291     bool res = SystemDictionaryShared::is_shared_class_visible_for_classloader(
1292               ik, class_loader, pkg_string, pkg_name,
1293               pkg_entry, mod_entry, CHECK_(false));
1294     return res;
1295   }
1296 }
1297 
1298 instanceKlassHandle SystemDictionary::load_shared_class(instanceKlassHandle ik,
1299                                                         Handle class_loader,
1300                                                         Handle protection_domain, TRAPS) {
1301   instanceKlassHandle nh = instanceKlassHandle(); // null Handle





1302 
1303   if (ik.not_null()) {
1304     Symbol* class_name = ik->name();
1305 
1306     bool visible = is_shared_class_visible(
1307                             class_name, ik, class_loader, CHECK_(nh));
1308     if (!visible) {
1309       return nh;
1310     }
1311 
1312     // Resolve the superclass and interfaces. They must be the same
1313     // as in dump time, because the layout of <ik> depends on
1314     // the specific layout of ik->super() and ik->local_interfaces().
1315     //
1316     // If unexpected superclass or interfaces are found, we cannot
1317     // load <ik> from the shared archive.
1318 
1319     if (ik->super() != NULL) {
1320       Symbol*  cn = ik->super()->name();
1321       Klass *s = resolve_super_or_fail(class_name, cn,


1330     }
1331 
1332     Array<Klass*>* interfaces = ik->local_interfaces();
1333     int num_interfaces = interfaces->length();
1334     for (int index = 0; index < num_interfaces; index++) {
1335       Klass* k = interfaces->at(index);
1336 
1337       // Note: can not use InstanceKlass::cast here because
1338       // interfaces' InstanceKlass's C++ vtbls haven't been
1339       // reinitialized yet (they will be once the interface classes
1340       // are loaded)
1341       Symbol*  name  = k->name();
1342       Klass* i = resolve_super_or_fail(class_name, name, class_loader, protection_domain, false, CHECK_(nh));
1343       if (k != i) {
1344         // The dynamically resolved interface class is not the same as the one we used during dump time,
1345         // so we cannot use ik.
1346         return nh;
1347       } else {
1348         assert(i->is_shared(), "must be");
1349       }
1350     }
1351 
1352     instanceKlassHandle new_ik = KlassFactory::check_shared_class_file_load_hook(
1353         ik, class_name, class_loader, protection_domain, CHECK_(nh));
1354     if (new_ik.not_null()) {
1355       // The class is changed by CFLH. Return the new class. The shared class is
1356       // not used.
1357       return new_ik;
1358     }
1359 
1360     // Adjust methods to recover missing data.  They need addresses for
1361     // interpreter entry points and their default native method address
1362     // must be reset.
1363 
1364     // Updating methods must be done under a lock so multiple
1365     // threads don't update these in parallel
1366     //
1367     // Shared classes are all currently loaded by either the bootstrap or
1368     // internal parallel class loaders, so this will never cause a deadlock
1369     // on a custom class loader lock.
1370 
1371     ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());
1372     {
1373       Handle lockObject = compute_loader_lock_object(class_loader, THREAD);
1374       check_loader_lock_contention(lockObject, THREAD);
1375       ObjectLocker ol(lockObject, THREAD, true);
1376       // prohibited package check assumes all classes loaded from archive call
1377       // restore_unshareable_info which calls ik->set_package()


< prev index next >