Skip to content

Commit 615b759

Browse files
committed
8255070: Shenandoah: Use single thread for concurrent CLD liveness test
Reviewed-by: rkennke
1 parent 6020991 commit 615b759

File tree

3 files changed

+34
-21
lines changed

3 files changed

+34
-21
lines changed

src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1941,7 +1941,7 @@ class ShenandoahConcurrentWeakRootsEvacUpdateTask : public AbstractGangTask {
19411941
ShenandoahVMWeakRoots<true /*concurrent*/> _vm_roots;
19421942

19431943
// Roots related to concurrent class unloading
1944-
ShenandoahClassLoaderDataRoots<true /* concurrent */, false /* single thread*/>
1944+
ShenandoahClassLoaderDataRoots<true /* concurrent */, true /* single thread*/>
19451945
_cld_roots;
19461946
ShenandoahConcurrentNMethodIterator _nmethod_itr;
19471947
ShenandoahConcurrentStringDedupRoots _dedup_roots;

src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class ShenandoahClassLoaderDataRoots {
149149
ShenandoahPhaseTimings::Phase _phase;
150150

151151
static uint worker_count(uint n_workers) {
152+
if (SINGLE_THREADED) return 1u;
153+
152154
// Limit concurrency a bit, otherwise it wastes resources when workers are tripping
153155
// over each other. This also leaves free workers to process other parts of the root
154156
// set, while admitted workers are busy with doing the CLDG walk.
@@ -161,6 +163,10 @@ class ShenandoahClassLoaderDataRoots {
161163

162164
void always_strong_cld_do(CLDClosure* clds, uint worker_id);
163165
void cld_do(CLDClosure* clds, uint worker_id);
166+
167+
private:
168+
typedef void (*CldDo)(CLDClosure*);
169+
void cld_do_impl(CldDo f, CLDClosure* clds, uint worker_id);
164170
};
165171

166172
class ShenandoahRootProcessor : public StackObj {

src/hotspot/share/gc/shenandoah/shenandoahRootProcessor.inline.hpp

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "gc/shenandoah/shenandoahUtils.hpp"
3636
#include "gc/shenandoah/heuristics/shenandoahHeuristics.hpp"
3737
#include "memory/resourceArea.hpp"
38+
#include "runtime/mutexLocker.hpp"
3839
#include "runtime/safepoint.hpp"
3940

4041
template <bool CONCURRENT>
@@ -81,43 +82,49 @@ ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::ShenandoahClassLoad
8182
if (!SINGLE_THREADED) {
8283
ClassLoaderDataGraph::clear_claimed_marks();
8384
}
84-
if (CONCURRENT) {
85+
if (CONCURRENT && !SINGLE_THREADED) {
8586
ClassLoaderDataGraph_lock->lock();
8687
}
88+
89+
// Non-concurrent mode only runs at safepoints by VM thread
90+
assert(CONCURRENT || SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
91+
assert(CONCURRENT || Thread::current()->is_VM_thread(), "Can only be done by VM thread");
8792
}
8893

8994
template <bool CONCURRENT, bool SINGLE_THREADED>
9095
ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::~ShenandoahClassLoaderDataRoots() {
91-
if (CONCURRENT) {
96+
if (CONCURRENT && !SINGLE_THREADED) {
9297
ClassLoaderDataGraph_lock->unlock();
9398
}
9499
}
95100

101+
template <bool CONCURRENT, bool SINGLE_THREADED>
102+
void ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::cld_do_impl(CldDo f, CLDClosure* clds, uint worker_id) {
103+
if (CONCURRENT) {
104+
if (_semaphore.try_acquire()) {
105+
ShenandoahWorkerTimingsTracker timer(_phase, ShenandoahPhaseTimings::CLDGRoots, worker_id);
106+
if (SINGLE_THREADED){
107+
MutexLocker ml(ClassLoaderDataGraph_lock, Mutex::_no_safepoint_check_flag);
108+
f(clds);
109+
} else {
110+
f(clds);
111+
}
112+
_semaphore.claim_all();
113+
}
114+
} else {
115+
f(clds);
116+
}
117+
}
118+
96119

97120
template <bool CONCURRENT, bool SINGLE_THREADED>
98121
void ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::always_strong_cld_do(CLDClosure* clds, uint worker_id) {
99-
if (SINGLE_THREADED) {
100-
assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
101-
assert(Thread::current()->is_VM_thread(), "Single threaded CLDG iteration can only be done by VM thread");
102-
ClassLoaderDataGraph::always_strong_cld_do(clds);
103-
} else if (_semaphore.try_acquire()) {
104-
ShenandoahWorkerTimingsTracker timer(_phase, ShenandoahPhaseTimings::CLDGRoots, worker_id);
105-
ClassLoaderDataGraph::always_strong_cld_do(clds);
106-
_semaphore.claim_all();
107-
}
122+
cld_do_impl(&ClassLoaderDataGraph::always_strong_cld_do, clds, worker_id);
108123
}
109124

110125
template <bool CONCURRENT, bool SINGLE_THREADED>
111126
void ShenandoahClassLoaderDataRoots<CONCURRENT, SINGLE_THREADED>::cld_do(CLDClosure* clds, uint worker_id) {
112-
if (SINGLE_THREADED) {
113-
assert(SafepointSynchronize::is_at_safepoint(), "Must be at a safepoint");
114-
assert(Thread::current()->is_VM_thread(), "Single threaded CLDG iteration can only be done by VM thread");
115-
ClassLoaderDataGraph::cld_do(clds);
116-
} else if (_semaphore.try_acquire()) {
117-
ShenandoahWorkerTimingsTracker timer(_phase, ShenandoahPhaseTimings::CLDGRoots, worker_id);
118-
ClassLoaderDataGraph::cld_do(clds);
119-
_semaphore.claim_all();
120-
}
127+
cld_do_impl(&ClassLoaderDataGraph::cld_do, clds, worker_id);
121128
}
122129

123130
class ShenandoahParallelOopsDoThreadClosure : public ThreadClosure {

0 commit comments

Comments
 (0)