mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-27 13:52:27 +00:00
8377701: Shenandoah: Convert ShenandoahEvacOOMHandler to use Atomic<T>
Reviewed-by: shade, xpeng, wkemper, phh
This commit is contained in:
parent
f02d190095
commit
4a6d359a45
@ -37,22 +37,22 @@ ShenandoahEvacOOMCounter::ShenandoahEvacOOMCounter() :
|
||||
void ShenandoahEvacOOMCounter::decrement() {
|
||||
assert(unmasked_count() > 0, "sanity");
|
||||
// NOTE: It's ok to simply decrement, even with mask set, because unmasked value is positive.
|
||||
AtomicAccess::dec(&_bits);
|
||||
_bits.fetch_then_sub(1);
|
||||
}
|
||||
|
||||
void ShenandoahEvacOOMCounter::clear() {
|
||||
assert(unmasked_count() == 0, "sanity");
|
||||
AtomicAccess::release_store_fence(&_bits, (jint)0);
|
||||
_bits.release_store_fence((jint)0);
|
||||
}
|
||||
|
||||
void ShenandoahEvacOOMCounter::set_oom_bit(bool decrement) {
|
||||
jint threads_in_evac = AtomicAccess::load_acquire(&_bits);
|
||||
jint threads_in_evac = _bits.load_acquire();
|
||||
while (true) {
|
||||
jint newval = decrement
|
||||
? (threads_in_evac - 1) | OOM_MARKER_MASK
|
||||
: threads_in_evac | OOM_MARKER_MASK;
|
||||
|
||||
jint other = AtomicAccess::cmpxchg(&_bits, threads_in_evac, newval);
|
||||
jint other = _bits.compare_exchange(threads_in_evac, newval);
|
||||
if (other == threads_in_evac) {
|
||||
// Success: wait for other threads to get out of the protocol and return.
|
||||
break;
|
||||
@ -65,7 +65,7 @@ void ShenandoahEvacOOMCounter::set_oom_bit(bool decrement) {
|
||||
|
||||
bool ShenandoahEvacOOMCounter::try_increment()
|
||||
{
|
||||
jint threads_in_evac = AtomicAccess::load_acquire(&_bits);
|
||||
jint threads_in_evac = _bits.load_acquire();
|
||||
|
||||
while (true) {
|
||||
// Cannot enter evacuation if OOM_MARKER_MASK is set.
|
||||
@ -73,7 +73,7 @@ bool ShenandoahEvacOOMCounter::try_increment()
|
||||
return false;
|
||||
}
|
||||
|
||||
jint other = AtomicAccess::cmpxchg(&_bits, threads_in_evac, threads_in_evac + 1);
|
||||
jint other = _bits.compare_exchange(threads_in_evac, threads_in_evac + 1);
|
||||
if (other == threads_in_evac) {
|
||||
// Success: caller may safely enter evacuation
|
||||
return true;
|
||||
|
||||
@ -27,6 +27,7 @@
|
||||
|
||||
#include "gc/shenandoah/shenandoahPadding.hpp"
|
||||
#include "memory/allocation.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/javaThread.hpp"
|
||||
#include "utilities/globalDefinitions.hpp"
|
||||
|
||||
@ -36,7 +37,7 @@
|
||||
class ShenandoahEvacOOMCounter {
|
||||
private:
|
||||
// Combination of a 31-bit counter and 1-bit OOM marker.
|
||||
volatile jint _bits;
|
||||
Atomic<jint> _bits;
|
||||
|
||||
// This class must be at least a cache line in size to prevent false sharing.
|
||||
shenandoah_padding_minus_size(0, sizeof(jint));
|
||||
|
||||
@ -29,14 +29,13 @@
|
||||
|
||||
#include "gc/shenandoah/shenandoahHeap.inline.hpp"
|
||||
#include "gc/shenandoah/shenandoahThreadLocalData.hpp"
|
||||
#include "runtime/atomicAccess.hpp"
|
||||
|
||||
jint ShenandoahEvacOOMCounter::load_acquire() {
|
||||
return AtomicAccess::load_acquire(&_bits);
|
||||
return _bits.load_acquire();
|
||||
}
|
||||
|
||||
jint ShenandoahEvacOOMCounter::unmasked_count() {
|
||||
return AtomicAccess::load_acquire(&_bits) & ~OOM_MARKER_MASK;
|
||||
return _bits.load_acquire() & ~OOM_MARKER_MASK;
|
||||
}
|
||||
|
||||
void ShenandoahEvacOOMHandler::enter_evacuation(Thread* thr) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user