< prev index next >

src/share/vm/classfile/moduleEntry.cpp

Print this page




 149 
 150 // If the module's loader, that a read edge is being established to, is
 151 // not the same loader as this module's and is not one of the 3 builtin
 152 // class loaders, then this module's reads list must be walked at GC
 153 // safepoint. Modules have the same life cycle as their defining class
 154 // loaders and should be removed if dead.
 155 void ModuleEntry::set_read_walk_required(ClassLoaderData* m_loader_data) {
 156   assert_locked_or_safepoint(Module_lock);
 157   if (!_must_walk_reads &&
 158       loader_data() != m_loader_data &&
 159       !m_loader_data->is_builtin_class_loader_data()) {
 160     _must_walk_reads = true;
 161     if (log_is_enabled(Trace, modules)) {
 162       ResourceMark rm;
 163       log_trace(modules)("ModuleEntry::set_read_walk_required(): module %s reads list must be walked",
 164                          (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
 165     }
 166   }
 167 }
 168 






 169 bool ModuleEntry::has_reads() const {
 170   assert_locked_or_safepoint(Module_lock);
 171   return ((_reads != NULL) && !_reads->is_empty());
 172 }
 173 
 174 // Purge dead module entries out of reads list.
 175 void ModuleEntry::purge_reads() {
 176   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 177 
 178   if (_must_walk_reads && has_reads()) {
 179     // This module's _must_walk_reads flag will be reset based
 180     // on the remaining live modules on the reads list.
 181     _must_walk_reads = false;
 182 
 183     if (log_is_enabled(Trace, modules)) {
 184       ResourceMark rm;
 185       log_trace(modules)("ModuleEntry::purge_reads(): module %s reads list being walked",
 186                          (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
 187     }
 188 


 252       }
 253 
 254       // Unlink from the Hashtable prior to freeing
 255       unlink_entry(to_remove);
 256       FREE_C_HEAP_ARRAY(char, to_remove);
 257     }
 258   }
 259   assert(number_of_entries() == 0, "should have removed all entries");
 260   assert(new_entry_free_list() == NULL, "entry present on ModuleEntryTable's free list");
 261   free_buckets();
 262 }
 263 
 264 void ModuleEntryTable::create_unnamed_module(ClassLoaderData* loader_data) {
 265   assert(Module_lock->owned_by_self(), "should have the Module_lock");
 266 
 267   // Each ModuleEntryTable has exactly one unnamed module
 268   if (loader_data->is_the_null_class_loader_data()) {
 269     // For the boot loader, the java.lang.reflect.Module for the unnamed module
 270     // is not known until a call to JVM_SetBootLoaderUnnamedModule is made. At
 271     // this point initially create the ModuleEntry for the unnamed module.
 272     _unnamed_module = new_entry(0, Handle(NULL), NULL, NULL, NULL, loader_data);
 273   } else {
 274     // For all other class loaders the java.lang.reflect.Module for their
 275     // corresponding unnamed module can be found in the java.lang.ClassLoader object.
 276     oop module = java_lang_ClassLoader::unnamedModule(loader_data->class_loader());
 277     _unnamed_module = new_entry(0, Handle(module), NULL, NULL, NULL, loader_data);
 278 
 279     // Store pointer to the ModuleEntry in the unnamed module's java.lang.reflect.Module
 280     // object.
 281     java_lang_reflect_Module::set_module_entry(module, _unnamed_module);
 282   }
 283 
 284   // Add to bucket 0, no name to hash on
 285   add_entry(0, _unnamed_module);
 286 }
 287 
 288 ModuleEntry* ModuleEntryTable::new_entry(unsigned int hash, Handle module_handle, Symbol* name,

 289                                          Symbol* version, Symbol* location,
 290                                          ClassLoaderData* loader_data) {
 291   assert(Module_lock->owned_by_self(), "should have the Module_lock");
 292   ModuleEntry* entry = (ModuleEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtModule);
 293 
 294   // Initialize everything BasicHashtable would
 295   entry->set_next(NULL);
 296   entry->set_hash(hash);
 297   entry->set_literal(name);
 298 
 299   // Initialize fields specific to a ModuleEntry
 300   entry->init();
 301   if (name != NULL) {
 302     name->increment_refcount();
 303   } else {
 304     // Unnamed modules can read all other unnamed modules.
 305     entry->set_can_read_all_unnamed();
 306   }
 307 
 308   if (!module_handle.is_null()) {
 309     entry->set_module(loader_data->add_handle(module_handle));
 310   }
 311 
 312   entry->set_loader_data(loader_data);
 313   entry->set_version(version);
 314   entry->set_location(location);

 315 
 316   if (ClassLoader::is_in_patch_mod_entries(name)) {
 317     entry->set_is_patched();
 318     if (log_is_enabled(Trace, modules, patch)) {
 319       ResourceMark rm;
 320       log_trace(modules, patch)("Marked module %s as patched from --patch-module", name->as_C_string());
 321     }
 322   }
 323 
 324   TRACE_INIT_ID(entry);
 325 
 326   return entry;
 327 }
 328 
 329 void ModuleEntryTable::add_entry(int index, ModuleEntry* new_entry) {
 330   assert(Module_lock->owned_by_self(), "should have the Module_lock");
 331   Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
 332 }
 333 
 334 ModuleEntry* ModuleEntryTable::locked_create_entry_or_null(Handle module_handle,

 335                                                            Symbol* module_name,
 336                                                            Symbol* module_version,
 337                                                            Symbol* module_location,
 338                                                            ClassLoaderData* loader_data) {
 339   assert(module_name != NULL, "ModuleEntryTable locked_create_entry_or_null should never be called for unnamed module.");
 340   assert(Module_lock->owned_by_self(), "should have the Module_lock");
 341   // Check if module already exists.
 342   if (lookup_only(module_name) != NULL) {
 343     return NULL;
 344   } else {
 345     ModuleEntry* entry = new_entry(compute_hash(module_name), module_handle, module_name,
 346                                    module_version, module_location, loader_data);
 347     add_entry(index_for(module_name), entry);
 348     return entry;
 349   }
 350 }
 351 
 352 // lookup_only by Symbol* to find a ModuleEntry.
 353 ModuleEntry* ModuleEntryTable::lookup_only(Symbol* name) {
 354   if (name == NULL) {
 355     // Return this table's unnamed module
 356     return unnamed_module();
 357   }
 358   int index = index_for(name);
 359   for (ModuleEntry* m = bucket(index); m != NULL; m = m->next()) {
 360     if (m->name()->fast_compare(name) == 0) {
 361       return m;
 362     }
 363   }
 364   return NULL;
 365 }




 149 
 150 // If the module's loader, that a read edge is being established to, is
 151 // not the same loader as this module's and is not one of the 3 builtin
 152 // class loaders, then this module's reads list must be walked at GC
 153 // safepoint. Modules have the same life cycle as their defining class
 154 // loaders and should be removed if dead.
 155 void ModuleEntry::set_read_walk_required(ClassLoaderData* m_loader_data) {
 156   assert_locked_or_safepoint(Module_lock);
 157   if (!_must_walk_reads &&
 158       loader_data() != m_loader_data &&
 159       !m_loader_data->is_builtin_class_loader_data()) {
 160     _must_walk_reads = true;
 161     if (log_is_enabled(Trace, modules)) {
 162       ResourceMark rm;
 163       log_trace(modules)("ModuleEntry::set_read_walk_required(): module %s reads list must be walked",
 164                          (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
 165     }
 166   }
 167 }
 168 
 169 // Set whether the module is open, i.e. all its packages are unqualifiedly exported
 170 void ModuleEntry::set_is_open(bool is_open) {
 171   assert_lock_strong(Module_lock);
 172   _is_open = is_open;
 173 }
 174 
 175 bool ModuleEntry::has_reads() const {
 176   assert_locked_or_safepoint(Module_lock);
 177   return ((_reads != NULL) && !_reads->is_empty());
 178 }
 179 
 180 // Purge dead module entries out of reads list.
 181 void ModuleEntry::purge_reads() {
 182   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 183 
 184   if (_must_walk_reads && has_reads()) {
 185     // This module's _must_walk_reads flag will be reset based
 186     // on the remaining live modules on the reads list.
 187     _must_walk_reads = false;
 188 
 189     if (log_is_enabled(Trace, modules)) {
 190       ResourceMark rm;
 191       log_trace(modules)("ModuleEntry::purge_reads(): module %s reads list being walked",
 192                          (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
 193     }
 194 


 258       }
 259 
 260       // Unlink from the Hashtable prior to freeing
 261       unlink_entry(to_remove);
 262       FREE_C_HEAP_ARRAY(char, to_remove);
 263     }
 264   }
 265   assert(number_of_entries() == 0, "should have removed all entries");
 266   assert(new_entry_free_list() == NULL, "entry present on ModuleEntryTable's free list");
 267   free_buckets();
 268 }
 269 
 270 void ModuleEntryTable::create_unnamed_module(ClassLoaderData* loader_data) {
 271   assert(Module_lock->owned_by_self(), "should have the Module_lock");
 272 
 273   // Each ModuleEntryTable has exactly one unnamed module
 274   if (loader_data->is_the_null_class_loader_data()) {
 275     // For the boot loader, the java.lang.reflect.Module for the unnamed module
 276     // is not known until a call to JVM_SetBootLoaderUnnamedModule is made. At
 277     // this point initially create the ModuleEntry for the unnamed module.
 278     _unnamed_module = new_entry(0, Handle(NULL), true, NULL, NULL, NULL, loader_data);
 279   } else {
 280     // For all other class loaders the java.lang.reflect.Module for their
 281     // corresponding unnamed module can be found in the java.lang.ClassLoader object.
 282     oop module = java_lang_ClassLoader::unnamedModule(loader_data->class_loader());
 283     _unnamed_module = new_entry(0, Handle(module), true, NULL, NULL, NULL, loader_data);
 284 
 285     // Store pointer to the ModuleEntry in the unnamed module's java.lang.reflect.Module
 286     // object.
 287     java_lang_reflect_Module::set_module_entry(module, _unnamed_module);
 288   }
 289 
 290   // Add to bucket 0, no name to hash on
 291   add_entry(0, _unnamed_module);
 292 }
 293 
 294 ModuleEntry* ModuleEntryTable::new_entry(unsigned int hash, Handle module_handle,
 295                                          bool is_open, Symbol* name,
 296                                          Symbol* version, Symbol* location,
 297                                          ClassLoaderData* loader_data) {
 298   assert(Module_lock->owned_by_self(), "should have the Module_lock");
 299   ModuleEntry* entry = (ModuleEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtModule);
 300 
 301   // Initialize everything BasicHashtable would
 302   entry->set_next(NULL);
 303   entry->set_hash(hash);
 304   entry->set_literal(name);
 305 
 306   // Initialize fields specific to a ModuleEntry
 307   entry->init();
 308   if (name != NULL) {
 309     name->increment_refcount();
 310   } else {
 311     // Unnamed modules can read all other unnamed modules.
 312     entry->set_can_read_all_unnamed();
 313   }
 314 
 315   if (!module_handle.is_null()) {
 316     entry->set_module(loader_data->add_handle(module_handle));
 317   }
 318 
 319   entry->set_loader_data(loader_data);
 320   entry->set_version(version);
 321   entry->set_location(location);
 322   entry->set_is_open(is_open);
 323 
 324   if (ClassLoader::is_in_patch_mod_entries(name)) {
 325     entry->set_is_patched();
 326     if (log_is_enabled(Trace, modules, patch)) {
 327       ResourceMark rm;
 328       log_trace(modules, patch)("Marked module %s as patched from --patch-module", name->as_C_string());
 329     }
 330   }
 331 
 332   TRACE_INIT_ID(entry);
 333 
 334   return entry;
 335 }
 336 
 337 void ModuleEntryTable::add_entry(int index, ModuleEntry* new_entry) {
 338   assert(Module_lock->owned_by_self(), "should have the Module_lock");
 339   Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
 340 }
 341 
 342 ModuleEntry* ModuleEntryTable::locked_create_entry_or_null(Handle module_handle,
 343                                                            bool is_open,
 344                                                            Symbol* module_name,
 345                                                            Symbol* module_version,
 346                                                            Symbol* module_location,
 347                                                            ClassLoaderData* loader_data) {
 348   assert(module_name != NULL, "ModuleEntryTable locked_create_entry_or_null should never be called for unnamed module.");
 349   assert(Module_lock->owned_by_self(), "should have the Module_lock");
 350   // Check if module already exists.
 351   if (lookup_only(module_name) != NULL) {
 352     return NULL;
 353   } else {
 354     ModuleEntry* entry = new_entry(compute_hash(module_name), module_handle, is_open, module_name,
 355                                    module_version, module_location, loader_data);
 356     add_entry(index_for(module_name), entry);
 357     return entry;
 358   }
 359 }
 360 
 361 // lookup_only by Symbol* to find a ModuleEntry.
 362 ModuleEntry* ModuleEntryTable::lookup_only(Symbol* name) {
 363   if (name == NULL) {
 364     // Return this table's unnamed module
 365     return unnamed_module();
 366   }
 367   int index = index_for(name);
 368   for (ModuleEntry* m = bucket(index); m != NULL; m = m->next()) {
 369     if (m->name()->fast_compare(name) == 0) {
 370       return m;
 371     }
 372   }
 373   return NULL;
 374 }


< prev index next >