8376531: Genshen: Missing volatile modifier on multiple fields of ShenandoahOldGeneration

This commit is contained in:
Xiaolong Peng 2026-01-27 12:48:42 -08:00
parent 0f087a7fef
commit b89b8f877e
2 changed files with 16 additions and 16 deletions

View File

@ -63,7 +63,7 @@ private:
uint _nworkers;
ShenandoahHeapRegion** _coalesce_and_fill_region_array;
uint _coalesce_and_fill_region_count;
volatile bool _is_preempted;
Atomic<bool> _is_preempted;
public:
ShenandoahConcurrentCoalesceAndFillTask(uint nworkers,
@ -88,7 +88,7 @@ public:
if (!r->oop_coalesce_and_fill(true)) {
// Coalesce and fill has been preempted
AtomicAccess::store(&_is_preempted, true);
_is_preempted.store_relaxed(true);
return;
}
}
@ -96,7 +96,7 @@ public:
// Value returned from is_completed() is only valid after all worker thread have terminated.
bool is_completed() {
return !AtomicAccess::load(&_is_preempted);
return !_is_preempted.load_relaxed();
}
};
@ -147,23 +147,23 @@ void ShenandoahOldGeneration::augment_promoted_reserve(size_t increment) {
void ShenandoahOldGeneration::reset_promoted_expended() {
shenandoah_assert_heaplocked_or_safepoint();
AtomicAccess::store(&_promoted_expended, static_cast<size_t>(0));
AtomicAccess::store(&_promotion_failure_count, static_cast<size_t>(0));
AtomicAccess::store(&_promotion_failure_words, static_cast<size_t>(0));
_promoted_expended.store_relaxed(0);
_promotion_failure_count.store_relaxed(0);
_promotion_failure_words.store_relaxed(0);
}
size_t ShenandoahOldGeneration::expend_promoted(size_t increment) {
shenandoah_assert_heaplocked_or_safepoint();
assert(get_promoted_expended() + increment <= get_promoted_reserve(), "Do not expend more promotion than budgeted");
return AtomicAccess::add(&_promoted_expended, increment);
return _promoted_expended.add_then_fetch(increment);
}
size_t ShenandoahOldGeneration::unexpend_promoted(size_t decrement) {
return AtomicAccess::sub(&_promoted_expended, decrement);
return _promoted_expended.sub_then_fetch(decrement);
}
size_t ShenandoahOldGeneration::get_promoted_expended() const {
return AtomicAccess::load(&_promoted_expended);
return _promoted_expended.load_relaxed();
}
bool ShenandoahOldGeneration::can_allocate(const ShenandoahAllocRequest &req) const {
@ -582,8 +582,8 @@ void ShenandoahOldGeneration::handle_failed_evacuation() {
}
void ShenandoahOldGeneration::handle_failed_promotion(Thread* thread, size_t size) {
AtomicAccess::inc(&_promotion_failure_count);
AtomicAccess::add(&_promotion_failure_words, size);
_promotion_failure_count.add_then_fetch(static_cast<size_t>(1));
_promotion_failure_words.and_then_fetch(size);
LogTarget(Debug, gc, plab) lt;
LogStream ls(lt);

View File

@ -64,7 +64,7 @@ private:
// is therefore always accessed through atomic operations. This is increased when a
// PLAB is allocated for promotions. The value is decreased by the amount of memory
// remaining in a PLAB when it is retired.
size_t _promoted_expended;
Atomic<size_t> _promoted_expended;
// Represents the quantity of live bytes we expect to promote during the next GC cycle, either by
// evacuation or by promote-in-place. This value is used by the young heuristic to trigger mixed collections.
@ -78,8 +78,8 @@ private:
// Keep track of the number and size of promotions that failed. Perhaps we should use this to increase
// the size of the old generation for the next collection cycle.
size_t _promotion_failure_count;
size_t _promotion_failure_words;
Atomic<size_t> _promotion_failure_count;
Atomic<size_t> _promotion_failure_words;
// During construction of the collection set, we keep track of regions that are eligible
// for promotion in place. These fields track the count of those humongous and regular regions.
@ -126,8 +126,8 @@ public:
size_t get_promoted_expended() const;
// Return the count and size (in words) of failed promotions since the last reset
size_t get_promotion_failed_count() const { return AtomicAccess::load(&_promotion_failure_count); }
size_t get_promotion_failed_words() const { return AtomicAccess::load(&_promotion_failure_words); }
size_t get_promotion_failed_count() const { return _promotion_failure_count.load_relaxed(); }
size_t get_promotion_failed_words() const { return _promotion_failure_words.load_relaxed(); }
// Test if there is enough memory reserved for this promotion
bool can_promote(size_t requested_bytes) const {