--- a/src/hotspot/share/classfile/packageEntry.cpp Fri Nov 16 07:30:40 2018 -0500
+++ b/src/hotspot/share/classfile/packageEntry.cpp Fri Nov 16 10:54:04 2018 -0500
@@ -125,7 +125,7 @@
// 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::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::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 @@
}
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);
}