Skip to content

Commit

Permalink
8334769: Shenandoah: Move CodeCache_lock close to its use in Shenando…
Browse files Browse the repository at this point in the history
…ahConcurrentNMethodIterator

Reviewed-by: phh
Backport-of: 4ebb77120af5a4ccbfde63b24cb50e05a3161f16
  • Loading branch information
shipilev committed Jul 29, 2024
1 parent 5ed58c2 commit efee05f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
9 changes: 2 additions & 7 deletions src/hotspot/share/gc/shenandoah/shenandoahCodeRoots.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2017, 2021, Red Hat, Inc. All rights reserved.
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2022, Red Hat, Inc. 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
Expand Down Expand Up @@ -163,12 +164,10 @@ class ShenandoahDisarmNMethodsTask : public AbstractGangTask {
AbstractGangTask("Shenandoah Disarm NMethods"),
_iterator(ShenandoahCodeRoots::table()) {
assert(SafepointSynchronize::is_at_safepoint(), "Only at a safepoint");
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_iterator.nmethods_do_begin();
}

~ShenandoahDisarmNMethodsTask() {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_iterator.nmethods_do_end();
}

Expand Down Expand Up @@ -270,12 +269,10 @@ class ShenandoahUnlinkTask : public AbstractGangTask {
_cl(unloading_occurred),
_verifier(verifier),
_iterator(ShenandoahCodeRoots::table()) {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_iterator.nmethods_do_begin();
}

~ShenandoahUnlinkTask() {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_iterator.nmethods_do_end();
}

Expand Down Expand Up @@ -330,12 +327,10 @@ class ShenandoahNMethodPurgeTask : public AbstractGangTask {
AbstractGangTask("Shenandoah Purge NMethods"),
_cl(),
_iterator(ShenandoahCodeRoots::table()) {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_iterator.nmethods_do_begin();
}

~ShenandoahNMethodPurgeTask() {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_iterator.nmethods_do_end();
}

Expand Down
7 changes: 2 additions & 5 deletions src/hotspot/share/gc/shenandoah/shenandoahConcurrentGC.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2021, Red Hat, Inc. All rights reserved.
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2022, Red Hat, Inc. 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
Expand Down Expand Up @@ -750,14 +751,12 @@ class ShenandoahConcurrentWeakRootsEvacUpdateTask : public AbstractGangTask {
_nmethod_itr(ShenandoahCodeRoots::table()),
_phase(phase) {
if (ShenandoahHeap::heap()->unload_classes()) {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_nmethod_itr.nmethods_do_begin();
}
}

~ShenandoahConcurrentWeakRootsEvacUpdateTask() {
if (ShenandoahHeap::heap()->unload_classes()) {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_nmethod_itr.nmethods_do_end();
}
// Notify runtime data structures of potentially dead oops
Expand Down Expand Up @@ -862,14 +861,12 @@ class ShenandoahConcurrentRootsEvacUpdateTask : public AbstractGangTask {
_cld_roots(phase, ShenandoahHeap::heap()->workers()->active_workers()),
_nmethod_itr(ShenandoahCodeRoots::table()) {
if (!ShenandoahHeap::heap()->unload_classes()) {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_nmethod_itr.nmethods_do_begin();
}
}

~ShenandoahConcurrentRootsEvacUpdateTask() {
if (!ShenandoahHeap::heap()->unload_classes()) {
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_nmethod_itr.nmethods_do_end();
}
}
Expand Down
7 changes: 4 additions & 3 deletions src/hotspot/share/gc/shenandoah/shenandoahNMethod.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2019, 2021, Red Hat, Inc. All rights reserved.
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2019, 2022, Red Hat, Inc. 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
Expand Down Expand Up @@ -546,7 +547,7 @@ ShenandoahConcurrentNMethodIterator::ShenandoahConcurrentNMethodIterator(Shenand
}

void ShenandoahConcurrentNMethodIterator::nmethods_do_begin() {
assert(CodeCache_lock->owned_by_self(), "Lock must be held");
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_table_snapshot = _table->snapshot_for_iteration();
}

Expand All @@ -556,7 +557,7 @@ void ShenandoahConcurrentNMethodIterator::nmethods_do(NMethodClosure* cl) {
}

void ShenandoahConcurrentNMethodIterator::nmethods_do_end() {
assert(CodeCache_lock->owned_by_self(), "Lock must be held");
MutexLocker mu(CodeCache_lock, Mutex::_no_safepoint_check_flag);
_table->finish_iteration(_table_snapshot);
CodeCache_lock->notify_all();
}

1 comment on commit efee05f

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.