Skip to content
Permalink
Browse files

8235678: Remove unnecessary calls to Thread::current() in MutexLocker…

… calls

Add THREAD argument when available and make Thread* the first argument to relevant MutexLocker and MonitorLocker constructors

Reviewed-by: lfoltan, coleenp, dholmes
  • Loading branch information
Harold Seigel committed Jan 16, 2020
1 parent e2240b7 commit 7fc58a102005b05da6e5956d448e1c063149fe11
Showing with 122 additions and 121 deletions.
  1. +3 −3 src/hotspot/share/c1/c1_Runtime1.cpp
  2. +2 −2 src/hotspot/share/ci/ciEnv.cpp
  3. +2 −2 src/hotspot/share/ci/ciReplay.cpp
  4. +5 −5 src/hotspot/share/classfile/classLoader.cpp
  5. +2 −2 src/hotspot/share/classfile/javaClasses.cpp
  6. +3 −3 src/hotspot/share/classfile/modules.cpp
  7. +25 −25 src/hotspot/share/classfile/systemDictionary.cpp
  8. +4 −4 src/hotspot/share/classfile/systemDictionaryShared.cpp
  9. +8 −8 src/hotspot/share/compiler/compileBroker.cpp
  10. +2 −2 src/hotspot/share/jfr/jni/jfrGetAllEventClasses.cpp
  11. +3 −3 src/hotspot/share/jfr/recorder/checkpoint/jfrCheckpointManager.cpp
  12. +2 −2 src/hotspot/share/jfr/recorder/service/jfrRecorderThread.cpp
  13. +2 −2 src/hotspot/share/jvmci/jvmciRuntime.cpp
  14. +1 −1 src/hotspot/share/memory/filemap.cpp
  15. +6 −6 src/hotspot/share/memory/universe.cpp
  16. +1 −1 src/hotspot/share/oops/instanceKlass.cpp
  17. +2 −2 src/hotspot/share/oops/method.cpp
  18. +2 −2 src/hotspot/share/oops/objArrayKlass.cpp
  19. +2 −2 src/hotspot/share/oops/typeArrayKlass.cpp
  20. +4 −3 src/hotspot/share/prims/jvmtiCodeBlobEvents.cpp
  21. +2 −2 src/hotspot/share/prims/jvmtiEnv.cpp
  22. +2 −2 src/hotspot/share/prims/jvmtiExport.cpp
  23. +5 −5 src/hotspot/share/prims/methodHandles.cpp
  24. +5 −5 src/hotspot/share/prims/whitebox.cpp
  25. +4 −4 src/hotspot/share/runtime/mutexLocker.hpp
  26. +2 −2 src/hotspot/share/runtime/notificationThread.cpp
  27. +2 −2 src/hotspot/share/runtime/os.cpp
  28. +2 −2 src/hotspot/share/runtime/serviceThread.cpp
  29. +2 −2 src/hotspot/share/services/attachListener.cpp
  30. +2 −2 src/hotspot/share/services/diagnosticCommand.cpp
  31. +2 −2 src/hotspot/share/services/diagnosticFramework.cpp
  32. +3 −3 src/hotspot/share/services/lowMemoryDetector.cpp
  33. +2 −2 src/hotspot/share/services/management.cpp
  34. +2 −2 src/hotspot/share/services/memoryManager.cpp
  35. +2 −2 src/hotspot/share/services/memoryPool.cpp
  36. +2 −2 src/hotspot/share/services/nmtDCmd.cpp
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, 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
@@ -1040,7 +1040,7 @@ JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_i
// Now copy code back

