< prev index next >

src/hotspot/share/classfile/systemDictionary.cpp

Print this page




1172                                       _shared_dictionary_size, t, number_of_entries,
1173                                       false /* explicitly set _resizable to false */);
1174 }
1175 
1176 
1177 // If there is a shared dictionary, then find the entry for the
1178 // given shared system class, if any.
1179 
1180 InstanceKlass* SystemDictionary::find_shared_class(Symbol* class_name) {
1181   if (shared_dictionary() != NULL) {
1182     unsigned int d_hash = shared_dictionary()->compute_hash(class_name);
1183     int d_index = shared_dictionary()->hash_to_index(d_hash);
1184 
1185     return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
1186   } else {
1187     return NULL;
1188   }
1189 }
1190 
1191 
1192 // Load a class from the shared spaces (found through the shared system
1193 // dictionary).  Force the superclass and all interfaces to be loaded.
1194 // Update the class definition to include sibling classes and no
1195 // subclasses (yet).  [Classes in the shared space are not part of the
1196 // object hierarchy until loaded.]
1197 
1198 InstanceKlass* SystemDictionary::load_shared_class(
1199                  Symbol* class_name, Handle class_loader, TRAPS) {
1200   InstanceKlass* ik = find_shared_class(class_name);
1201   // Make sure we only return the boot class for the NULL classloader.
1202   if (ik != NULL &&
1203       ik->is_shared_boot_class() && class_loader.is_null()) {
1204     Handle protection_domain;
1205     return load_shared_class(ik, class_loader, protection_domain, THREAD);
1206   }
1207   return NULL;
1208 }
1209 
1210 // Check if a shared class can be loaded by the specific classloader:
1211 //
1212 // NULL classloader:
1213 //   - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1214 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1215 //     be defined in an unnamed module.
1216 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1217                                                InstanceKlass* ik,
1218                                                Handle class_loader, TRAPS) {
1219   assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
1220          "Cannot use sharing if java.base is patched");
1221   ResourceMark rm;
1222   int path_index = ik->shared_classpath_index();
1223   ClassLoaderData* loader_data = class_loader_data(class_loader);
1224   if (path_index < 0) {
1225     // path_index < 0 indicates that the class is intended for a custom loader


1478         // within a module not defined to the boot loader or in a
1479         // a named package within the unnamed module.  In all cases,
1480         // limit visibility to search for the class only in the boot
1481         // loader's append path.
1482         search_only_bootloader_append = true;
1483       }
1484     }
1485 
1486     // Prior to bootstrapping's module initialization, never load a class outside
1487     // of the boot loader's module path
1488     assert(Universe::is_module_initialized() ||
1489            !search_only_bootloader_append,
1490            "Attempt to load a class outside of boot loader's module path");
1491 
1492     // Search the shared system dictionary for classes preloaded into the
1493     // shared spaces.
1494     InstanceKlass* k = NULL;
1495     {
1496 #if INCLUDE_CDS
1497       PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1498       k = load_shared_class(class_name, class_loader, THREAD);
1499 #endif
1500     }
1501 
1502     if (k == NULL) {
1503       // Use VM class loader
1504       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1505       k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
1506     }
1507 
1508     // find_or_define_instance_class may return a different InstanceKlass
1509     if (k != NULL) {
1510       InstanceKlass* defined_k =
1511         find_or_define_instance_class(class_name, class_loader, k, THREAD);
1512       if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1513         // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1514         assert(defined_k != NULL, "Should have a klass if there's no exception");
1515         loader_data->add_to_deallocate_list(k);
1516         k = defined_k;
1517       } else if (HAS_PENDING_EXCEPTION) {
1518         loader_data->add_to_deallocate_list(k);




1172                                       _shared_dictionary_size, t, number_of_entries,
1173                                       false /* explicitly set _resizable to false */);
1174 }
1175 
1176 
1177 // If there is a shared dictionary, then find the entry for the
1178 // given shared system class, if any.
1179 
1180 InstanceKlass* SystemDictionary::find_shared_class(Symbol* class_name) {
1181   if (shared_dictionary() != NULL) {
1182     unsigned int d_hash = shared_dictionary()->compute_hash(class_name);
1183     int d_index = shared_dictionary()->hash_to_index(d_hash);
1184 
1185     return shared_dictionary()->find_shared_class(d_index, d_hash, class_name);
1186   } else {
1187     return NULL;
1188   }
1189 }
1190 
1191 
1192 // Load a class for boot loader from the shared spaces (found through
1193 // the shared system dictionary). Force the super class and all interfaces
1194 // to be loaded.
1195 InstanceKlass* SystemDictionary::load_shared_boot_class(Symbol* class_name,
1196                                                         TRAPS) {



1197   InstanceKlass* ik = find_shared_class(class_name);
1198   // Make sure we only return the boot class.
1199   if (ik != NULL && ik->is_shared_boot_class()) {
1200     return load_shared_class(ik, Handle(), Handle(), THREAD);


1201   }
1202   return NULL;
1203 }
1204 
1205 // Check if a shared class can be loaded by the specific classloader:
1206 //
1207 // NULL classloader:
1208 //   - Module class from "modules" jimage. ModuleEntry must be defined in the classloader.
1209 //   - Class from -Xbootclasspath/a. The class has no defined PackageEntry, or must
1210 //     be defined in an unnamed module.
1211 bool SystemDictionary::is_shared_class_visible(Symbol* class_name,
1212                                                InstanceKlass* ik,
1213                                                Handle class_loader, TRAPS) {
1214   assert(!ModuleEntryTable::javabase_moduleEntry()->is_patched(),
1215          "Cannot use sharing if java.base is patched");
1216   ResourceMark rm;
1217   int path_index = ik->shared_classpath_index();
1218   ClassLoaderData* loader_data = class_loader_data(class_loader);
1219   if (path_index < 0) {
1220     // path_index < 0 indicates that the class is intended for a custom loader


1473         // within a module not defined to the boot loader or in a
1474         // a named package within the unnamed module.  In all cases,
1475         // limit visibility to search for the class only in the boot
1476         // loader's append path.
1477         search_only_bootloader_append = true;
1478       }
1479     }
1480 
1481     // Prior to bootstrapping's module initialization, never load a class outside
1482     // of the boot loader's module path
1483     assert(Universe::is_module_initialized() ||
1484            !search_only_bootloader_append,
1485            "Attempt to load a class outside of boot loader's module path");
1486 
1487     // Search the shared system dictionary for classes preloaded into the
1488     // shared spaces.
1489     InstanceKlass* k = NULL;
1490     {
1491 #if INCLUDE_CDS
1492       PerfTraceTime vmtimer(ClassLoader::perf_shared_classload_time());
1493       k = load_shared_boot_class(class_name, THREAD);
1494 #endif
1495     }
1496 
1497     if (k == NULL) {
1498       // Use VM class loader
1499       PerfTraceTime vmtimer(ClassLoader::perf_sys_classload_time());
1500       k = ClassLoader::load_class(class_name, search_only_bootloader_append, CHECK_NULL);
1501     }
1502 
1503     // find_or_define_instance_class may return a different InstanceKlass
1504     if (k != NULL) {
1505       InstanceKlass* defined_k =
1506         find_or_define_instance_class(class_name, class_loader, k, THREAD);
1507       if (!HAS_PENDING_EXCEPTION && defined_k != k) {
1508         // If a parallel capable class loader already defined this class, register 'k' for cleanup.
1509         assert(defined_k != NULL, "Should have a klass if there's no exception");
1510         loader_data->add_to_deallocate_list(k);
1511         k = defined_k;
1512       } else if (HAS_PENDING_EXCEPTION) {
1513         loader_data->add_to_deallocate_list(k);


< prev index next >