< prev index next >

src/hotspot/share/classfile/moduleEntry.cpp

Concurrent class unloading

186                         (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);                                                  
187     }                                                                                                                                
188   }                                                                                                                                  
189 }                                                                                                                                    
190 
191 // Set whether the module is open, i.e. all its packages are unqualifiedly exported                                                  
192 void ModuleEntry::set_is_open(bool is_open) {                                                                                        
193   assert_lock_strong(Module_lock);                                                                                                   
194   _is_open = is_open;                                                                                                                
195 }                                                                                                                                    
196 
197 // Returns true if the module has a non-empty reads list. As such, the unnamed                                                       
198 // module will return false.                                                                                                         
199 bool ModuleEntry::has_reads_list() const {                                                                                           
200   assert_locked_or_safepoint(Module_lock);                                                                                           
201   return ((_reads != NULL) && !_reads->is_empty());                                                                                  
202 }                                                                                                                                    
203 
204 // Purge dead module entries out of reads list.                                                                                      
205 void ModuleEntry::purge_reads() {                                                                                                    
206   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");                                                           
207 
208   if (_must_walk_reads && has_reads_list()) {                                                                                        
209     // This module's _must_walk_reads flag will be reset based                                                                       
210     // on the remaining live modules on the reads list.                                                                              
211     _must_walk_reads = false;                                                                                                        
212 
213     if (log_is_enabled(Trace, module)) {                                                                                             
214       ResourceMark rm;                                                                                                               
215       log_trace(module)("ModuleEntry::purge_reads(): module %s reads list being walked",                                             
216                         (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);                                                  
217     }                                                                                                                                
218 
219     // Go backwards because this removes entries that are dead.                                                                      
220     int len = _reads->length();                                                                                                      
221     for (int idx = len - 1; idx >= 0; idx--) {                                                                                       
222       ModuleEntry* module_idx = _reads->at(idx);                                                                                     
223       ClassLoaderData* cld_idx = module_idx->loader_data();                                                                          
224       if (cld_idx->is_unloading()) {                                                                                                 
225         _reads->delete_at(idx);                                                                                                      

186                         (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
187     }
188   }
189 }
190 
191 // Set whether the module is open, i.e. all its packages are unqualifiedly exported
192 void ModuleEntry::set_is_open(bool is_open) {
193   assert_lock_strong(Module_lock);
194   _is_open = is_open;
195 }
196 
197 // Returns true if the module has a non-empty reads list. As such, the unnamed
198 // module will return false.
199 bool ModuleEntry::has_reads_list() const {
200   assert_locked_or_safepoint(Module_lock);
201   return ((_reads != NULL) && !_reads->is_empty());
202 }
203 
204 // Purge dead module entries out of reads list.
205 void ModuleEntry::purge_reads() {
206   assert(UseZGC || SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
207 
208   if (_must_walk_reads && has_reads_list()) {
209     // This module's _must_walk_reads flag will be reset based
210     // on the remaining live modules on the reads list.
211     _must_walk_reads = false;
212 
213     if (log_is_enabled(Trace, module)) {
214       ResourceMark rm;
215       log_trace(module)("ModuleEntry::purge_reads(): module %s reads list being walked",
216                         (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
217     }
218 
219     // Go backwards because this removes entries that are dead.
220     int len = _reads->length();
221     for (int idx = len - 1; idx >= 0; idx--) {
222       ModuleEntry* module_idx = _reads->at(idx);
223       ClassLoaderData* cld_idx = module_idx->loader_data();
224       if (cld_idx->is_unloading()) {
225         _reads->delete_at(idx);

227         // Update the need to walk this module's reads based on live modules                                                         
228         set_read_walk_required(cld_idx);                                                                                             
229       }                                                                                                                              
230     }                                                                                                                                
231   }                                                                                                                                  
232 }                                                                                                                                    
233 
234 void ModuleEntry::module_reads_do(ModuleClosure* f) {                                                                                
235   assert_locked_or_safepoint(Module_lock);                                                                                           
236   assert(f != NULL, "invariant");                                                                                                    
237 
238   if (has_reads_list()) {                                                                                                            
239     int reads_len = _reads->length();                                                                                                
240     for (int i = 0; i < reads_len; ++i) {                                                                                            
241       f->do_module(_reads->at(i));                                                                                                   
242     }                                                                                                                                
243   }                                                                                                                                  
244 }                                                                                                                                    
245 
246 void ModuleEntry::delete_reads() {                                                                                                   
247   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");                                                           
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 ini
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.                                               

227         // Update the need to walk this module's reads based on live modules
228         set_read_walk_required(cld_idx);
229       }
230     }
231   }
232 }
233 
234 void ModuleEntry::module_reads_do(ModuleClosure* f) {
235   assert_locked_or_safepoint(Module_lock);
236   assert(f != NULL, "invariant");
237 
238   if (has_reads_list()) {
239     int reads_len = _reads->length();
240     for (int i = 0; i < reads_len; ++i) {
241       f->do_module(_reads->at(i));
242     }
243   }
244 }
245 
246 void ModuleEntry::delete_reads() {
247   assert(UseZGC || SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
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 ini
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.
< prev index next >