Skip to content
Permalink
Browse files
8261496: Shenandoah: reconsider pacing updates memory ordering
Reviewed-by: rkennke, clanger
Backport-of: 4642730
  • Loading branch information
shipilev committed Jun 25, 2021
1 parent a092a17 commit 2c2cc746d77d83488d019ff15d21488cb1479f99
@@ -93,7 +93,7 @@ void ShenandoahControlThread::run_service() {
bool implicit_gc_requested = _gc_requested.is_set() && !is_explicit_gc(_requested_gc_cause);

// This control loop iteration have seen this much allocations.
size_t allocs_seen = Atomic::xchg<size_t>(0, &_allocs_seen);
size_t allocs_seen = Atomic::xchg<size_t>(0, &_allocs_seen, memory_order_relaxed);

// Check if we have seen a new target for soft max heap size.
bool soft_max_changed = check_soft_max_changed();
@@ -627,7 +627,7 @@ void ShenandoahControlThread::notify_heap_changed() {

void ShenandoahControlThread::pacing_notify_alloc(size_t words) {
assert(ShenandoahPacing, "should only call when pacing is enabled");
Atomic::add(words, &_allocs_seen);
Atomic::add(words, &_allocs_seen, memory_order_relaxed);
}

void ShenandoahControlThread::set_forced_counters_update(bool value) {
@@ -187,7 +187,7 @@ size_t ShenandoahPacer::update_and_get_progress_history() {
void ShenandoahPacer::restart_with(size_t non_taxable_bytes, double tax_rate) {
size_t initial = (size_t)(non_taxable_bytes * tax_rate) >> LogHeapWordSize;
STATIC_ASSERT(sizeof(size_t) <= sizeof(intptr_t));
Atomic::xchg((intptr_t)initial, &_budget);
Atomic::xchg((intptr_t)initial, &_budget, memory_order_relaxed);
Atomic::store(tax_rate, &_tax_rate);
Atomic::inc(&_epoch);

@@ -209,14 +209,14 @@ bool ShenandoahPacer::claim_for_alloc(size_t words, bool force) {
return false;
}
new_val = cur - tax;
} while (Atomic::cmpxchg(new_val, &_budget, cur) != cur);
} while (Atomic::cmpxchg(new_val, &_budget, cur, memory_order_relaxed) != cur);
return true;
}

void ShenandoahPacer::unpace_for_alloc(intptr_t epoch, size_t words) {
assert(ShenandoahPacing, "Only be here when pacing is enabled");

if (_epoch != epoch) {
if (Atomic::load(&_epoch) != epoch) {
// Stale ticket, no need to unpace.
return;
}
@@ -53,13 +53,13 @@ inline void ShenandoahPacer::report_internal(size_t words) {
inline void ShenandoahPacer::report_progress_internal(size_t words) {
assert(ShenandoahPacing, "Only be here when pacing is enabled");
STATIC_ASSERT(sizeof(size_t) <= sizeof(intptr_t));
Atomic::add((intptr_t)words, &_progress);
Atomic::add((intptr_t)words, &_progress, memory_order_relaxed);
}

inline void ShenandoahPacer::add_budget(size_t words) {
STATIC_ASSERT(sizeof(size_t) <= sizeof(intptr_t));
intptr_t inc = (intptr_t) words;
intptr_t new_budget = Atomic::add(inc, &_budget);
intptr_t new_budget = Atomic::add(inc, &_budget, memory_order_relaxed);

// Was the budget replenished beyond zero? Then all pacing claims
// are satisfied, notify the waiters. Avoid taking any locks here,

1 comment on commit 2c2cc74

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on 2c2cc74 Jun 25, 2021

Please sign in to comment.