8259068: Streamline class loader locking

Reviewed-by: dcubed, iklam
This commit is contained in:
Coleen Phillimore 2021-01-15 17:47:33 +00:00
parent 27a39c8d3f
commit 9aa5672af0
6 changed files with 47 additions and 102 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2021, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -1030,23 +1030,12 @@ InstanceKlass* SystemDictionaryShared::find_or_load_shared_class(
THREAD, java_lang_ClassLoader::non_reflection_class_loader(class_loader()));
ClassLoaderData *loader_data = register_loader(class_loader);
Dictionary* dictionary = loader_data->dictionary();
unsigned int d_hash = dictionary->compute_hash(name);
bool DoObjectLock = true;
if (is_parallelCapable(class_loader)) {
DoObjectLock = false;
}
// Make sure we are synchronized on the class loader before we proceed
//
// Note: currently, find_or_load_shared_class is called only from
// JVM_FindLoadedClass and used for PlatformClassLoader and AppClassLoader,
// which are parallel-capable loaders, so this lock is NOT taken.
Handle lockObject = compute_loader_lock_object(THREAD, class_loader);
check_loader_lock_contention(THREAD, lockObject);
ObjectLocker ol(lockObject, THREAD, DoObjectLock);
// which are parallel-capable loaders, so a lock here is NOT taken.
assert(is_parallelCapable(class_loader), "ObjectLocker not required");
{
MutexLocker mu(THREAD, SystemDictionary_lock);
InstanceKlass* check = dictionary->find_class(d_hash, name);
@ -1057,7 +1046,7 @@ InstanceKlass* SystemDictionaryShared::find_or_load_shared_class(
k = load_shared_class_for_builtin_loader(name, class_loader, THREAD);
if (k != NULL) {
define_instance_class(k, CHECK_NULL);
define_instance_class(k, class_loader, CHECK_NULL);
}
}
}