187 (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
188 }
189 }
190 }
191
192 // Set whether the module is open, i.e. all its packages are unqualifiedly exported
193 void ModuleEntry::set_is_open(bool is_open) {
194 assert_lock_strong(Module_lock);
195 _is_open = is_open;
196 }
197
198 // Returns true if the module has a non-empty reads list. As such, the unnamed
199 // module will return false.
200 bool ModuleEntry::has_reads_list() const {
201 assert_locked_or_safepoint(Module_lock);
202 return ((_reads != NULL) && !_reads->is_empty());
203 }
204
205 // Purge dead module entries out of reads list.
206 void ModuleEntry::purge_reads() {
207 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
208
209 if (_must_walk_reads && has_reads_list()) {
210 // This module's _must_walk_reads flag will be reset based
211 // on the remaining live modules on the reads list.
212 _must_walk_reads = false;
213
214 if (log_is_enabled(Trace, module)) {
215 ResourceMark rm;
216 log_trace(module)("ModuleEntry::purge_reads(): module %s reads list being walked",
217 (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
218 }
219
220 // Go backwards because this removes entries that are dead.
221 int len = _reads->length();
222 for (int idx = len - 1; idx >= 0; idx--) {
223 ModuleEntry* module_idx = _reads->at(idx);
224 ClassLoaderData* cld_idx = module_idx->loader_data();
225 if (cld_idx->is_unloading()) {
226 _reads->delete_at(idx);
227 } else {
228 // Update the need to walk this module's reads based on live modules
229 set_read_walk_required(cld_idx);
230 }
231 }
232 }
233 }
234
235 void ModuleEntry::module_reads_do(ModuleClosure* f) {
236 assert_locked_or_safepoint(Module_lock);
237 assert(f != NULL, "invariant");
238
239 if (has_reads_list()) {
240 int reads_len = _reads->length();
241 for (int i = 0; i < reads_len; ++i) {
242 f->do_module(_reads->at(i));
243 }
244 }
245 }
246
247 void ModuleEntry::delete_reads() {
248 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
249 delete _reads;
250 _reads = NULL;
251 }
252
253 ModuleEntry* ModuleEntry::create_unnamed_module(ClassLoaderData* cld) {
254 // The java.lang.Module for this loader's
255 // corresponding unnamed module can be found in the java.lang.ClassLoader object.
256 oop module = java_lang_ClassLoader::unnamedModule(cld->class_loader());
257
258 // Ensure that the unnamed module was correctly set when the class loader was constructed.
259 // Guarantee will cause a recognizable crash if the user code has circumvented calling the ClassLoader constructor.
260 ResourceMark rm;
261 guarantee(java_lang_Module::is_instance(module),
262 "The unnamed module for ClassLoader %s, is null or not an instance of java.lang.Module. The class loader has not been initialized correctly.",
263 cld->loader_name_and_id());
264
265 ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(Thread::current(), module), cld);
266
267 // Store pointer to the ModuleEntry in the unnamed module's java.lang.Module object.
268 java_lang_Module::set_module_entry(module, unnamed_module);
302
303 entry->set_loader_data(cld);
304 entry->_is_open = true;
305
306 JFR_ONLY(INIT_ID(entry);)
307
308 return entry;
309 }
310
311 void ModuleEntry::delete_unnamed_module() {
312 // Do not need unlink_entry() since the unnamed module is not in the hashtable
313 FREE_C_HEAP_ARRAY(char, this);
314 }
315
316 ModuleEntryTable::ModuleEntryTable(int table_size)
317 : Hashtable<Symbol*, mtModule>(table_size, sizeof(ModuleEntry))
318 {
319 }
320
321 ModuleEntryTable::~ModuleEntryTable() {
322 assert_locked_or_safepoint(Module_lock);
323
324 // Walk through all buckets and all entries in each bucket,
325 // freeing each entry.
326 for (int i = 0; i < table_size(); ++i) {
327 for (ModuleEntry* m = bucket(i); m != NULL;) {
328 ModuleEntry* to_remove = m;
329 // read next before freeing.
330 m = m->next();
331
332 ResourceMark rm;
333 if (to_remove->name() != NULL) {
334 log_info(module, unload)("unloading module %s", to_remove->name()->as_C_string());
335 }
336 log_debug(module)("ModuleEntryTable: deleting module: %s", to_remove->name() != NULL ?
337 to_remove->name()->as_C_string() : UNNAMED_MODULE);
338
339 // Clean out the C heap allocated reads list first before freeing the entry
340 to_remove->delete_reads();
341 if (to_remove->name() != NULL) {
342 to_remove->name()->decrement_refcount();
343 }
|
187 (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
188 }
189 }
190 }
191
192 // Set whether the module is open, i.e. all its packages are unqualifiedly exported
193 void ModuleEntry::set_is_open(bool is_open) {
194 assert_lock_strong(Module_lock);
195 _is_open = is_open;
196 }
197
198 // Returns true if the module has a non-empty reads list. As such, the unnamed
199 // module will return false.
200 bool ModuleEntry::has_reads_list() const {
201 assert_locked_or_safepoint(Module_lock);
202 return ((_reads != NULL) && !_reads->is_empty());
203 }
204
205 // Purge dead module entries out of reads list.
206 void ModuleEntry::purge_reads() {
207 assert_locked_or_safepoint(Module_lock);
208
209 if (_must_walk_reads && has_reads_list()) {
210 // This module's _must_walk_reads flag will be reset based
211 // on the remaining live modules on the reads list.
212 _must_walk_reads = false;
213
214 if (log_is_enabled(Trace, module)) {
215 ResourceMark rm;
216 log_trace(module)("ModuleEntry::purge_reads(): module %s reads list being walked",
217 (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
218 }
219
220 // Go backwards because this removes entries that are dead.
221 int len = _reads->length();
222 for (int idx = len - 1; idx >= 0; idx--) {
223 ModuleEntry* module_idx = _reads->at(idx);
224 ClassLoaderData* cld_idx = module_idx->loader_data();
225 if (cld_idx->is_unloading()) {
226 _reads->delete_at(idx);
227 } else {
228 // Update the need to walk this module's reads based on live modules
229 set_read_walk_required(cld_idx);
230 }
231 }
232 }
233 }
234
235 void ModuleEntry::module_reads_do(ModuleClosure* f) {
236 assert_locked_or_safepoint(Module_lock);
237 assert(f != NULL, "invariant");
238
239 if (has_reads_list()) {
240 int reads_len = _reads->length();
241 for (int i = 0; i < reads_len; ++i) {
242 f->do_module(_reads->at(i));
243 }
244 }
245 }
246
247 void ModuleEntry::delete_reads() {
248 delete _reads;
249 _reads = NULL;
250 }
251
252 ModuleEntry* ModuleEntry::create_unnamed_module(ClassLoaderData* cld) {
253 // The java.lang.Module for this loader's
254 // corresponding unnamed module can be found in the java.lang.ClassLoader object.
255 oop module = java_lang_ClassLoader::unnamedModule(cld->class_loader());
256
257 // Ensure that the unnamed module was correctly set when the class loader was constructed.
258 // Guarantee will cause a recognizable crash if the user code has circumvented calling the ClassLoader constructor.
259 ResourceMark rm;
260 guarantee(java_lang_Module::is_instance(module),
261 "The unnamed module for ClassLoader %s, is null or not an instance of java.lang.Module. The class loader has not been initialized correctly.",
262 cld->loader_name_and_id());
263
264 ModuleEntry* unnamed_module = new_unnamed_module_entry(Handle(Thread::current(), module), cld);
265
266 // Store pointer to the ModuleEntry in the unnamed module's java.lang.Module object.
267 java_lang_Module::set_module_entry(module, unnamed_module);
301
302 entry->set_loader_data(cld);
303 entry->_is_open = true;
304
305 JFR_ONLY(INIT_ID(entry);)
306
307 return entry;
308 }
309
310 void ModuleEntry::delete_unnamed_module() {
311 // Do not need unlink_entry() since the unnamed module is not in the hashtable
312 FREE_C_HEAP_ARRAY(char, this);
313 }
314
315 ModuleEntryTable::ModuleEntryTable(int table_size)
316 : Hashtable<Symbol*, mtModule>(table_size, sizeof(ModuleEntry))
317 {
318 }
319
320 ModuleEntryTable::~ModuleEntryTable() {
321 // Walk through all buckets and all entries in each bucket,
322 // freeing each entry.
323 for (int i = 0; i < table_size(); ++i) {
324 for (ModuleEntry* m = bucket(i); m != NULL;) {
325 ModuleEntry* to_remove = m;
326 // read next before freeing.
327 m = m->next();
328
329 ResourceMark rm;
330 if (to_remove->name() != NULL) {
331 log_info(module, unload)("unloading module %s", to_remove->name()->as_C_string());
332 }
333 log_debug(module)("ModuleEntryTable: deleting module: %s", to_remove->name() != NULL ?
334 to_remove->name()->as_C_string() : UNNAMED_MODULE);
335
336 // Clean out the C heap allocated reads list first before freeing the entry
337 to_remove->delete_reads();
338 if (to_remove->name() != NULL) {
339 to_remove->name()->decrement_refcount();
340 }
|