diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp b/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp index 4d4730de0b2..c1c820cb554 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefine.cpp @@ -575,7 +575,7 @@ bool G1ConcurrentRefine::adjust_num_threads_periodically() { if (!_needs_adjust) { Tickspan since_adjust = Ticks::now() - _last_adjust; if (since_adjust.milliseconds() < adjust_threads_period_ms()) { - _num_threads_wanted = 0; + _num_threads_wanted.store_relaxed(0); return false; } } @@ -592,7 +592,7 @@ bool G1ConcurrentRefine::adjust_num_threads_periodically() { _needs_adjust = true; } - return (_num_threads_wanted > 0) && !heap_was_locked(); + return (num_threads_wanted() > 0) && !heap_was_locked(); } void G1ConcurrentRefine::adjust_threads_wanted(size_t available_bytes) { @@ -603,7 +603,7 @@ void G1ConcurrentRefine::adjust_threads_wanted(size_t available_bytes) { size_t num_cards = policy->current_pending_cards(); - _threads_needed.update(_num_threads_wanted, + _threads_needed.update(num_threads_wanted(), available_bytes, num_cards, _pending_cards_target); @@ -613,7 +613,7 @@ void G1ConcurrentRefine::adjust_threads_wanted(size_t available_bytes) { new_wanted = _thread_control.max_num_threads(); } - _num_threads_wanted = new_wanted; + _num_threads_wanted.store_relaxed(new_wanted); log_debug(gc, refine)("Concurrent refinement: wanted %u, pending cards: %zu (pending-from-gc %zu), " "predicted: %zu, goal %zu, time-until-next-gc: %1.2fms pred-refine-rate %1.2fc/ms log-rate %1.2fc/ms", diff --git a/src/hotspot/share/gc/g1/g1ConcurrentRefine.hpp b/src/hotspot/share/gc/g1/g1ConcurrentRefine.hpp index 50fb412f3af..62e56c14c68 100644 --- a/src/hotspot/share/gc/g1/g1ConcurrentRefine.hpp +++ b/src/hotspot/share/gc/g1/g1ConcurrentRefine.hpp @@ -28,6 +28,7 @@ #include "gc/g1/g1ConcurrentRefineStats.hpp" #include "gc/g1/g1ConcurrentRefineThreadsNeeded.hpp" #include "memory/allocation.hpp" +#include "runtime/atomic.hpp" #include "utilities/debug.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/growableArray.hpp" @@ -212,7 +213,7 @@ public: // class G1ConcurrentRefine : public CHeapObj { G1Policy* _policy; - volatile uint _num_threads_wanted; + Atomic _num_threads_wanted; size_t _pending_cards_target; Ticks _last_adjust; Ticks _last_deactivate; @@ -306,7 +307,7 @@ public: // obtaining the heap lock. bool heap_was_locked() const { return _heap_was_locked; } - uint num_threads_wanted() const { return _num_threads_wanted; } + uint num_threads_wanted() const { return _num_threads_wanted.load_relaxed(); } uint max_num_threads() const { return _thread_control.max_num_threads(); } // Iterate over all concurrent refinement threads applying the given closure.