diff --git a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp index 2368b5b4fc432..48291e5828b15 100644 --- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp +++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp @@ -64,7 +64,6 @@ #include "gc/g1/g1RemSet.hpp" #include "gc/g1/g1ReviseYoungLengthTask.hpp" #include "gc/g1/g1RootClosures.hpp" -#include "gc/g1/g1RootProcessor.hpp" #include "gc/g1/g1SATBMarkQueueSet.hpp" #include "gc/g1/g1ServiceThread.hpp" #include "gc/g1/g1ThreadLocalData.hpp" diff --git a/src/hotspot/share/gc/g1/g1HeapVerifier.cpp b/src/hotspot/share/gc/g1/g1HeapVerifier.cpp index 21b3545f7e087..a64989e375575 100644 --- a/src/hotspot/share/gc/g1/g1HeapVerifier.cpp +++ b/src/hotspot/share/gc/g1/g1HeapVerifier.cpp @@ -343,7 +343,7 @@ void G1HeapVerifier::verify(VerifyOption vo) { G1VerifyCodeRootNMethodClosure blobsCl(&codeRootsCl); { - G1RootProcessor root_processor(_g1h, 1); + G1RootProcessor root_processor(_g1h, false /* is_parallel */); root_processor.process_all_roots(&rootsCl, &cldCl, &blobsCl); } diff --git a/src/hotspot/share/gc/g1/g1RootProcessor.cpp b/src/hotspot/share/gc/g1/g1RootProcessor.cpp index cf28c53648d74..dac237cb2775b 100644 --- a/src/hotspot/share/gc/g1/g1RootProcessor.cpp +++ b/src/hotspot/share/gc/g1/g1RootProcessor.cpp @@ -46,10 +46,12 @@ #include "utilities/enumIterator.hpp" #include "utilities/macros.hpp" -G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h, uint n_workers) : +G1RootProcessor::G1RootProcessor(G1CollectedHeap* g1h, bool is_parallel) : _g1h(g1h), _process_strong_tasks(G1RP_PS_NumElements), - _srs(n_workers) {} + _nmethod_marking_scope(), + _threads_claim_token_scope(), + _is_parallel(is_parallel) {} void G1RootProcessor::evacuate_roots(G1ParScanThreadState* pss, uint worker_id) { G1GCPhaseTimes* phase_times = _g1h->phase_times(); @@ -175,8 +177,7 @@ void G1RootProcessor::process_java_roots(G1RootClosures* closures, // oops_do_process_weak and oops_do_process_strong in nmethod.hpp { G1GCParPhaseTimesTracker x(phase_times, G1GCPhaseTimes::ThreadRoots, worker_id); - bool is_par = n_workers() > 1; - Threads::possibly_parallel_oops_do(is_par, + Threads::possibly_parallel_oops_do(_is_parallel, closures->strong_oops(), closures->strong_nmethods()); } @@ -209,7 +210,3 @@ void G1RootProcessor::process_code_cache_roots(NMethodClosure* nmethod_closure, CodeCache::nmethods_do(nmethod_closure); } } - -uint G1RootProcessor::n_workers() const { - return _srs.n_threads(); -} diff --git a/src/hotspot/share/gc/g1/g1RootProcessor.hpp b/src/hotspot/share/gc/g1/g1RootProcessor.hpp index 2313fd62f20c0..27c92d730cf58 100644 --- a/src/hotspot/share/gc/g1/g1RootProcessor.hpp +++ b/src/hotspot/share/gc/g1/g1RootProcessor.hpp @@ -25,10 +25,11 @@ #ifndef SHARE_GC_G1_G1ROOTPROCESSOR_HPP #define SHARE_GC_G1_G1ROOTPROCESSOR_HPP +#include "code/nmethod.hpp" #include "gc/shared/oopStorageSetParState.hpp" -#include "gc/shared/strongRootsScope.hpp" #include "memory/allocation.hpp" #include "runtime/mutex.hpp" +#include "runtime/threads.hpp" class CLDClosure; class G1CollectedHeap; @@ -48,7 +49,9 @@ class SubTasksDone; class G1RootProcessor : public StackObj { G1CollectedHeap* _g1h; SubTasksDone _process_strong_tasks; - StrongRootsScope _srs; + NMethodMarkingScope _nmethod_marking_scope; + ThreadsClaimTokenScope _threads_claim_token_scope; + bool _is_parallel; OopStorageSetStrongParState _oop_storage_set_strong_par_state; enum G1H_process_roots_tasks { @@ -72,7 +75,7 @@ class G1RootProcessor : public StackObj { uint worker_id); public: - G1RootProcessor(G1CollectedHeap* g1h, uint n_workers); + G1RootProcessor(G1CollectedHeap* g1h, bool is_parallel); // Apply correct closures from pss to the strongly and weakly reachable roots in the system // in a single pass. @@ -88,9 +91,6 @@ class G1RootProcessor : public StackObj { void process_all_roots(OopClosure* oops, CLDClosure* clds, NMethodClosure* nmethods); - - // Number of worker threads used by the root processor. - uint n_workers() const; }; #endif // SHARE_GC_G1_G1ROOTPROCESSOR_HPP diff --git a/src/hotspot/share/gc/g1/g1YoungCollector.cpp b/src/hotspot/share/gc/g1/g1YoungCollector.cpp index 6a7d4717a6f24..54ff46cb259bd 100644 --- a/src/hotspot/share/gc/g1/g1YoungCollector.cpp +++ b/src/hotspot/share/gc/g1/g1YoungCollector.cpp @@ -52,6 +52,7 @@ #include "gc/shared/gcTimer.hpp" #include "gc/shared/gcTraceTime.inline.hpp" #include "gc/shared/referenceProcessor.hpp" +#include "gc/shared/strongRootsScope.hpp" #include "gc/shared/weakProcessor.inline.hpp" #include "gc/shared/workerPolicy.hpp" #include "gc/shared/workerThread.hpp" @@ -750,7 +751,7 @@ void G1YoungCollector::evacuate_initial_collection_set(G1ParScanThreadStateSet* Ticks start_processing = Ticks::now(); { - G1RootProcessor root_processor(_g1h, num_workers); + G1RootProcessor root_processor(_g1h, num_workers > 1 /* is_parallel */); G1EvacuateRegionsTask g1_par_task(_g1h, per_thread_states, task_queues(), diff --git a/src/hotspot/share/gc/shared/strongRootsScope.cpp b/src/hotspot/share/gc/shared/strongRootsScope.cpp index 1316df68e5f9d..2130cd5f1c0a1 100644 --- a/src/hotspot/share/gc/shared/strongRootsScope.cpp +++ b/src/hotspot/share/gc/shared/strongRootsScope.cpp @@ -34,18 +34,3 @@ MarkScope::MarkScope() { MarkScope::~MarkScope() { nmethod::oops_do_marking_epilogue(); } - -StrongRootsScope::StrongRootsScope(uint n_threads) : _n_threads(n_threads) { - // No need for thread claim for statically-known sequential case (_n_threads == 0) - // For positive values, clients of this class often unify sequential/parallel - // cases, so they expect the thread claim token to be updated. - if (_n_threads != 0) { - Threads::change_thread_claim_token(); - } -} - -StrongRootsScope::~StrongRootsScope() { - if (_n_threads != 0) { - Threads::assert_all_threads_claimed(); - } -} diff --git a/src/hotspot/share/gc/shared/strongRootsScope.hpp b/src/hotspot/share/gc/shared/strongRootsScope.hpp index 2d33753e4b0b5..be6cb4b549fb4 100644 --- a/src/hotspot/share/gc/shared/strongRootsScope.hpp +++ b/src/hotspot/share/gc/shared/strongRootsScope.hpp @@ -33,17 +33,4 @@ class MarkScope : public StackObj { ~MarkScope(); }; -// Sets up and tears down the required state for sequential/parallel root processing. -class StrongRootsScope : public MarkScope { - // Number of threads participating in the roots processing. - // 0 means statically-known sequential root processing; used only by Serial GC - const uint _n_threads; - - public: - StrongRootsScope(uint n_threads); - ~StrongRootsScope(); - - uint n_threads() const { return _n_threads; } -}; - #endif // SHARE_GC_SHARED_STRONGROOTSSCOPE_HPP diff --git a/src/hotspot/share/runtime/safepoint.cpp b/src/hotspot/share/runtime/safepoint.cpp index a1922612bd685..051cc6261f830 100644 --- a/src/hotspot/share/runtime/safepoint.cpp +++ b/src/hotspot/share/runtime/safepoint.cpp @@ -30,7 +30,6 @@ #include "gc/shared/collectedHeap.hpp" #include "gc/shared/gcLocker.hpp" #include "gc/shared/oopStorage.hpp" -#include "gc/shared/strongRootsScope.hpp" #include "gc/shared/workerThread.hpp" #include "gc/shared/workerUtils.hpp" #include "interpreter/interpreter.hpp"