@@ -179,6 +179,7 @@ void ReferenceProcessor::verify_total_count_zero(DiscoveredList lists[], const c
179179#endif
180180
181181ReferenceProcessorStats 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+
722726void 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
756761void 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
780786void 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
11371144RefProcMTDegreeAdjuster::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
0 commit comments