79 _must_walk_exports = true;
80 if (log_is_enabled(Trace, modules)) {
81 ResourceMark rm;
82 assert(name() != NULL, "PackageEntry without a valid name");
83 log_trace(modules)("PackageEntry::set_export_walk_required(): package %s defined in module %s, exports list must be walked",
84 name()->as_C_string(),
85 (this_pkg_mod == NULL || this_pkg_mod->name() == NULL) ?
86 UNNAMED_MODULE : this_pkg_mod->name()->as_C_string());
87 }
88 }
89 }
90
91 // Set the package's exported states based on the value of the ModuleEntry.
92 void PackageEntry::set_exported(ModuleEntry* m) {
93 MutexLocker m1(Module_lock);
94 if (is_unqual_exported()) {
95 // An exception could be thrown, but choose to simply ignore.
96 // Illegal to convert an unqualified exported package to be qualifiedly exported
97 return;
98 }
99
100 if (m == NULL) {
101 // NULL indicates the package is being unqualifiedly exported. Clean up
102 // the qualified list at the next safepoint.
103 set_unqual_exported();
104
105 } else {
106 // Add the exported module
107 add_qexport(m);
108 }
109 }
110
111 // Set the package as exported to all unnamed modules unless the package is
112 // already unqualifiedly exported.
113 void PackageEntry::set_is_exported_allUnnamed() {
114 MutexLocker m1(Module_lock);
115 if (!is_unqual_exported()) {
116 _export_flags = PKG_EXP_ALLUNNAMED;
117 }
118 }
119
120 // Remove dead module entries within the package's exported list. Note that
121 // if all of the modules on the _qualified_exports get purged the list does not
122 // get deleted. This prevents the package from illegally transitioning from
123 // exported to non-exported.
124 void PackageEntry::purge_qualified_exports() {
125 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
126 if (_must_walk_exports &&
127 _qualified_exports != NULL &&
128 !_qualified_exports->is_empty()) {
129 ModuleEntry* pkg_module = module();
130
131 // This package's _must_walk_exports flag will be reset based
132 // on the remaining live modules on the exports list.
133 _must_walk_exports = false;
191 }
192 assert(number_of_entries() == 0, "should have removed all entries");
193 assert(new_entry_free_list() == NULL, "entry present on PackageEntryTable's free list");
194 free_buckets();
195 }
196
197 PackageEntry* PackageEntryTable::new_entry(unsigned int hash, Symbol* name, ModuleEntry* module) {
198 assert(Module_lock->owned_by_self(), "should have the Module_lock");
199 PackageEntry* entry = (PackageEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtModule);
200
201 // Initialize everything BasicHashtable would
202 entry->set_next(NULL);
203 entry->set_hash(hash);
204 entry->set_literal(name);
205
206 TRACE_INIT_ID(entry);
207
208 // Initialize fields specific to a PackageEntry
209 entry->init();
210 entry->name()->increment_refcount();
211 if (!module->is_named()) {
212 // Set the exported state to true because all packages
213 // within the unnamed module are unqualifiedly exported
214 entry->set_unqual_exported();
215 }
216 entry->set_module(module);
217 return entry;
218 }
219
220 void PackageEntryTable::add_entry(int index, PackageEntry* new_entry) {
221 assert(Module_lock->owned_by_self(), "should have the Module_lock");
222 Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
223 }
224
225 // Create package in loader's package entry table and return the entry.
226 // If entry already exists, return null. Assume Module lock was taken by caller.
227 PackageEntry* PackageEntryTable::locked_create_entry_or_null(Symbol* name, ModuleEntry* module) {
228 assert(Module_lock->owned_by_self(), "should have the Module_lock");
229 // Check if package already exists. Return NULL if it does.
230 if (lookup_only(name) != NULL) {
231 return NULL;
232 } else {
233 PackageEntry* entry = new_entry(compute_hash(name), name, module);
234 add_entry(index_for(name), entry);
235 return entry;
|
79 _must_walk_exports = true;
80 if (log_is_enabled(Trace, modules)) {
81 ResourceMark rm;
82 assert(name() != NULL, "PackageEntry without a valid name");
83 log_trace(modules)("PackageEntry::set_export_walk_required(): package %s defined in module %s, exports list must be walked",
84 name()->as_C_string(),
85 (this_pkg_mod == NULL || this_pkg_mod->name() == NULL) ?
86 UNNAMED_MODULE : this_pkg_mod->name()->as_C_string());
87 }
88 }
89 }
90
91 // Set the package's exported states based on the value of the ModuleEntry.
92 void PackageEntry::set_exported(ModuleEntry* m) {
93 MutexLocker m1(Module_lock);
94 if (is_unqual_exported()) {
95 // An exception could be thrown, but choose to simply ignore.
96 // Illegal to convert an unqualified exported package to be qualifiedly exported
97 return;
98 }
99 if (module()->is_open()) {
100 // No-op for open modules since all packages are unqualifiedly exported
101 return;
102 }
103
104 if (m == NULL) {
105 // NULL indicates the package is being unqualifiedly exported. Clean up
106 // the qualified list at the next safepoint.
107 set_unqual_exported();
108 } else {
109 // Add the exported module
110 add_qexport(m);
111 }
112 }
113
114 // Set the package as exported to all unnamed modules unless the package is
115 // already unqualifiedly exported.
116 void PackageEntry::set_is_exported_allUnnamed() {
117 if (module()->is_open()) {
118 // No-op for open modules since all packages are unqualifiedly exported
119 return;
120 }
121
122 MutexLocker m1(Module_lock);
123 if (!is_unqual_exported()) {
124 _export_flags = PKG_EXP_ALLUNNAMED;
125 }
126 }
127
128 // Remove dead module entries within the package's exported list. Note that
129 // if all of the modules on the _qualified_exports get purged the list does not
130 // get deleted. This prevents the package from illegally transitioning from
131 // exported to non-exported.
132 void PackageEntry::purge_qualified_exports() {
133 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
134 if (_must_walk_exports &&
135 _qualified_exports != NULL &&
136 !_qualified_exports->is_empty()) {
137 ModuleEntry* pkg_module = module();
138
139 // This package's _must_walk_exports flag will be reset based
140 // on the remaining live modules on the exports list.
141 _must_walk_exports = false;
199 }
200 assert(number_of_entries() == 0, "should have removed all entries");
201 assert(new_entry_free_list() == NULL, "entry present on PackageEntryTable's free list");
202 free_buckets();
203 }
204
205 PackageEntry* PackageEntryTable::new_entry(unsigned int hash, Symbol* name, ModuleEntry* module) {
206 assert(Module_lock->owned_by_self(), "should have the Module_lock");
207 PackageEntry* entry = (PackageEntry*) NEW_C_HEAP_ARRAY(char, entry_size(), mtModule);
208
209 // Initialize everything BasicHashtable would
210 entry->set_next(NULL);
211 entry->set_hash(hash);
212 entry->set_literal(name);
213
214 TRACE_INIT_ID(entry);
215
216 // Initialize fields specific to a PackageEntry
217 entry->init();
218 entry->name()->increment_refcount();
219 entry->set_module(module);
220 return entry;
221 }
222
223 void PackageEntryTable::add_entry(int index, PackageEntry* new_entry) {
224 assert(Module_lock->owned_by_self(), "should have the Module_lock");
225 Hashtable<Symbol*, mtModule>::add_entry(index, (HashtableEntry<Symbol*, mtModule>*)new_entry);
226 }
227
228 // Create package in loader's package entry table and return the entry.
229 // If entry already exists, return null. Assume Module lock was taken by caller.
230 PackageEntry* PackageEntryTable::locked_create_entry_or_null(Symbol* name, ModuleEntry* module) {
231 assert(Module_lock->owned_by_self(), "should have the Module_lock");
232 // Check if package already exists. Return NULL if it does.
233 if (lookup_only(name) != NULL) {
234 return NULL;
235 } else {
236 PackageEntry* entry = new_entry(compute_hash(name), name, module);
237 add_entry(index_for(name), entry);
238 return entry;
|