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
189 // Go backwards because this removes entries that are dead.
190 int len = _reads->length();
191 for (int idx = len - 1; idx >= 0; idx--) {
192 ModuleEntry* module_idx = _reads->at(idx);
193 ClassLoaderData* cld_idx = module_idx->loader_data();
194 if (cld_idx->is_unloading()) {
195 _reads->delete_at(idx);
196 } else {
197 // Update the need to walk this module's reads based on live modules
198 set_read_walk_required(cld_idx);
199 }
200 }
201 }
202 }
203
204 void ModuleEntry::module_reads_do(ModuleClosure* const f) {
205 assert_locked_or_safepoint(Module_lock);
206 assert(f != NULL, "invariant");
207
208 if (has_reads()) {
209 int reads_len = _reads->length();
210 for (int i = 0; i < reads_len; ++i) {
211 f->do_module(_reads->at(i));
212 }
213 }
214 }
215
216 void ModuleEntry::delete_reads() {
217 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
218 delete _reads;
219 _reads = NULL;
220 }
221
222 ModuleEntryTable::ModuleEntryTable(int table_size)
223 : Hashtable<Symbol*, mtModule>(table_size, sizeof(ModuleEntry)), _unnamed_module(NULL)
224 {
225 }
226
227 ModuleEntryTable::~ModuleEntryTable() {
228 assert_locked_or_safepoint(Module_lock);
229
230 // Walk through all buckets and all entries in each bucket,
231 // freeing each entry.
232 for (int i = 0; i < table_size(); ++i) {
233 for (ModuleEntry* m = bucket(i); m != NULL;) {
234 ModuleEntry* to_remove = m;
235 // read next before freeing.
236 m = m->next();
237
238 ResourceMark rm;
239 log_debug(modules)("ModuleEntryTable: deleting module: %s", to_remove->name() != NULL ?
240 to_remove->name()->as_C_string() : UNNAMED_MODULE);
241
242 // Clean out the C heap allocated reads list first before freeing the entry
243 to_remove->delete_reads();
244 if (to_remove->name() != NULL) {
245 to_remove->name()->decrement_refcount();
246 }
247 if (to_remove->version() != NULL) {
248 to_remove->version()->decrement_refcount();
|
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 return ((_reads != NULL) && !_reads->is_empty());
171 }
172
173 // Purge dead module entries out of reads list.
174 void ModuleEntry::purge_reads() {
175 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
176
177 if (_must_walk_reads && has_reads()) {
178 // This module's _must_walk_reads flag will be reset based
179 // on the remaining live modules on the reads list.
180 _must_walk_reads = false;
181
182 if (log_is_enabled(Trace, modules)) {
183 ResourceMark rm;
184 log_trace(modules)("ModuleEntry::purge_reads(): module %s reads list being walked",
185 (name() != NULL) ? name()->as_C_string() : UNNAMED_MODULE);
186 }
187
188 // Go backwards because this removes entries that are dead.
189 int len = _reads->length();
190 for (int idx = len - 1; idx >= 0; idx--) {
191 ModuleEntry* module_idx = _reads->at(idx);
192 ClassLoaderData* cld_idx = module_idx->loader_data();
193 if (cld_idx->is_unloading()) {
194 _reads->delete_at(idx);
195 } else {
196 // Update the need to walk this module's reads based on live modules
197 set_read_walk_required(cld_idx);
198 }
199 }
200 }
201 }
202
203 void ModuleEntry::module_reads_do(ModuleClosure* const f) {
204 assert(f != NULL, "invariant");
205 if (has_reads()) {
206 int reads_len = _reads->length();
207 for (int i = 0; i < reads_len; ++i) {
208 f->do_module(_reads->at(i));
209 }
210 }
211 }
212
213 void ModuleEntry::delete_reads() {
214 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
215 delete _reads;
216 _reads = NULL;
217 }
218
219 ModuleEntryTable::ModuleEntryTable(int table_size)
220 : Hashtable<Symbol*, mtModule>(table_size, sizeof(ModuleEntry)), _unnamed_module(NULL)
221 {
222 }
223
224 ModuleEntryTable::~ModuleEntryTable() {
225 assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
226
227 // Walk through all buckets and all entries in each bucket,
228 // freeing each entry.
229 for (int i = 0; i < table_size(); ++i) {
230 for (ModuleEntry* m = bucket(i); m != NULL;) {
231 ModuleEntry* to_remove = m;
232 // read next before freeing.
233 m = m->next();
234
235 ResourceMark rm;
236 log_debug(modules)("ModuleEntryTable: deleting module: %s", to_remove->name() != NULL ?
237 to_remove->name()->as_C_string() : UNNAMED_MODULE);
238
239 // Clean out the C heap allocated reads list first before freeing the entry
240 to_remove->delete_reads();
241 if (to_remove->name() != NULL) {
242 to_remove->name()->decrement_refcount();
243 }
244 if (to_remove->version() != NULL) {
245 to_remove->version()->decrement_refcount();
|