hotspot/src/share/vm/classfile/moduleEntry.cpp
changeset 39616 f82b1f888578
parent 39290 0cc9f5028562
child 39625 8702e5b9bfed
equal deleted inserted replaced
39615:9ab0913a0e65 39616:f82b1f888578
    38 #include "utilities/hashtable.inline.hpp"
    38 #include "utilities/hashtable.inline.hpp"
    39 #include "utilities/ostream.hpp"
    39 #include "utilities/ostream.hpp"
    40 
    40 
    41 ModuleEntry* ModuleEntryTable::_javabase_module = NULL;
    41 ModuleEntry* ModuleEntryTable::_javabase_module = NULL;
    42 
    42 
    43 
       
    44 void ModuleEntry::set_location(Symbol* location) {
    43 void ModuleEntry::set_location(Symbol* location) {
    45   if (_location != NULL) {
    44   if (_location != NULL) {
    46     // _location symbol's refcounts are managed by ModuleEntry,
    45     // _location symbol's refcounts are managed by ModuleEntry,
    47     // must decrement the old one before updating.
    46     // must decrement the old one before updating.
    48     _location->decrement_refcount();
    47     _location->decrement_refcount();
   113   } else {
   112   } else {
   114     if (_reads == NULL) {
   113     if (_reads == NULL) {
   115       // Lazily create a module's reads list
   114       // Lazily create a module's reads list
   116       _reads = new (ResourceObj::C_HEAP, mtModule)GrowableArray<ModuleEntry*>(MODULE_READS_SIZE, true);
   115       _reads = new (ResourceObj::C_HEAP, mtModule)GrowableArray<ModuleEntry*>(MODULE_READS_SIZE, true);
   117     }
   116     }
       
   117 
       
   118     // Determine, based on this newly established read edge to module m,
       
   119     // if this module's read list should be walked at a GC safepoint.
       
   120     set_read_walk_required(m->loader_data());
       
   121 
       
   122     // Establish readability to module m
   118     _reads->append_if_missing(m);
   123     _reads->append_if_missing(m);
       
   124   }
       
   125 }
       
   126 
       
   127 // If the module's loader, that a read edge is being established to, is
       
   128 // not the same loader as this module's and is not one of the 3 builtin
       
   129 // class loaders, then this module's reads list must be walked at GC
       
   130 // safepoint. Modules have the same life cycle as their defining class
       
   131 // loaders and should be removed if dead.
       
   132 void ModuleEntry::set_read_walk_required(ClassLoaderData* m_loader_data) {
       
   133   assert_locked_or_safepoint(Module_lock);
       
   134   if (!_must_walk_reads &&
       
   135       loader_data() != m_loader_data &&
       
   136       !m_loader_data->is_builtin_class_loader_data()) {
       
   137     _must_walk_reads = true;
       
   138     if (log_is_enabled(Trace, modules)) {
       
   139       ResourceMark rm;
       
   140       log_trace(modules)("ModuleEntry::set_read_walk_required(): module %s reads list must be walked",
       
   141                          (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
       
   142     }
   119   }
   143   }
   120 }
   144 }
   121 
   145 
   122 bool ModuleEntry::has_reads() const {
   146 bool ModuleEntry::has_reads() const {
   123   assert_locked_or_safepoint(Module_lock);
   147   assert_locked_or_safepoint(Module_lock);
   125 }
   149 }
   126 
   150 
   127 // Purge dead module entries out of reads list.
   151 // Purge dead module entries out of reads list.
   128 void ModuleEntry::purge_reads() {
   152 void ModuleEntry::purge_reads() {
   129   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
   153   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
   130   if (has_reads()) {
   154 
       
   155   if (_must_walk_reads && has_reads()) {
       
   156     // This module's _must_walk_reads flag will be reset based
       
   157     // on the remaining live modules on the reads list.
       
   158     _must_walk_reads = false;
       
   159 
       
   160     if (log_is_enabled(Trace, modules)) {
       
   161       ResourceMark rm;
       
   162       log_trace(modules)("ModuleEntry::purge_reads(): module %s reads list being walked",
       
   163                          (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
       
   164     }
       
   165 
   131     // Go backwards because this removes entries that are dead.
   166     // Go backwards because this removes entries that are dead.
   132     int len = _reads->length();
   167     int len = _reads->length();
   133     for (int idx = len - 1; idx >= 0; idx--) {
   168     for (int idx = len - 1; idx >= 0; idx--) {
   134       ModuleEntry* module_idx = _reads->at(idx);
   169       ModuleEntry* module_idx = _reads->at(idx);
   135       ClassLoaderData* cld = module_idx->loader();
   170       ClassLoaderData* cld_idx = module_idx->loader_data();
   136       if (cld->is_unloading()) {
   171       if (cld_idx->is_unloading()) {
   137         _reads->delete_at(idx);
   172         _reads->delete_at(idx);
       
   173       } else {
       
   174         // Update the need to walk this module's reads based on live modules
       
   175         set_read_walk_required(cld_idx);
   138       }
   176       }
   139     }
   177     }
   140   }
   178   }
   141 }
   179 }
   142 
   180 
   246 
   284 
   247   if (!module_handle.is_null()) {
   285   if (!module_handle.is_null()) {
   248     entry->set_module(loader_data->add_handle(module_handle));
   286     entry->set_module(loader_data->add_handle(module_handle));
   249   }
   287   }
   250 
   288 
   251   entry->set_loader(loader_data);
   289   entry->set_loader_data(loader_data);
   252   entry->set_version(version);
   290   entry->set_version(version);
   253   entry->set_location(location);
   291   entry->set_location(location);
   254 
   292 
   255   TRACE_INIT_MODULE_ID(entry);
   293   TRACE_INIT_MODULE_ID(entry);
   256 
   294 
   377   ResourceMark rm;
   415   ResourceMark rm;
   378   st->print_cr("entry "PTR_FORMAT" name %s module "PTR_FORMAT" loader %s version %s location %s strict %s next "PTR_FORMAT,
   416   st->print_cr("entry "PTR_FORMAT" name %s module "PTR_FORMAT" loader %s version %s location %s strict %s next "PTR_FORMAT,
   379                p2i(this),
   417                p2i(this),
   380                name() == NULL ? UNNAMED_MODULE : name()->as_C_string(),
   418                name() == NULL ? UNNAMED_MODULE : name()->as_C_string(),
   381                p2i(module()),
   419                p2i(module()),
   382                loader()->loader_name(),
   420                loader_data()->loader_name(),
   383                version() != NULL ? version()->as_C_string() : "NULL",
   421                version() != NULL ? version()->as_C_string() : "NULL",
   384                location() != NULL ? location()->as_C_string() : "NULL",
   422                location() != NULL ? location()->as_C_string() : "NULL",
   385                BOOL_TO_STR(!can_read_all_unnamed()), p2i(next()));
   423                BOOL_TO_STR(!can_read_all_unnamed()), p2i(next()));
   386 }
   424 }
   387 
   425 
   399             "Verify of Module Entry Table failed");
   437             "Verify of Module Entry Table failed");
   400   debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
   438   debug_only(verify_lookup_length((double)number_of_entries() / table_size()));
   401 }
   439 }
   402 
   440 
   403 void ModuleEntry::verify() {
   441 void ModuleEntry::verify() {
   404   guarantee(loader() != NULL, "A module entry must be associated with a loader.");
   442   guarantee(loader_data() != NULL, "A module entry must be associated with a loader.");
   405 }
   443 }