Skip to content

Commit 5e40fb6

Browse files
Thomas Schatzlalbertnetymk
andcommitted
8277394: Remove the use of safepoint_workers in reference processor
Co-authored-by: Albert Mingkun Yang <ayang@openjdk.org> Reviewed-by: ayang, iwalulya
1 parent 2528c62 commit 5e40fb6

File tree

9 files changed

+37
-45
lines changed

9 files changed

+37
-45
lines changed

src/hotspot/share/gc/g1/g1ConcurrentMark.cpp

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,25 +1693,12 @@ void G1ConcurrentMark::weak_refs_work() {
16931693
// Prefer to grow the stack until the max capacity.
16941694
_global_mark_stack.set_should_grow();
16951695

1696-
// We need at least one active thread. If reference processing
1697-
// is not multi-threaded we use the current (VMThread) thread,
1698-
// otherwise we use the workers from the G1CollectedHeap and
1699-
// we utilize all the worker threads we can.
1700-
uint active_workers = (ParallelRefProcEnabled ? _g1h->workers()->active_workers() : 1U);
1701-
active_workers = clamp(active_workers, 1u, _max_num_tasks);
1702-
1703-
// Set the degree of MT processing here. If the discovery was done MT,
1704-
// the number of threads involved during discovery could differ from
1705-
// the number of active workers. This is OK as long as the discovered
1706-
// Reference lists are balanced (see balance_all_queues() and balance_queues()).
1707-
rp->set_active_mt_degree(active_workers);
1708-
17091696
// Parallel processing task executor.
17101697
G1CMRefProcProxyTask task(rp->max_num_queues(), *_g1h, *this);
17111698
ReferenceProcessorPhaseTimes pt(_gc_timer_cm, rp->max_num_queues());
17121699

17131700
// Process the weak references.
1714-
const ReferenceProcessorStats& stats = rp->process_discovered_references(task, pt);
1701+
const ReferenceProcessorStats& stats = rp->process_discovered_references(task, _g1h->workers(), pt);
17151702
_gc_tracer_cm->report_gc_reference_stats(stats);
17161703
pt.print_all_references();
17171704

@@ -1721,8 +1708,6 @@ void G1ConcurrentMark::weak_refs_work() {
17211708

17221709
assert(has_overflown() || _global_mark_stack.is_empty(),
17231710
"Mark stack should be empty (unless it has overflown)");
1724-
1725-
assert(rp->num_queues() == active_workers, "why not");
17261711
}
17271712

17281713
if (has_overflown()) {

src/hotspot/share/gc/g1/g1FullCollector.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -299,18 +299,14 @@ void G1FullCollector::phase1_mark_live_objects() {
299299
}
300300

301301
{
302-
uint old_active_mt_degree = reference_processor()->num_queues();
303-
reference_processor()->set_active_mt_degree(workers());
304302
GCTraceTime(Debug, gc, phases) debug("Phase 1: Reference Processing", scope()->timer());
305303
// Process reference objects found during marking.
306304
ReferenceProcessorPhaseTimes pt(scope()->timer(), reference_processor()->max_num_queues());
307305
G1FullGCRefProcProxyTask task(*this, reference_processor()->max_num_queues());
308-
const ReferenceProcessorStats& stats = reference_processor()->process_discovered_references(task, pt);
306+
const ReferenceProcessorStats& stats = reference_processor()->process_discovered_references(task, _heap->workers(), pt);
309307
scope()->tracer()->report_gc_reference_stats(stats);
310308
pt.print_all_references();
311309
assert(marker(0)->oop_stack()->is_empty(), "Should be no oops on the stack");
312-
313-
reference_processor()->set_active_mt_degree(old_active_mt_degree);
314310
}
315311

316312
{

src/hotspot/share/gc/g1/g1YoungCollector.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -971,12 +971,9 @@ void G1YoungCollector::process_discovered_references(G1ParScanThreadStateSet* pe
971971
ReferenceProcessor* rp = ref_processor_stw();
972972
assert(rp->discovery_enabled(), "should have been enabled");
973973

974-
uint no_of_gc_workers = workers()->active_workers();
975-
rp->set_active_mt_degree(no_of_gc_workers);
976-
977974
G1STWRefProcProxyTask task(rp->max_num_queues(), *_g1h, *per_thread_states, *task_queues());
978975
ReferenceProcessorPhaseTimes& pt = *phase_times()->ref_phase_times();
979-
ReferenceProcessorStats stats = rp->process_discovered_references(task, pt);
976+
ReferenceProcessorStats stats = rp->process_discovered_references(task, _g1h->workers(), pt);
980977

981978
gc_tracer_stw()->report_gc_reference_stats(stats);
982979

src/hotspot/share/gc/parallel/psParallelCompact.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1310,9 +1310,8 @@ void PSParallelCompact::marking_phase(ParallelOldTracer *gc_tracer) {
13101310
ReferenceProcessorStats stats;
13111311
ReferenceProcessorPhaseTimes pt(&_gc_timer, ref_processor()->max_num_queues());
13121312

1313-
ref_processor()->set_active_mt_degree(active_gc_threads);
13141313
ParallelCompactRefProcProxyTask task(ref_processor()->max_num_queues());
1315-
stats = ref_processor()->process_discovered_references(task, pt);
1314+
stats = ref_processor()->process_discovered_references(task, &ParallelScavengeHeap::heap()->workers(), pt);
13161315

13171316
gc_tracer->report_gc_reference_stats(stats);
13181317
pt.print_all_references();

src/hotspot/share/gc/parallel/psScavenge.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -410,12 +410,11 @@ bool PSScavenge::invoke(bool clear_soft_refs) {
410410
{
411411
GCTraceTime(Debug, gc, phases) tm("Reference Processing", &_gc_timer);
412412

413-
reference_processor()->set_active_mt_degree(active_workers);
414413
ReferenceProcessorStats stats;
415414
ReferenceProcessorPhaseTimes pt(&_gc_timer, reference_processor()->max_num_queues());
416415

417416
ParallelScavengeRefProcProxyTask task(reference_processor()->max_num_queues());
418-
stats = reference_processor()->process_discovered_references(task, pt);
417+
stats = reference_processor()->process_discovered_references(task, &ParallelScavengeHeap::heap()->workers(), pt);
419418

420419
_gc_tracer.report_gc_reference_stats(stats);
421420
pt.print_all_references();

src/hotspot/share/gc/serial/defNewGeneration.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,7 @@ bool DefNewGeneration::collect(bool clear_all_soft_refs) {
631631
ReferenceProcessor* rp = ref_processor();
632632
ReferenceProcessorPhaseTimes pt(_gc_timer, rp->max_num_queues());
633633
SerialGCRefProcProxyTask task(is_alive, keep_alive, evacuate_followers);
634-
const ReferenceProcessorStats& stats = rp->process_discovered_references(task, pt);
634+
const ReferenceProcessorStats& stats = rp->process_discovered_references(task, nullptr, pt);
635635
_gc_tracer->report_gc_reference_stats(stats);
636636
_gc_tracer->report_tenuring_threshold(tenuring_threshold());
637637
pt.print_all_references();

src/hotspot/share/gc/serial/serialFullGC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ void SerialFullGC::phase1_mark(bool clear_all_softrefs) {
498498

499499
ReferenceProcessorPhaseTimes pt(_gc_timer, ref_processor()->max_num_queues());
500500
SerialGCRefProcProxyTask task(is_alive, keep_alive, follow_stack_closure);
501-
const ReferenceProcessorStats& stats = ref_processor()->process_discovered_references(task, pt);
501+
const ReferenceProcessorStats& stats = ref_processor()->process_discovered_references(task, nullptr, pt);
502502
pt.print_all_references();
503503
gc_tracer()->report_gc_reference_stats(stats);
504504
}

src/hotspot/share/gc/shared/referenceProcessor.cpp

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ void ReferenceProcessor::verify_total_count_zero(DiscoveredList lists[], const c
179179
#endif
180180

181181
ReferenceProcessorStats ReferenceProcessor::process_discovered_references(RefProcProxyTask& proxy_task,
182+
WorkerThreads* workers,
182183
ReferenceProcessorPhaseTimes& phase_times) {
183184

184185
double start_time = os::elapsedTime();
@@ -197,17 +198,17 @@ ReferenceProcessorStats ReferenceProcessor::process_discovered_references(RefPro
197198

198199
{
199200
RefProcTotalPhaseTimesTracker tt(SoftWeakFinalRefsPhase, &phase_times);
200-
process_soft_weak_final_refs(proxy_task, phase_times);
201+
process_soft_weak_final_refs(proxy_task, workers, phase_times);
201202
}
202203

203204
{
204205
RefProcTotalPhaseTimesTracker tt(KeepAliveFinalRefsPhase, &phase_times);
205-
process_final_keep_alive(proxy_task, phase_times);
206+
process_final_keep_alive(proxy_task, workers, phase_times);
206207
}
207208

208209
{
209210
RefProcTotalPhaseTimesTracker tt(PhantomRefsPhase, &phase_times);
210-
process_phantom_refs(proxy_task, phase_times);
211+
process_phantom_refs(proxy_task, workers, phase_times);
211212
}
212213

213214
phase_times.set_total_time_ms((os::elapsedTime() - start_time) * 1000);
@@ -698,15 +699,14 @@ void ReferenceProcessor::balance_queues(DiscoveredList ref_lists[]) {
698699
#endif
699700
}
700701

701-
void ReferenceProcessor::run_task(RefProcTask& task, RefProcProxyTask& proxy_task, bool marks_oops_alive) {
702+
void ReferenceProcessor::run_task(RefProcTask& task, RefProcProxyTask& proxy_task, WorkerThreads* workers, bool marks_oops_alive) {
702703
log_debug(gc, ref)("ReferenceProcessor::execute queues: %d, %s, marks_oops_alive: %s",
703704
num_queues(),
704705
processing_is_mt() ? "RefProcThreadModel::Multi" : "RefProcThreadModel::Single",
705706
marks_oops_alive ? "true" : "false");
706707

707708
proxy_task.prepare_run_task(task, num_queues(), processing_is_mt() ? RefProcThreadModel::Multi : RefProcThreadModel::Single, marks_oops_alive);
708709
if (processing_is_mt()) {
709-
WorkerThreads* workers = Universe::heap()->safepoint_workers();
710710
assert(workers != nullptr, "can not dispatch multi threaded without workers");
711711
assert(workers->active_workers() >= num_queues(),
712712
"Ergonomically chosen workers(%u) should be less than or equal to active workers(%u)",
@@ -719,7 +719,12 @@ void ReferenceProcessor::run_task(RefProcTask& task, RefProcProxyTask& proxy_tas
719719
}
720720
}
721721

722+
static uint num_active_workers(WorkerThreads* workers) {
723+
return workers != nullptr ? workers->active_workers() : 1;
724+
}
725+
722726
void ReferenceProcessor::process_soft_weak_final_refs(RefProcProxyTask& proxy_task,
727+
WorkerThreads* workers,
723728
ReferenceProcessorPhaseTimes& phase_times) {
724729

725730
size_t const num_soft_refs = phase_times.ref_discovered(REF_SOFT);
@@ -732,7 +737,7 @@ void ReferenceProcessor::process_soft_weak_final_refs(RefProcProxyTask& proxy_ta
732737
return;
733738
}
734739

735-
RefProcMTDegreeAdjuster a(this, SoftWeakFinalRefsPhase, num_total_refs);
740+
RefProcMTDegreeAdjuster a(this, SoftWeakFinalRefsPhase, num_active_workers(workers), num_total_refs);
736741

737742
if (processing_is_mt()) {
738743
RefProcBalanceQueuesTimeTracker tt(SoftWeakFinalRefsPhase, &phase_times);
@@ -746,14 +751,15 @@ void ReferenceProcessor::process_soft_weak_final_refs(RefProcProxyTask& proxy_ta
746751
log_reflist("SoftWeakFinalRefsPhase Final before", _discoveredFinalRefs, _max_num_queues);
747752

748753
RefProcSoftWeakFinalPhaseTask phase_task(*this, &phase_times);
749-
run_task(phase_task, proxy_task, false);
754+
run_task(phase_task, proxy_task, workers, false);
750755

751756
verify_total_count_zero(_discoveredSoftRefs, "SoftReference");
752757
verify_total_count_zero(_discoveredWeakRefs, "WeakReference");
753758
log_reflist("SoftWeakFinalRefsPhase Final after", _discoveredFinalRefs, _max_num_queues);
754759
}
755760

756761
void ReferenceProcessor::process_final_keep_alive(RefProcProxyTask& proxy_task,
762+
WorkerThreads* workers,
757763
ReferenceProcessorPhaseTimes& phase_times) {
758764

759765
size_t const num_final_refs = phase_times.ref_discovered(REF_FINAL);
@@ -763,7 +769,7 @@ void ReferenceProcessor::process_final_keep_alive(RefProcProxyTask& proxy_task,
763769
return;
764770
}
765771

766-
RefProcMTDegreeAdjuster a(this, KeepAliveFinalRefsPhase, num_final_refs);
772+
RefProcMTDegreeAdjuster a(this, KeepAliveFinalRefsPhase, num_active_workers(workers), num_final_refs);
767773

768774
if (processing_is_mt()) {
769775
RefProcBalanceQueuesTimeTracker tt(KeepAliveFinalRefsPhase, &phase_times);
@@ -772,12 +778,13 @@ void ReferenceProcessor::process_final_keep_alive(RefProcProxyTask& proxy_task,
772778

773779
// Traverse referents of final references and keep them and followers alive.
774780
RefProcKeepAliveFinalPhaseTask phase_task(*this, &phase_times);
775-
run_task(phase_task, proxy_task, true);
781+
run_task(phase_task, proxy_task, workers, true);
776782

777783
verify_total_count_zero(_discoveredFinalRefs, "FinalReference");
778784
}
779785

780786
void ReferenceProcessor::process_phantom_refs(RefProcProxyTask& proxy_task,
787+
WorkerThreads* workers,
781788
ReferenceProcessorPhaseTimes& phase_times) {
782789

783790
size_t const num_phantom_refs = phase_times.ref_discovered(REF_PHANTOM);
@@ -787,7 +794,7 @@ void ReferenceProcessor::process_phantom_refs(RefProcProxyTask& proxy_task,
787794
return;
788795
}
789796

790-
RefProcMTDegreeAdjuster a(this, PhantomRefsPhase, num_phantom_refs);
797+
RefProcMTDegreeAdjuster a(this, PhantomRefsPhase, num_active_workers(workers), num_phantom_refs);
791798

792799
if (processing_is_mt()) {
793800
RefProcBalanceQueuesTimeTracker tt(PhantomRefsPhase, &phase_times);
@@ -797,7 +804,7 @@ void ReferenceProcessor::process_phantom_refs(RefProcProxyTask& proxy_task,
797804
log_reflist("PhantomRefsPhase Phantom before", _discoveredPhantomRefs, _max_num_queues);
798805

799806
RefProcPhantomPhaseTask phase_task(*this, &phase_times);
800-
run_task(phase_task, proxy_task, false);
807+
run_task(phase_task, proxy_task, workers, false);
801808

802809
verify_total_count_zero(_discoveredPhantomRefs, "PhantomReference");
803810
}
@@ -1136,10 +1143,11 @@ bool RefProcMTDegreeAdjuster::use_max_threads(RefProcPhases phase) const {
11361143

11371144
RefProcMTDegreeAdjuster::RefProcMTDegreeAdjuster(ReferenceProcessor* rp,
11381145
RefProcPhases phase,
1146+
uint num_active_workers,
11391147
size_t ref_count):
11401148
_rp(rp),
11411149
_saved_num_queues(_rp->num_queues()) {
1142-
uint workers = ergo_proc_thread_count(ref_count, _rp->num_queues(), phase);
1150+
uint workers = ergo_proc_thread_count(ref_count, num_active_workers, phase);
11431151
_rp->set_active_mt_degree(workers);
11441152
}
11451153

src/hotspot/share/gc/shared/referenceProcessor.hpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ class DiscoveredListIterator {
185185
class ReferenceProcessor : public ReferenceDiscoverer {
186186
friend class RefProcTask;
187187
friend class RefProcKeepAliveFinalPhaseTask;
188+
friend class RefProcMTDegreeAdjuster;
188189
public:
189190
// Names of sub-phases of reference processing. Indicates the type of the reference
190191
// processed and the associated phase number at the end.
@@ -253,19 +254,22 @@ class ReferenceProcessor : public ReferenceDiscoverer {
253254
DiscoveredList* _discoveredFinalRefs;
254255
DiscoveredList* _discoveredPhantomRefs;
255256

256-
void run_task(RefProcTask& task, RefProcProxyTask& proxy_task, bool marks_oops_alive);
257+
void run_task(RefProcTask& task, RefProcProxyTask& proxy_task, WorkerThreads* threads, bool marks_oops_alive);
257258

258259
// Drop Soft/Weak/Final references with a null or live referent, and clear
259260
// and enqueue non-Final references.
260261
void process_soft_weak_final_refs(RefProcProxyTask& proxy_task,
262+
WorkerThreads* workers,
261263
ReferenceProcessorPhaseTimes& phase_times);
262264

263265
// Keep alive followers of Final references, and enqueue.
264266
void process_final_keep_alive(RefProcProxyTask& proxy_task,
267+
WorkerThreads* workers,
265268
ReferenceProcessorPhaseTimes& phase_times);
266269

267270
// Drop and keep alive live Phantom references, or clear and enqueue if dead.
268271
void process_phantom_refs(RefProcProxyTask& proxy_task,
272+
WorkerThreads* workers,
269273
ReferenceProcessorPhaseTimes& phase_times);
270274

271275
// Work methods used by the process_* methods. All methods return the number of
@@ -292,12 +296,14 @@ class ReferenceProcessor : public ReferenceDiscoverer {
292296
_always_clear_soft_ref_policy : _default_soft_ref_policy;
293297
_current_soft_ref_policy->setup(); // snapshot the policy threshold
294298
}
299+
300+
void set_active_mt_degree(uint v);
301+
295302
public:
296303
static int number_of_subclasses_of_ref() { return (REF_PHANTOM - REF_NONE); }
297304

298305
uint num_queues() const { return _num_queues; }
299306
uint max_num_queues() const { return _max_num_queues; }
300-
void set_active_mt_degree(uint v);
301307

302308
void start_discovery(bool always_clear) {
303309
enable_discovery();
@@ -416,6 +422,7 @@ class ReferenceProcessor : public ReferenceDiscoverer {
416422
// Process references found during GC (called by the garbage collector)
417423
ReferenceProcessorStats
418424
process_discovered_references(RefProcProxyTask& proxy_task,
425+
WorkerThreads* workers,
419426
ReferenceProcessorPhaseTimes& phase_times);
420427

421428
// If a discovery is in process that is being superseded, abandon it: all
@@ -589,6 +596,7 @@ class RefProcMTDegreeAdjuster : public StackObj {
589596
public:
590597
RefProcMTDegreeAdjuster(ReferenceProcessor* rp,
591598
RefProcPhases phase,
599+
uint num_active_workers,
592600
size_t ref_count);
593601
~RefProcMTDegreeAdjuster();
594602
};

0 commit comments

Comments
 (0)