8207778: Add locking to ModuleEntry and PackageEntry tables

Restructure ClassLoaderDataGraph code to simplify using locks in SystemDictionary::do_unloading()

Reviewed-by: lfoltan, coleenp
This commit is contained in:
Harold Seigel 2018-08-10 09:30:26 -04:00
parent 092e9e4f81
commit 83b2fb5b0d
7 changed files with 37 additions and 28 deletions

View file

@ -1418,27 +1418,6 @@ bool ClassLoaderDataGraph::do_unloading(bool do_cleaning) {
} }
if (seen_dead_loader) { if (seen_dead_loader) {
data = _head;
while (data != NULL) {
// Remove entries in the dictionary of live class loader that have
// initiated loading classes in a dead class loader.
if (data->dictionary() != NULL) {
data->dictionary()->do_unloading();
}
// Walk a ModuleEntry's reads, and a PackageEntry's exports
// lists to determine if there are modules on those lists that are now
// dead and should be removed. A module's life cycle is equivalent
// to its defining class loader's life cycle. Since a module is
// considered dead if its class loader is dead, these walks must
// occur after each class loader's aliveness is determined.
if (data->packages() != NULL) {
data->packages()->purge_all_package_exports();
}
if (data->modules_defined()) {
data->modules()->purge_all_module_reads();
}
data = data->next();
}
JFR_ONLY(post_class_unload_events();) JFR_ONLY(post_class_unload_events();)
} }
@ -1447,6 +1426,32 @@ bool ClassLoaderDataGraph::do_unloading(bool do_cleaning) {
return seen_dead_loader; return seen_dead_loader;
} }
// There's at least one dead class loader. Purge refererences of healthy module
// reads lists and package export lists to modules belonging to dead loaders.
void ClassLoaderDataGraph::clean_module_and_package_info() {
ClassLoaderData* data = _head;
while (data != NULL) {
// Remove entries in the dictionary of live class loader that have
// initiated loading classes in a dead class loader.
if (data->dictionary() != NULL) {
data->dictionary()->do_unloading();
}
// Walk a ModuleEntry's reads, and a PackageEntry's exports
// lists to determine if there are modules on those lists that are now
// dead and should be removed. A module's life cycle is equivalent
// to its defining class loader's life cycle. Since a module is
// considered dead if its class loader is dead, these walks must
// occur after each class loader's aliveness is determined.
if (data->packages() != NULL) {
data->packages()->purge_all_package_exports();
}
if (data->modules_defined()) {
data->modules()->purge_all_module_reads();
}
data = data->next();
}
}
void ClassLoaderDataGraph::purge() { void ClassLoaderDataGraph::purge() {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!"); assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint!");
ClassLoaderData* list = _unloading; ClassLoaderData* list = _unloading;

View file

@ -97,6 +97,7 @@ class ClassLoaderDataGraph : public AllStatic {
public: public:
static ClassLoaderData* find_or_create(Handle class_loader); static ClassLoaderData* find_or_create(Handle class_loader);
static void clean_module_and_package_info();
static void purge(); static void purge();
static void clear_claimed_marks(); static void clear_claimed_marks();
// oops do // oops do

View file

@ -65,7 +65,7 @@ void LoaderConstraintTable::free_entry(LoaderConstraintEntry *entry) {
LoaderConstraintEntry** LoaderConstraintTable::find_loader_constraint( LoaderConstraintEntry** LoaderConstraintTable::find_loader_constraint(
Symbol* name, Handle loader) { Symbol* name, Handle loader) {
assert_lock_strong(SystemDictionary_lock);
unsigned int hash = compute_hash(name); unsigned int hash = compute_hash(name);
int index = hash_to_index(hash); int index = hash_to_index(hash);
LoaderConstraintEntry** pp = bucket_addr(index); LoaderConstraintEntry** pp = bucket_addr(index);
@ -89,7 +89,7 @@ LoaderConstraintEntry** LoaderConstraintTable::find_loader_constraint(
void LoaderConstraintTable::purge_loader_constraints() { void LoaderConstraintTable::purge_loader_constraints() {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); assert_locked_or_safepoint(SystemDictionary_lock);
LogTarget(Info, class, loader, constraints) lt; LogTarget(Info, class, loader, constraints) lt;
// Remove unloaded entries from constraint table // Remove unloaded entries from constraint table
for (int index = 0; index < table_size(); index++) { for (int index = 0; index < table_size(); index++) {

View file

@ -436,7 +436,7 @@ ModuleEntry* ModuleEntryTable::lookup_only(Symbol* name) {
// Remove dead modules from all other alive modules' reads list. // Remove dead modules from all other alive modules' reads list.
// This should only occur at class unloading. // This should only occur at class unloading.
void ModuleEntryTable::purge_all_module_reads() { void ModuleEntryTable::purge_all_module_reads() {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); assert_locked_or_safepoint(Module_lock);
for (int i = 0; i < table_size(); i++) { for (int i = 0; i < table_size(); i++) {
for (ModuleEntry* entry = bucket(i); for (ModuleEntry* entry = bucket(i);
entry != NULL; entry != NULL;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2016, 2017, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -302,7 +302,7 @@ bool PackageEntry::exported_pending_delete() const {
// Remove dead entries from all packages' exported list // Remove dead entries from all packages' exported list
void PackageEntryTable::purge_all_package_exports() { void PackageEntryTable::purge_all_package_exports() {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); assert_locked_or_safepoint(Module_lock);
for (int i = 0; i < table_size(); i++) { for (int i = 0; i < table_size(); i++) {
for (PackageEntry* entry = bucket(i); for (PackageEntry* entry = bucket(i);
entry != NULL; entry != NULL;

View file

@ -100,7 +100,7 @@ ResolutionErrorTable::ResolutionErrorTable(int table_size)
// RedefineClasses support - remove matching entry of a // RedefineClasses support - remove matching entry of a
// constant pool that is going away // constant pool that is going away
void ResolutionErrorTable::delete_entry(ConstantPool* c) { void ResolutionErrorTable::delete_entry(ConstantPool* c) {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); assert_locked_or_safepoint(SystemDictionary_lock);
for (int i = 0; i < table_size(); i++) { for (int i = 0; i < table_size(); i++) {
for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) { for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
ResolutionErrorEntry* entry = *p; ResolutionErrorEntry* entry = *p;
@ -118,7 +118,7 @@ void ResolutionErrorTable::delete_entry(ConstantPool* c) {
// Remove unloaded entries from the table // Remove unloaded entries from the table
void ResolutionErrorTable::purge_resolution_errors() { void ResolutionErrorTable::purge_resolution_errors() {
assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); assert_locked_or_safepoint(SystemDictionary_lock);
for (int i = 0; i < table_size(); i++) { for (int i = 0; i < table_size(); i++) {
for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) { for (ResolutionErrorEntry** p = bucket_addr(i); *p != NULL; ) {
ResolutionErrorEntry* entry = *p; ResolutionErrorEntry* entry = *p;

View file

@ -1853,6 +1853,9 @@ bool SystemDictionary::do_unloading(GCTimer* gc_timer,
// First, mark for unload all ClassLoaderData referencing a dead class loader. // First, mark for unload all ClassLoaderData referencing a dead class loader.
unloading_occurred = ClassLoaderDataGraph::do_unloading(do_cleaning); unloading_occurred = ClassLoaderDataGraph::do_unloading(do_cleaning);
if (unloading_occurred) {
ClassLoaderDataGraph::clean_module_and_package_info();
}
} }
if (unloading_occurred) { if (unloading_occurred) {