Skip to content
Permalink
Browse files

8241520: Shenandoah: simplify region sequence numbers handling

Reviewed-by: rkennke
  • Loading branch information
shipilev committed Mar 24, 2020
1 parent 40173c5 commit cb1632e8e35dfe81950349fcc54ffbb5a2d85346
@@ -179,6 +179,9 @@ HeapWord* ShenandoahFreeSet::try_allocate_in(ShenandoahHeapRegion* r, Shenandoah
// Allocation successful, bump stats:
if (req.is_mutator_alloc()) {
increase_used(size * HeapWordSize);
if (_heap->is_traversal_mode()) {
r->update_seqnum_last_alloc_mutator();
}
}

// Record actual allocation size
@@ -992,7 +992,7 @@ void ShenandoahHeap::print_heap_regions_on(outputStream* st) const {
st->print_cr("EU=empty-uncommitted, EC=empty-committed, R=regular, H=humongous start, HC=humongous continuation, CS=collection set, T=trash, P=pinned");
st->print_cr("BTE=bottom/top/end, U=used, T=TLAB allocs, G=GCLAB allocs, S=shared allocs, L=live data");
st->print_cr("R=root, CP=critical pins, TAMS=top-at-mark-start (previous, next)");
st->print_cr("SN=alloc sequence numbers (first mutator, last mutator, first gc, last gc)");
st->print_cr("SN=alloc sequence number");

for (size_t i = 0; i < num_regions(); i++) {
get_region(i)->print_on(st);
@@ -66,10 +66,7 @@ ShenandoahHeapRegion::ShenandoahHeapRegion(ShenandoahHeap* heap, HeapWord* start
_tlab_allocs(0),
_gclab_allocs(0),
_shared_allocs(0),
_seqnum_first_alloc_mutator(0),
_seqnum_first_alloc_gc(0),
_seqnum_last_alloc_mutator(0),
_seqnum_last_alloc_gc(0),
_live_data(0),
_critical_pins(0),
_update_watermark(start) {
@@ -315,27 +312,28 @@ void ShenandoahHeapRegion::reset_alloc_metadata() {
_tlab_allocs = 0;
_gclab_allocs = 0;
_shared_allocs = 0;
_seqnum_first_alloc_mutator = 0;
_seqnum_last_alloc_mutator = 0;
_seqnum_first_alloc_gc = 0;
_seqnum_last_alloc_gc = 0;
}

void ShenandoahHeapRegion::reset_alloc_metadata_to_shared() {
if (used() > 0) {
_tlab_allocs = 0;
_gclab_allocs = 0;
_shared_allocs = used() >> LogHeapWordSize;
uint64_t next = _alloc_seq_num.value++;
_seqnum_first_alloc_mutator = next;
_seqnum_last_alloc_mutator = next;
_seqnum_first_alloc_gc = 0;
_seqnum_last_alloc_gc = 0;
if (_heap->is_traversal_mode()) {
update_seqnum_last_alloc_mutator();
}
} else {
reset_alloc_metadata();
}
}

void ShenandoahHeapRegion::update_seqnum_last_alloc_mutator() {
assert(_heap->is_traversal_mode(), "Sanity");
_heap->assert_heaplock_or_safepoint();
_seqnum_last_alloc_mutator = _alloc_seq_num.value++;
}

size_t ShenandoahHeapRegion::get_shared_allocs() const {
return _shared_allocs * HeapWordSize;
}
@@ -421,9 +419,7 @@ void ShenandoahHeapRegion::print_on(outputStream* st) const {
st->print("|S " SIZE_FORMAT_W(5) "%1s", byte_size_in_proper_unit(get_shared_allocs()), proper_unit_for_byte_size(get_shared_allocs()));
st->print("|L " SIZE_FORMAT_W(5) "%1s", byte_size_in_proper_unit(get_live_data_bytes()), proper_unit_for_byte_size(get_live_data_bytes()));
st->print("|CP " SIZE_FORMAT_W(3), pin_count());
st->print("|SN " UINT64_FORMAT_X_W(12) ", " UINT64_FORMAT_X_W(8) ", " UINT64_FORMAT_X_W(8) ", " UINT64_FORMAT_X_W(8),
seqnum_first_alloc_mutator(), seqnum_last_alloc_mutator(),
seqnum_first_alloc_gc(), seqnum_last_alloc_gc());
st->print("|SN " UINT64_FORMAT_X_W(12), _seqnum_last_alloc_mutator);
st->cr();
}

@@ -253,10 +253,7 @@ class ShenandoahHeapRegion : public ContiguousSpace {
size_t _gclab_allocs;
size_t _shared_allocs;

uint64_t _seqnum_first_alloc_mutator;
uint64_t _seqnum_first_alloc_gc;
uint64_t _seqnum_last_alloc_mutator;
uint64_t _seqnum_last_alloc_gc;

volatile size_t _live_data;
volatile size_t _critical_pins;
@@ -404,31 +401,12 @@ class ShenandoahHeapRegion : public ContiguousSpace {
size_t get_tlab_allocs() const;
size_t get_gclab_allocs() const;

uint64_t seqnum_first_alloc() const {
if (_seqnum_first_alloc_mutator == 0) return _seqnum_first_alloc_gc;
if (_seqnum_first_alloc_gc == 0) return _seqnum_first_alloc_mutator;
return MIN2(_seqnum_first_alloc_mutator, _seqnum_first_alloc_gc);
}

uint64_t seqnum_last_alloc() const {
return MAX2(_seqnum_last_alloc_mutator, _seqnum_last_alloc_gc);
}

uint64_t seqnum_first_alloc_mutator() const {
return _seqnum_first_alloc_mutator;
}

uint64_t seqnum_last_alloc_mutator() const {
assert(_heap->is_traversal_mode(), "Sanity");
return _seqnum_last_alloc_mutator;
}

uint64_t seqnum_first_alloc_gc() const {
return _seqnum_first_alloc_gc;
}

uint64_t seqnum_last_alloc_gc() const {
return _seqnum_last_alloc_gc;
}
void update_seqnum_last_alloc_mutator();

HeapWord* get_update_watermark() const {
// Updates to the update-watermark only happen at safepoints or, when pushing
@@ -53,29 +53,6 @@ HeapWord* ShenandoahHeapRegion::allocate(size_t size, ShenandoahAllocRequest::Ty
}

inline void ShenandoahHeapRegion::adjust_alloc_metadata(ShenandoahAllocRequest::Type type, size_t size) {
bool is_first_alloc = (top() == bottom());

switch (type) {
case ShenandoahAllocRequest::_alloc_shared:
case ShenandoahAllocRequest::_alloc_tlab:
_seqnum_last_alloc_mutator = _alloc_seq_num.value++;
if (is_first_alloc) {
assert (_seqnum_first_alloc_mutator == 0, "Region " SIZE_FORMAT " metadata is correct", _region_number);
_seqnum_first_alloc_mutator = _seqnum_last_alloc_mutator;
}
break;
case ShenandoahAllocRequest::_alloc_shared_gc:
case ShenandoahAllocRequest::_alloc_gclab:
_seqnum_last_alloc_gc = _alloc_seq_num.value++;
if (is_first_alloc) {
assert (_seqnum_first_alloc_gc == 0, "Region " SIZE_FORMAT " metadata is correct", _region_number);
_seqnum_first_alloc_gc = _seqnum_last_alloc_gc;
}
break;
default:
ShouldNotReachHere();
}

switch (type) {
case ShenandoahAllocRequest::_alloc_shared:
case ShenandoahAllocRequest::_alloc_shared_gc:
@@ -396,27 +396,6 @@ class ShenandoahVerifyHeapRegionClosure : public ShenandoahHeapRegionClosure {

verify(r, r->is_cset() == _heap->collection_set()->is_in(r),
"Transitional: region flags and collection set agree");

verify(r, r->is_empty() || r->seqnum_first_alloc() != 0,
"Non-empty regions should have first seqnum set");

verify(r, r->is_empty() || (r->seqnum_first_alloc_mutator() != 0 || r->seqnum_first_alloc_gc() != 0),
"Non-empty regions should have first seqnum set to either GC or mutator");

verify(r, r->is_empty() || r->seqnum_last_alloc() != 0,
"Non-empty regions should have last seqnum set");

verify(r, r->is_empty() || (r->seqnum_last_alloc_mutator() != 0 || r->seqnum_last_alloc_gc() != 0),
"Non-empty regions should have last seqnum set to either GC or mutator");

verify(r, r->seqnum_first_alloc() <= r->seqnum_last_alloc(),
"First seqnum should not be greater than last timestamp");

verify(r, r->seqnum_first_alloc_mutator() <= r->seqnum_last_alloc_mutator(),
"First mutator seqnum should not be greater than last seqnum");

verify(r, r->seqnum_first_alloc_gc() <= r->seqnum_last_alloc_gc(),
"First GC seqnum should not be greater than last seqnum");
}
};

0 comments on commit cb1632e

Please sign in to comment.