mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-27 13:52:27 +00:00
8377044: Shenandoah: Convert ShenandoahHeap related code to use Atomic<T>
Reviewed-by: kdnilsen, xpeng, wkemper
This commit is contained in:
parent
b41ba3a496
commit
2925eb8cfb
@ -86,6 +86,7 @@
|
||||
#include "nmt/memTracker.hpp"
|
||||
#include "oops/compressedOops.inline.hpp"
|
||||
#include "prims/jvmtiTagMap.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/atomicAccess.hpp"
|
||||
#include "runtime/globals.hpp"
|
||||
#include "runtime/interfaceSupport.inline.hpp"
|
||||
@ -201,9 +202,9 @@ jint ShenandoahHeap::initialize() {
|
||||
assert(num_min_regions <= _num_regions, "sanity");
|
||||
_minimum_size = num_min_regions * reg_size_bytes;
|
||||
|
||||
_soft_max_size = clamp(SoftMaxHeapSize, min_capacity(), max_capacity());
|
||||
_soft_max_size.store_relaxed(clamp(SoftMaxHeapSize, min_capacity(), max_capacity()));
|
||||
|
||||
_committed = _initial_size;
|
||||
_committed.store_relaxed(_initial_size);
|
||||
|
||||
size_t heap_page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
|
||||
size_t bitmap_page_size = UseLargePages ? os::large_page_size() : os::vm_page_size();
|
||||
@ -725,17 +726,17 @@ size_t ShenandoahHeap::used() const {
|
||||
}
|
||||
|
||||
size_t ShenandoahHeap::committed() const {
|
||||
return AtomicAccess::load(&_committed);
|
||||
return _committed.load_relaxed();
|
||||
}
|
||||
|
||||
void ShenandoahHeap::increase_committed(size_t bytes) {
|
||||
shenandoah_assert_heaplocked_or_safepoint();
|
||||
_committed += bytes;
|
||||
_committed.fetch_then_add(bytes, memory_order_relaxed);
|
||||
}
|
||||
|
||||
void ShenandoahHeap::decrease_committed(size_t bytes) {
|
||||
shenandoah_assert_heaplocked_or_safepoint();
|
||||
_committed -= bytes;
|
||||
_committed.fetch_then_sub(bytes, memory_order_relaxed);
|
||||
}
|
||||
|
||||
size_t ShenandoahHeap::capacity() const {
|
||||
@ -747,7 +748,7 @@ size_t ShenandoahHeap::max_capacity() const {
|
||||
}
|
||||
|
||||
size_t ShenandoahHeap::soft_max_capacity() const {
|
||||
size_t v = AtomicAccess::load(&_soft_max_size);
|
||||
size_t v = _soft_max_size.load_relaxed();
|
||||
assert(min_capacity() <= v && v <= max_capacity(),
|
||||
"Should be in bounds: %zu <= %zu <= %zu",
|
||||
min_capacity(), v, max_capacity());
|
||||
@ -758,7 +759,7 @@ void ShenandoahHeap::set_soft_max_capacity(size_t v) {
|
||||
assert(min_capacity() <= v && v <= max_capacity(),
|
||||
"Should be in bounds: %zu <= %zu <= %zu",
|
||||
min_capacity(), v, max_capacity());
|
||||
AtomicAccess::store(&_soft_max_size, v);
|
||||
_soft_max_size.store_relaxed(v);
|
||||
}
|
||||
|
||||
size_t ShenandoahHeap::min_capacity() const {
|
||||
@ -1941,7 +1942,7 @@ private:
|
||||
size_t const _stride;
|
||||
|
||||
shenandoah_padding(0);
|
||||
volatile size_t _index;
|
||||
Atomic<size_t> _index;
|
||||
shenandoah_padding(1);
|
||||
|
||||
public:
|
||||
@ -1954,8 +1955,8 @@ public:
|
||||
size_t stride = _stride;
|
||||
|
||||
size_t max = _heap->num_regions();
|
||||
while (AtomicAccess::load(&_index) < max) {
|
||||
size_t cur = AtomicAccess::fetch_then_add(&_index, stride, memory_order_relaxed);
|
||||
while (_index.load_relaxed() < max) {
|
||||
size_t cur = _index.fetch_then_add(stride, memory_order_relaxed);
|
||||
size_t start = cur;
|
||||
size_t end = MIN2(cur + stride, max);
|
||||
if (start >= max) break;
|
||||
@ -2703,11 +2704,11 @@ ShenandoahRegionIterator::ShenandoahRegionIterator(ShenandoahHeap* heap) :
|
||||
_index(0) {}
|
||||
|
||||
void ShenandoahRegionIterator::reset() {
|
||||
_index = 0;
|
||||
_index.store_relaxed(0);
|
||||
}
|
||||
|
||||
bool ShenandoahRegionIterator::has_next() const {
|
||||
return _index < _heap->num_regions();
|
||||
return _index.load_relaxed() < _heap->num_regions();
|
||||
}
|
||||
|
||||
ShenandoahLiveData* ShenandoahHeap::get_liveness_cache(uint worker_id) {
|
||||
|
||||
@ -88,7 +88,7 @@ private:
|
||||
ShenandoahHeap* _heap;
|
||||
|
||||
shenandoah_padding(0);
|
||||
volatile size_t _index;
|
||||
Atomic<size_t> _index;
|
||||
shenandoah_padding(1);
|
||||
|
||||
// No implicit copying: iterators should be passed by reference to capture the state
|
||||
@ -208,9 +208,9 @@ private:
|
||||
size_t _initial_size;
|
||||
size_t _minimum_size;
|
||||
|
||||
volatile size_t _soft_max_size;
|
||||
Atomic<size_t> _soft_max_size;
|
||||
shenandoah_padding(0);
|
||||
volatile size_t _committed;
|
||||
Atomic<size_t> _committed;
|
||||
shenandoah_padding(1);
|
||||
|
||||
public:
|
||||
@ -340,7 +340,7 @@ private:
|
||||
ShenandoahSharedFlag _full_gc_move_in_progress;
|
||||
ShenandoahSharedFlag _concurrent_strong_root_in_progress;
|
||||
|
||||
size_t _gc_no_progress_count;
|
||||
Atomic<size_t> _gc_no_progress_count;
|
||||
|
||||
// This updates the singular, global gc state. This call must happen on a safepoint.
|
||||
void set_gc_state_at_safepoint(uint mask, bool value);
|
||||
|
||||
@ -49,7 +49,7 @@
|
||||
#include "gc/shenandoah/shenandoahWorkGroup.hpp"
|
||||
#include "oops/compressedOops.inline.hpp"
|
||||
#include "oops/oop.inline.hpp"
|
||||
#include "runtime/atomicAccess.hpp"
|
||||
#include "runtime/atomic.hpp"
|
||||
#include "runtime/javaThread.hpp"
|
||||
#include "runtime/objectMonitor.inline.hpp"
|
||||
#include "runtime/prefetch.inline.hpp"
|
||||
@ -61,7 +61,7 @@ inline ShenandoahHeap* ShenandoahHeap::heap() {
|
||||
}
|
||||
|
||||
inline ShenandoahHeapRegion* ShenandoahRegionIterator::next() {
|
||||
size_t new_index = AtomicAccess::add(&_index, (size_t) 1, memory_order_relaxed);
|
||||
size_t new_index = _index.add_then_fetch((size_t) 1, memory_order_relaxed);
|
||||
// get_region() provides the bounds-check and returns null on OOB.
|
||||
return _heap->get_region(new_index - 1);
|
||||
}
|
||||
@ -75,15 +75,15 @@ inline WorkerThreads* ShenandoahHeap::safepoint_workers() {
|
||||
}
|
||||
|
||||
inline void ShenandoahHeap::notify_gc_progress() {
|
||||
AtomicAccess::store(&_gc_no_progress_count, (size_t) 0);
|
||||
_gc_no_progress_count.store_relaxed((size_t) 0);
|
||||
|
||||
}
|
||||
inline void ShenandoahHeap::notify_gc_no_progress() {
|
||||
AtomicAccess::inc(&_gc_no_progress_count);
|
||||
_gc_no_progress_count.add_then_fetch((size_t) 1);
|
||||
}
|
||||
|
||||
inline size_t ShenandoahHeap::get_gc_no_progress_count() const {
|
||||
return AtomicAccess::load(&_gc_no_progress_count);
|
||||
return _gc_no_progress_count.load_relaxed();
|
||||
}
|
||||
|
||||
inline size_t ShenandoahHeap::heap_region_index_containing(const void* addr) const {
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
nonstatic_field(ShenandoahHeap, _regions, ShenandoahHeapRegion**) \
|
||||
nonstatic_field(ShenandoahHeap, _log_min_obj_alignment_in_bytes, int) \
|
||||
nonstatic_field(ShenandoahHeap, _free_set, ShenandoahFreeSet*) \
|
||||
volatile_nonstatic_field(ShenandoahHeap, _committed, size_t) \
|
||||
volatile_nonstatic_field(ShenandoahHeap, _committed, Atomic<size_t>) \
|
||||
static_field(ShenandoahHeapRegion, RegionSizeBytes, size_t) \
|
||||
static_field(ShenandoahHeapRegion, RegionSizeBytesShift, size_t) \
|
||||
nonstatic_field(ShenandoahHeapRegion, _state, Atomic<ShenandoahHeapRegion::RegionState>) \
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user