{
MutexLocker ml_patch (Patching_lock, Mutex::_no_safepoint_check_flag);
MutexLocker ml_patch (THREAD, Patching_lock, Mutex::_no_safepoint_check_flag);
//
// Deoptimization may have happened while we waited for the lock.
// In that case we don't bother to do any patching we just return
@@ -1259,7 +1259,7 @@ JRT_ENTRY(void, Runtime1::patch_code(JavaThread* thread, Runtime1::StubID stub_i
// If we are patching in a non-perm oop, make sure the nmethod
// is on the right list.
{
MutexLocker ml_code (CodeCache_lock, Mutex::_no_safepoint_check_flag);
MutexLocker ml_code (THREAD, CodeCache_lock, Mutex::_no_safepoint_check_flag);
nmethod* nm = CodeCache::find_nmethod(caller_frame.pc());
guarantee(nm != NULL, "only nmethods can contain non-perm oops");

@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2020, 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
@@ -971,7 +971,7 @@ void ciEnv::register_method(ciMethod* target,
nmethod* nm = NULL;
{
// To prevent compile queue updates.
MutexLocker locker(MethodCompileQueue_lock, THREAD);
MutexLocker locker(THREAD, MethodCompileQueue_lock);

// Prevent SystemDictionary::add_to_hierarchy from running
// and invalidating our dependencies until we install this method.
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2013, 2020, 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
@@ -631,7 +631,7 @@ class CompileReplay : public StackObj {
{
// Grab a lock here to prevent multiple
// MethodData*s from being created.
MutexLocker ml(MethodData_lock, THREAD);
MutexLocker ml(THREAD, MethodData_lock);
if (method->method_data() == NULL) {
ClassLoaderData* loader_data = method->method_holder()->class_loader_data();
MethodData* method_data = MethodData::allocate(loader_data, methodHandle(THREAD, method), CHECK);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, 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
@@ -726,7 +726,7 @@ void ClassLoader::add_to_exploded_build_list(Symbol* module_sym, TRAPS) {
ModuleClassPathList* module_cpl = new ModuleClassPathList(module_sym);
module_cpl->add_to_list(new_entry);
{
MutexLocker ml(Module_lock, THREAD);
MutexLocker ml(THREAD, Module_lock);
_exploded_entries->push(module_cpl);
}
log_info(class, load)("path: %s", path);
@@ -1090,7 +1090,7 @@ objArrayOop ClassLoader::get_system_packages(TRAPS) {
// List of pointers to PackageEntrys that have loaded classes.
GrowableArray<PackageEntry*>* loaded_class_pkgs = new GrowableArray<PackageEntry*>(50);
{
MutexLocker ml(Module_lock, THREAD);
MutexLocker ml(THREAD, Module_lock);

PackageEntryTable* pe_table =
ClassLoaderData::the_null_class_loader_data()->packages();
@@ -1187,7 +1187,7 @@ ClassFileStream* ClassLoader::search_module_entries(const GrowableArray<ModuleCl
// The exploded build entries can be added to at any time so a lock is
// needed when searching them.
assert(!ClassLoader::has_jrt_entry(), "Must be exploded build");
MutexLocker ml(Module_lock, THREAD);
MutexLocker ml(THREAD, Module_lock);
e = find_first_module_cpe(mod_entry, module_list);
} else {
e = find_first_module_cpe(mod_entry, module_list);
@@ -1670,7 +1670,7 @@ void ClassLoader::create_javabase() {
}

{
MutexLocker ml(Module_lock, THREAD);
MutexLocker ml(THREAD, Module_lock);
ModuleEntry* jb_module = null_cld_modules->locked_create_entry(Handle(),
false, vmSymbols::java_base(), NULL, NULL, null_cld);
if (jb_module == NULL) {
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, 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
@@ -882,7 +882,7 @@ void java_lang_Class::set_mirror_module_field(Klass* k, Handle mirror, Handle mo

bool javabase_was_defined = false;
{
MutexLocker m1(Module_lock, THREAD);
MutexLocker m1(THREAD, Module_lock);
// Keep list of classes needing java.base module fixup
if (!ModuleEntryTable::javabase_defined()) {
assert(k->java_mirror() != NULL, "Class's mirror is null");
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2020, 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
@@ -194,7 +194,7 @@ static void define_javabase_module(jobject module, jstring version,

bool duplicate_javabase = false;
{
MutexLocker m1(Module_lock, THREAD);
MutexLocker m1(THREAD, Module_lock);

if (ModuleEntryTable::javabase_defined()) {
duplicate_javabase = true;
@@ -379,7 +379,7 @@ void Modules::define_module(jobject module, jboolean is_open, jstring version,
PackageEntryTable* package_table = NULL;
PackageEntry* existing_pkg = NULL;
{
MutexLocker ml(Module_lock, THREAD);
MutexLocker ml(THREAD, Module_lock);

if (num_packages > 0) {
package_table = get_package_entry_table(h_loader);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2020, 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
@@ -378,7 +378,7 @@ InstanceKlass* SystemDictionary::resolve_super_or_fail(Symbol* child_name,
bool child_already_loaded = false;
bool throw_circularity_error = false;
{
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
InstanceKlass* childk = find_class(d_hash, child_name, dictionary);
InstanceKlass* quicksuperk;
// to support // loading: if child done loading, just return superclass
@@ -424,7 +424,7 @@ InstanceKlass* SystemDictionary::resolve_super_or_fail(Symbol* child_name,
// which keeps the loader_data alive, as well as all instanceKlasses in
// the loader_data. parseClassFile adds the instanceKlass to loader_data.
{
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
placeholders()->find_and_remove(p_index, p_hash, child_name, loader_data, PlaceholderTable::LOAD_SUPER, THREAD);
SystemDictionary_lock->notify_all();
}
@@ -500,7 +500,7 @@ void SystemDictionary::validate_protection_domain(InstanceKlass* klass,
Symbol* kn = klass->name();
unsigned int d_hash = dictionary->compute_hash(kn);

MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
int d_index = dictionary->hash_to_index(d_hash);
dictionary->add_protection_domain(d_index, d_hash, klass,
protection_domain, THREAD);
@@ -587,7 +587,7 @@ InstanceKlass* SystemDictionary::handle_parallel_super_load(
// parallelCapable class loaders do NOT wait for parallel superclass loads to complete
// Serial class loaders and bootstrap classloader do wait for superclass loads
if (!class_loader.is_null() && is_parallelCapable(class_loader)) {
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
// Check if classloading completed while we were loading superclass or waiting
return find_class(d_hash, name, dictionary);
}
@@ -597,7 +597,7 @@ InstanceKlass* SystemDictionary::handle_parallel_super_load(
bool super_load_in_progress = true;
PlaceholderEntry* placeholder;
while (super_load_in_progress) {
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
// Check if classloading completed while we were loading superclass or waiting
InstanceKlass* check = find_class(d_hash, name, dictionary);
if (check != NULL) {
@@ -714,7 +714,7 @@ InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
name->as_C_string(),
class_loader.is_null() ? "null" : class_loader->klass()->name()->as_C_string());
{
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
InstanceKlass* check = find_class(d_hash, name, dictionary);
if (check != NULL) {
// InstanceKlass is already loaded, so just return it
@@ -774,7 +774,7 @@ InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
// Allow parallel classloading of a class/classloader pair

{
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
if (class_loader.is_null() || !is_parallelCapable(class_loader)) {
PlaceholderEntry* oldprobe = placeholders()->get_entry(p_index, p_hash, name, loader_data);
if (oldprobe) {
@@ -861,7 +861,7 @@ InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,

{ // Grabbing the Compile_lock prevents systemDictionary updates
// during compilations.
MutexLocker mu(Compile_lock, THREAD);
MutexLocker mu(THREAD, Compile_lock);
update_dictionary(d_hash, p_index, p_hash,
k, class_loader, THREAD);
}
@@ -879,7 +879,7 @@ InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
// clean up placeholder entries for LOAD_INSTANCE success or error
// This brackets the SystemDictionary updates for both defining
// and initiating loaders
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
placeholders()->find_and_remove(p_index, p_hash, name, loader_data, PlaceholderTable::LOAD_INSTANCE, THREAD);
SystemDictionary_lock->notify_all();
}
@@ -894,7 +894,7 @@ InstanceKlass* SystemDictionary::resolve_instance_class_or_null(Symbol* name,
#ifdef ASSERT
{
ClassLoaderData* loader_data = k->class_loader_data();
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
InstanceKlass* kk = find_class(name, loader_data);
assert(kk == k, "should be present in dictionary");
}
@@ -1026,7 +1026,7 @@ InstanceKlass* SystemDictionary::parse_stream(Symbol* class_name,
k->class_loader_data()->initialize_holder(Handle(THREAD, k->java_mirror()));

{
MutexLocker mu_r(Compile_lock, THREAD);
MutexLocker mu_r(THREAD, Compile_lock);

// Add to class hierarchy, initialize vtables, and do possible
// deoptimizations.
@@ -1144,7 +1144,7 @@ InstanceKlass* SystemDictionary::resolve_from_stream(Symbol* class_name,

// Make sure we have an entry in the SystemDictionary on success
debug_only( {
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);

Klass* check = find_class(h_name, k->class_loader_data());
assert(check == k, "should be present in the dictionary");
@@ -1582,7 +1582,7 @@ void SystemDictionary::define_instance_class(InstanceKlass* k, TRAPS) {
unsigned int p_hash = placeholders()->compute_hash(name_h);
int p_index = placeholders()->hash_to_index(p_hash);

MutexLocker mu_r(Compile_lock, THREAD);
MutexLocker mu_r(THREAD, Compile_lock);

// Add to class hierarchy, initialize vtables, and do possible
// deoptimizations.
@@ -1639,7 +1639,7 @@ InstanceKlass* SystemDictionary::find_or_define_instance_class(Symbol* class_nam
PlaceholderEntry* probe;

{
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
// First check if class already defined
if (is_parallelDefine(class_loader)) {
InstanceKlass* check = find_class(d_hash, name_h, dictionary);
@@ -1680,7 +1680,7 @@ InstanceKlass* SystemDictionary::find_or_define_instance_class(Symbol* class_nam

// definer must notify any waiting threads
{
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
PlaceholderEntry* probe = placeholders()->get_entry(p_index, p_hash, name_h, loader_data);
assert(probe != NULL, "DEFINE_CLASS placeholder lost?");
if (probe != NULL) {
@@ -2066,7 +2066,7 @@ void SystemDictionary::check_constraints(unsigned int d_hash,
Symbol *name = k->name();
ClassLoaderData *loader_data = class_loader_data(class_loader);

MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);

InstanceKlass* check = find_class(d_hash, name, loader_data->dictionary());
if (check != NULL) {
@@ -2131,7 +2131,7 @@ void SystemDictionary::update_dictionary(unsigned int d_hash,
ClassLoaderData *loader_data = class_loader_data(class_loader);

{
MutexLocker mu1(SystemDictionary_lock, THREAD);
MutexLocker mu1(THREAD, SystemDictionary_lock);

// Make a new dictionary entry.
Dictionary* dictionary = loader_data->dictionary();
@@ -2175,15 +2175,15 @@ Klass* SystemDictionary::find_constrained_instance_or_array_klass(
if (t != T_OBJECT) {
klass = Universe::typeArrayKlassObj(t);
} else {
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
klass = constraints()->find_constrained_klass(fd.object_key(), class_loader);
}
// If element class already loaded, allocate array klass
if (klass != NULL) {
klass = klass->array_klass_or_null(fd.dimension());
}
} else {
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
// Non-array classes are easy: simply check the constraint table.
klass = constraints()->find_constrained_klass(class_name, class_loader);
}
@@ -2224,7 +2224,7 @@ bool SystemDictionary::add_loader_constraint(Symbol* class_name,
unsigned int d_hash2 = dictionary2->compute_hash(constraint_name);

{
MutexLocker mu_s(SystemDictionary_lock, THREAD);
MutexLocker mu_s(THREAD, SystemDictionary_lock);
InstanceKlass* klass1 = find_class(d_hash1, constraint_name, dictionary1);
InstanceKlass* klass2 = find_class(d_hash2, constraint_name, dictionary2);
return constraints()->add_entry(constraint_name, klass1, class_loader1,
@@ -2239,7 +2239,7 @@ void SystemDictionary::add_resolution_error(const constantPoolHandle& pool, int
unsigned int hash = resolution_errors()->compute_hash(pool, which);
int index = resolution_errors()->hash_to_index(hash);
{
MutexLocker ml(SystemDictionary_lock, Thread::current());
MutexLocker ml(Thread::current(), SystemDictionary_lock);
resolution_errors()->add_entry(index, hash, pool, which, error, message);
}
}
@@ -2255,7 +2255,7 @@ Symbol* SystemDictionary::find_resolution_error(const constantPoolHandle& pool,
unsigned int hash = resolution_errors()->compute_hash(pool, which);
int index = resolution_errors()->hash_to_index(hash);
{
MutexLocker ml(SystemDictionary_lock, Thread::current());
MutexLocker ml(Thread::current(), SystemDictionary_lock);
ResolutionErrorEntry* entry = resolution_errors()->find_entry(index, hash, pool, which);
if (entry != NULL) {
*message = entry->message();
@@ -2368,7 +2368,7 @@ Method* SystemDictionary::find_method_handle_intrinsic(vmIntrinsics::ID iid,
// Now grab the lock. We might have to throw away the new method,
// if a racing thread has managed to install one at the same time.
{
MutexLocker ml(SystemDictionary_lock, THREAD);
MutexLocker ml(THREAD, SystemDictionary_lock);
spe = invoke_method_table()->find_entry(index, hash, signature, iid);
if (spe == NULL)
spe = invoke_method_table()->add_entry(index, hash, signature, iid);
@@ -2627,7 +2627,7 @@ Handle SystemDictionary::find_method_handle_type(Symbol* signature,

if (can_be_cached) {
// We can cache this MethodType inside the JVM.
MutexLocker ml(SystemDictionary_lock, THREAD);
MutexLocker ml(THREAD, SystemDictionary_lock);
spe = invoke_method_table()->find_entry(index, hash, signature, null_iid);
if (spe == NULL)
spe = invoke_method_table()->add_entry(index, hash, signature, null_iid);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2020, 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
@@ -823,7 +823,7 @@ InstanceKlass* SystemDictionaryShared::find_or_load_shared_class(
ObjectLocker ol(lockObject, THREAD, DoObjectLock);

{
MutexLocker mu(SystemDictionary_lock, THREAD);
MutexLocker mu(THREAD, SystemDictionary_lock);
InstanceKlass* check = find_class(d_hash, name, dictionary);
if (check != NULL) {
return check;
@@ -935,7 +935,7 @@ InstanceKlass* SystemDictionaryShared::acquire_class_for_current_thread(
ClassLoaderData* loader_data = ClassLoaderData::class_loader_data(class_loader());

{
MutexLocker mu(SharedDictionary_lock, THREAD);
MutexLocker mu(THREAD, SharedDictionary_lock);
if (ik->class_loader_data() != NULL) {
// ik is already loaded (by this loader or by a different loader)
// or ik is being loaded by a different thread (by this loader or by a different loader)
@@ -978,7 +978,7 @@ bool SystemDictionaryShared::add_unregistered_class(InstanceKlass* k, TRAPS) {
} else {
bool isnew = _loaded_unregistered_classes.put(name, true);
assert(isnew, "sanity");
MutexLocker mu_r(Compile_lock, THREAD); // add_to_hierarchy asserts this.
MutexLocker mu_r(THREAD, Compile_lock); // add_to_hierarchy asserts this.
SystemDictionary::add_to_hierarchy(k, CHECK_0);
return true;
}

0 comments on commit 7fc58a1

Please sign in to comment.