Skip to content

Commit 43ea45d

Browse files
Xiaolong Pengvladimirlagunov
authored andcommitted
8376531: Genshen: Convert ShenandoahOldGeneration to use Atomic<T>
Reviewed-by: wkemper, shade
1 parent b0db66a commit 43ea45d

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

src/hotspot/share/gc/shenandoah/shenandoahOldGeneration.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class ShenandoahConcurrentCoalesceAndFillTask : public WorkerTask {
6363
uint _nworkers;
6464
ShenandoahHeapRegion** _coalesce_and_fill_region_array;
6565
uint _coalesce_and_fill_region_count;
66-
volatile bool _is_preempted;
66+
Atomic<bool> _is_preempted;
6767

6868
public:
6969
ShenandoahConcurrentCoalesceAndFillTask(uint nworkers,
@@ -88,15 +88,15 @@ class ShenandoahConcurrentCoalesceAndFillTask : public WorkerTask {
8888

8989
if (!r->oop_coalesce_and_fill(true)) {
9090
// Coalesce and fill has been preempted
91-
AtomicAccess::store(&_is_preempted, true);
91+
_is_preempted.store_relaxed(true);
9292
return;
9393
}
9494
}
9595
}
9696

9797
// Value returned from is_completed() is only valid after all worker thread have terminated.
9898
bool is_completed() {
99-
return !AtomicAccess::load(&_is_preempted);
99+
return !_is_preempted.load_relaxed();
100100
}
101101
};
102102

@@ -147,23 +147,23 @@ void ShenandoahOldGeneration::augment_promoted_reserve(size_t increment) {
147147

148148
void ShenandoahOldGeneration::reset_promoted_expended() {
149149
shenandoah_assert_heaplocked_or_safepoint();
150-
AtomicAccess::store(&_promoted_expended, static_cast<size_t>(0));
151-
AtomicAccess::store(&_promotion_failure_count, static_cast<size_t>(0));
152-
AtomicAccess::store(&_promotion_failure_words, static_cast<size_t>(0));
150+
_promoted_expended.store_relaxed(0);
151+
_promotion_failure_count.store_relaxed(0);
152+
_promotion_failure_words.store_relaxed(0);
153153
}
154154

155155
size_t ShenandoahOldGeneration::expend_promoted(size_t increment) {
156156
shenandoah_assert_heaplocked_or_safepoint();
157157
assert(get_promoted_expended() + increment <= get_promoted_reserve(), "Do not expend more promotion than budgeted");
158-
return AtomicAccess::add(&_promoted_expended, increment);
158+
return _promoted_expended.add_then_fetch(increment);
159159
}
160160

161161
size_t ShenandoahOldGeneration::unexpend_promoted(size_t decrement) {
162-
return AtomicAccess::sub(&_promoted_expended, decrement);
162+
return _promoted_expended.sub_then_fetch(decrement);
163163
}
164164

165165
size_t ShenandoahOldGeneration::get_promoted_expended() const {
166-
return AtomicAccess::load(&_promoted_expended);
166+
return _promoted_expended.load_relaxed();
167167
}
168168

169169
bool ShenandoahOldGeneration::can_allocate(const ShenandoahAllocRequest &req) const {
@@ -582,8 +582,8 @@ void ShenandoahOldGeneration::handle_failed_evacuation() {
582582
}
583583

584584
void ShenandoahOldGeneration::handle_failed_promotion(Thread* thread, size_t size) {
585-
AtomicAccess::inc(&_promotion_failure_count);
586-
AtomicAccess::add(&_promotion_failure_words, size);
585+
_promotion_failure_count.add_then_fetch(1UL);
586+
_promotion_failure_words.and_then_fetch(size);
587587

588588
LogTarget(Debug, gc, plab) lt;
589589
LogStream ls(lt);

src/hotspot/share/gc/shenandoah/shenandoahOldGeneration.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ class ShenandoahOldGeneration : public ShenandoahGeneration {
6464
// is therefore always accessed through atomic operations. This is increased when a
6565
// PLAB is allocated for promotions. The value is decreased by the amount of memory
6666
// remaining in a PLAB when it is retired.
67-
size_t _promoted_expended;
67+
Atomic<size_t> _promoted_expended;
6868

6969
// Represents the quantity of live bytes we expect to promote during the next GC cycle, either by
7070
// evacuation or by promote-in-place. This value is used by the young heuristic to trigger mixed collections.
@@ -78,8 +78,8 @@ class ShenandoahOldGeneration : public ShenandoahGeneration {
7878

7979
// Keep track of the number and size of promotions that failed. Perhaps we should use this to increase
8080
// the size of the old generation for the next collection cycle.
81-
size_t _promotion_failure_count;
82-
size_t _promotion_failure_words;
81+
Atomic<size_t> _promotion_failure_count;
82+
Atomic<size_t> _promotion_failure_words;
8383

8484
// During construction of the collection set, we keep track of regions that are eligible
8585
// for promotion in place. These fields track the count of those humongous and regular regions.
@@ -126,8 +126,8 @@ class ShenandoahOldGeneration : public ShenandoahGeneration {
126126
size_t get_promoted_expended() const;
127127

128128
// Return the count and size (in words) of failed promotions since the last reset
129-
size_t get_promotion_failed_count() const { return AtomicAccess::load(&_promotion_failure_count); }
130-
size_t get_promotion_failed_words() const { return AtomicAccess::load(&_promotion_failure_words); }
129+
size_t get_promotion_failed_count() const { return _promotion_failure_count.load_relaxed(); }
130+
size_t get_promotion_failed_words() const { return _promotion_failure_words.load_relaxed(); }
131131

132132
// Test if there is enough memory reserved for this promotion
133133
bool can_promote(size_t requested_bytes) const {

0 commit comments

Comments
 (0)