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,7 +1418,18 @@ bool ClassLoaderDataGraph::do_unloading(bool do_cleaning) {
} }
if (seen_dead_loader) { if (seen_dead_loader) {
data = _head; JFR_ONLY(post_class_unload_events();)
}
log_debug(class, loader, data)("do_unloading: loaders processed %u, loaders removed %u", loaders_processed, loaders_removed);
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) { while (data != NULL) {
// Remove entries in the dictionary of live class loader that have // Remove entries in the dictionary of live class loader that have
// initiated loading classes in a dead class loader. // initiated loading classes in a dead class loader.
@ -1439,12 +1450,6 @@ bool ClassLoaderDataGraph::do_unloading(bool do_cleaning) {
} }
data = data->next(); data = data->next();
} }
JFR_ONLY(post_class_unload_events();)
}
log_debug(class, loader, data)("do_unloading: loaders processed %u, loaders removed %u", loaders_processed, loaders_removed);
return seen_dead_loader;
} }
void ClassLoaderDataGraph::purge() { void ClassLoaderDataGraph::purge() {

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) {