8213092: Add more runtime locks for concurrent class unloading

Add locks for calling CLDG::purge concurrently as well and for calling SystemDictionary::do_unloading concurrently.

Reviewed-by: eosterlund, hseigel
This commit is contained in:
Coleen Phillimore 2018-11-16 10:54:04 -05:00
parent dce8ff4dba
commit 673c68d993
6 changed files with 36 additions and 43 deletions

View file

@ -125,7 +125,7 @@ void PackageEntry::set_is_exported_allUnnamed() {
// get deleted. This prevents the package from illegally transitioning from
// exported to non-exported.
void PackageEntry::purge_qualified_exports() {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
assert_locked_or_safepoint(Module_lock);
if (_must_walk_exports &&
_qualified_exports != NULL &&
!_qualified_exports->is_empty()) {
@ -160,7 +160,6 @@ void PackageEntry::purge_qualified_exports() {
}
void PackageEntry::delete_qualified_exports() {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
if (_qualified_exports != NULL) {
delete _qualified_exports;
}
@ -228,29 +227,20 @@ PackageEntry* PackageEntryTable::locked_create_entry_or_null(Symbol* name, Modul
}
PackageEntry* PackageEntryTable::lookup(Symbol* name, ModuleEntry* module) {
MutexLocker ml(Module_lock);
PackageEntry* p = lookup_only(name);
if (p != NULL) {
return p;
} else {
// If not found, add to table. Grab the PackageEntryTable lock first.
MutexLocker ml(Module_lock);
// Since look-up was done lock-free, we need to check if another thread beat
// us in the race to insert the package.
PackageEntry* test = lookup_only(name);
if (test != NULL) {
// A race occurred and another thread introduced the package.
return test;
} else {
assert(module != NULL, "module should never be null");
PackageEntry* entry = new_entry(compute_hash(name), name, module);
add_entry(index_for(name), entry);
return entry;
}
assert(module != NULL, "module should never be null");
PackageEntry* entry = new_entry(compute_hash(name), name, module);
add_entry(index_for(name), entry);
return entry;
}
}
PackageEntry* PackageEntryTable::lookup_only(Symbol* name) {
MutexLockerEx ml(Module_lock->owned_by_self() ? NULL : Module_lock);
int index = index_for(name);
for (PackageEntry* p = bucket(index); p != NULL; p = p->next()) {
if (p->name()->fast_compare(name) == 0) {
@ -296,7 +286,7 @@ void PackageEntry::package_exports_do(ModuleClosure* f) {
}
bool PackageEntry::exported_pending_delete() const {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
assert_locked_or_safepoint(Module_lock);
return (is_unqual_exported() && _qualified_exports != NULL);
}