@@ -179,6 +179,7 @@ void ReferenceProcessor::verify_total_count_zero(DiscoveredList lists[], const c
179
179
#endif
180
180
181
181
ReferenceProcessorStats ReferenceProcessor::process_discovered_references (RefProcProxyTask& proxy_task,
182
+ WorkerThreads* workers,
182
183
ReferenceProcessorPhaseTimes& phase_times) {
183
184
184
185
double start_time = os::elapsedTime ();
@@ -197,17 +198,17 @@ ReferenceProcessorStats ReferenceProcessor::process_discovered_references(RefPro
197
198
198
199
{
199
200
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);
201
202
}
202
203
203
204
{
204
205
RefProcTotalPhaseTimesTracker tt (KeepAliveFinalRefsPhase, &phase_times);
205
- process_final_keep_alive (proxy_task, phase_times);
206
+ process_final_keep_alive (proxy_task, workers, phase_times);
206
207
}
207
208
208
209
{
209
210
RefProcTotalPhaseTimesTracker tt (PhantomRefsPhase, &phase_times);
210
- process_phantom_refs (proxy_task, phase_times);
211
+ process_phantom_refs (proxy_task, workers, phase_times);
211
212
}
212
213
213
214
phase_times.set_total_time_ms ((os::elapsedTime () - start_time) * 1000 );
@@ -698,15 +699,14 @@ void ReferenceProcessor::balance_queues(DiscoveredList ref_lists[]) {
698
699
#endif
699
700
}
700
701
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) {
702
703
log_debug (gc, ref)(" ReferenceProcessor::execute queues: %d, %s, marks_oops_alive: %s" ,
703
704
num_queues (),
704
705
processing_is_mt () ? " RefProcThreadModel::Multi" : " RefProcThreadModel::Single" ,
705
706
marks_oops_alive ? " true" : " false" );
706
707
707
708
proxy_task.prepare_run_task (task, num_queues (), processing_is_mt () ? RefProcThreadModel::Multi : RefProcThreadModel::Single, marks_oops_alive);
708
709
if (processing_is_mt ()) {
709
- WorkerThreads* workers = Universe::heap ()->safepoint_workers ();
710
710
assert (workers != nullptr , " can not dispatch multi threaded without workers" );
711
711
assert (workers->active_workers () >= num_queues (),
712
712
" 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
719
719
}
720
720
}
721
721
722
+ static uint num_active_workers (WorkerThreads* workers) {
723
+ return workers != nullptr ? workers->active_workers () : 1 ;
724
+ }
725
+
722
726
void ReferenceProcessor::process_soft_weak_final_refs (RefProcProxyTask& proxy_task,
727
+ WorkerThreads* workers,
723
728
ReferenceProcessorPhaseTimes& phase_times) {
724
729
725
730
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
732
737
return ;
733
738
}
734
739
735
- RefProcMTDegreeAdjuster a (this , SoftWeakFinalRefsPhase, num_total_refs);
740
+ RefProcMTDegreeAdjuster a (this , SoftWeakFinalRefsPhase, num_active_workers (workers), num_total_refs);
736
741
737
742
if (processing_is_mt ()) {
738
743
RefProcBalanceQueuesTimeTracker tt (SoftWeakFinalRefsPhase, &phase_times);
@@ -746,14 +751,15 @@ void ReferenceProcessor::process_soft_weak_final_refs(RefProcProxyTask& proxy_ta
746
751
log_reflist (" SoftWeakFinalRefsPhase Final before" , _discoveredFinalRefs, _max_num_queues);
747
752
748
753
RefProcSoftWeakFinalPhaseTask phase_task (*this , &phase_times);
749
- run_task (phase_task, proxy_task, false );
754
+ run_task (phase_task, proxy_task, workers, false );
750
755
751
756
verify_total_count_zero (_discoveredSoftRefs, " SoftReference" );
752
757
verify_total_count_zero (_discoveredWeakRefs, " WeakReference" );
753
758
log_reflist (" SoftWeakFinalRefsPhase Final after" , _discoveredFinalRefs, _max_num_queues);
754
759
}
755
760
756
761
void ReferenceProcessor::process_final_keep_alive (RefProcProxyTask& proxy_task,
762
+ WorkerThreads* workers,
757
763
ReferenceProcessorPhaseTimes& phase_times) {
758
764
759
765
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,
763
769
return ;
764
770
}
765
771
766
- RefProcMTDegreeAdjuster a (this , KeepAliveFinalRefsPhase, num_final_refs);
772
+ RefProcMTDegreeAdjuster a (this , KeepAliveFinalRefsPhase, num_active_workers (workers), num_final_refs);
767
773
768
774
if (processing_is_mt ()) {
769
775
RefProcBalanceQueuesTimeTracker tt (KeepAliveFinalRefsPhase, &phase_times);
@@ -772,12 +778,13 @@ void ReferenceProcessor::process_final_keep_alive(RefProcProxyTask& proxy_task,
772
778
773
779
// Traverse referents of final references and keep them and followers alive.
774
780
RefProcKeepAliveFinalPhaseTask phase_task (*this , &phase_times);
775
- run_task (phase_task, proxy_task, true );
781
+ run_task (phase_task, proxy_task, workers, true );
776
782
777
783
verify_total_count_zero (_discoveredFinalRefs, " FinalReference" );
778
784
}
779
785
780
786
void ReferenceProcessor::process_phantom_refs (RefProcProxyTask& proxy_task,
787
+ WorkerThreads* workers,
781
788
ReferenceProcessorPhaseTimes& phase_times) {
782
789
783
790
size_t const num_phantom_refs = phase_times.ref_discovered (REF_PHANTOM);
@@ -787,7 +794,7 @@ void ReferenceProcessor::process_phantom_refs(RefProcProxyTask& proxy_task,
787
794
return ;
788
795
}
789
796
790
- RefProcMTDegreeAdjuster a (this , PhantomRefsPhase, num_phantom_refs);
797
+ RefProcMTDegreeAdjuster a (this , PhantomRefsPhase, num_active_workers (workers), num_phantom_refs);
791
798
792
799
if (processing_is_mt ()) {
793
800
RefProcBalanceQueuesTimeTracker tt (PhantomRefsPhase, &phase_times);
@@ -797,7 +804,7 @@ void ReferenceProcessor::process_phantom_refs(RefProcProxyTask& proxy_task,
797
804
log_reflist (" PhantomRefsPhase Phantom before" , _discoveredPhantomRefs, _max_num_queues);
798
805
799
806
RefProcPhantomPhaseTask phase_task (*this , &phase_times);
800
- run_task (phase_task, proxy_task, false );
807
+ run_task (phase_task, proxy_task, workers, false );
801
808
802
809
verify_total_count_zero (_discoveredPhantomRefs, " PhantomReference" );
803
810
}
@@ -1136,10 +1143,11 @@ bool RefProcMTDegreeAdjuster::use_max_threads(RefProcPhases phase) const {
1136
1143
1137
1144
RefProcMTDegreeAdjuster::RefProcMTDegreeAdjuster (ReferenceProcessor* rp,
1138
1145
RefProcPhases phase,
1146
+ uint num_active_workers,
1139
1147
size_t ref_count):
1140
1148
_rp(rp),
1141
1149
_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);
1143
1151
_rp->set_active_mt_degree (workers);
1144
1152
}
1145
1153
0 commit comments