Skip to content
Permalink
Browse files

8241668: Shenandoah: make ShenandoahHeapRegion not derive from Contig…

…uousSpace

Reviewed-by: rkennke
  • Loading branch information
shipilev committed Mar 26, 2020
1 parent e509368 commit 8c5531b6297a0d839c982f052bbb8aae0f546044
@@ -1127,16 +1127,16 @@ void ShenandoahHeap::do_full_collection(bool clear_all_soft_refs) {
}

HeapWord* ShenandoahHeap::block_start(const void* addr) const {
Space* sp = heap_region_containing(addr);
if (sp != NULL) {
return sp->block_start(addr);
ShenandoahHeapRegion* r = heap_region_containing(addr);
if (r != NULL) {
return r->block_start(addr);
}
return NULL;
}

bool ShenandoahHeap::block_is_obj(const HeapWord* addr) const {
Space* sp = heap_region_containing(addr);
return sp->block_is_obj(addr);
ShenandoahHeapRegion* r = heap_region_containing(addr);
return r->block_is_obj(addr);
}

bool ShenandoahHeap::print_location(outputStream* st, void* addr) const {
@@ -60,9 +60,12 @@ ShenandoahHeapRegion::ShenandoahHeapRegion(ShenandoahHeap* heap, HeapWord* start
_heap(heap),
_reserved(MemRegion(start, size_words)),
_region_number(index),
_bottom(start),
_end(start + size_words),
_new_top(NULL),
_empty_time(os::elapsedTime()),
_state(committed ? _empty_committed : _empty_uncommitted),
_top(start),
_tlab_allocs(0),
_gclab_allocs(0),
_shared_allocs(0),
@@ -71,7 +74,11 @@ ShenandoahHeapRegion::ShenandoahHeapRegion(ShenandoahHeap* heap, HeapWord* start
_critical_pins(0),
_update_watermark(start) {

ContiguousSpace::initialize(_reserved, true, committed);
assert(Universe::on_page_boundary(_bottom) && Universe::on_page_boundary(_end),
"invalid space boundaries");
if (ZapUnusedHeapArea && committed) {
SpaceMangler::mangle_region(_reserved);
}
}

size_t ShenandoahHeapRegion::region_number() const {
@@ -469,10 +476,7 @@ ShenandoahHeapRegion* ShenandoahHeapRegion::humongous_start_region() const {
}

void ShenandoahHeapRegion::recycle() {
ContiguousSpace::clear(false);
if (ZapUnusedHeapArea) {
ContiguousSpace::mangle_unused_area_complete();
}
set_top(bottom());
clear_live_data();

reset_alloc_metadata();
@@ -481,9 +485,13 @@ void ShenandoahHeapRegion::recycle() {
set_update_watermark(bottom());

make_empty();

if (ZapUnusedHeapArea) {
SpaceMangler::mangle_region(_reserved);
}
}

HeapWord* ShenandoahHeapRegion::block_start_const(const void* p) const {
HeapWord* ShenandoahHeapRegion::block_start(const void* p) const {
assert(MemRegion(bottom(), end()).contains(p),
"p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
p2i(p), p2i(bottom()), p2i(end()));
@@ -501,6 +509,18 @@ HeapWord* ShenandoahHeapRegion::block_start_const(const void* p) const {
}
}

size_t ShenandoahHeapRegion::block_size(const HeapWord* p) const {
assert(MemRegion(bottom(), end()).contains(p),
"p (" PTR_FORMAT ") not in space [" PTR_FORMAT ", " PTR_FORMAT ")",
p2i(p), p2i(bottom()), p2i(end()));
if (p < top()) {
return oop(p)->size();
} else {
assert(p == top(), "just checking");
return pointer_delta(end(), (HeapWord*) p);
}
}

void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
// Absolute minimums we should not ever break.
static const size_t MIN_REGION_SIZE = 256*K;
@@ -25,7 +25,7 @@
#ifndef SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP
#define SHARE_GC_SHENANDOAH_SHENANDOAHHEAPREGION_HPP

#include "gc/shared/space.hpp"
#include "gc/shared/spaceDecorator.hpp"
#include "gc/shenandoah/shenandoahAllocRequest.hpp"
#include "gc/shenandoah/shenandoahAsserts.hpp"
#include "gc/shenandoah/shenandoahHeap.hpp"
@@ -35,7 +35,7 @@
class VMStructs;
class ShenandoahHeapRegionStateConstant;

class ShenandoahHeapRegion : public ContiguousSpace {
class ShenandoahHeapRegion : public CHeapObj<mtGC> {
friend class VMStructs;
friend class ShenandoahHeapRegionStateConstant;
private:
@@ -237,9 +237,11 @@ class ShenandoahHeapRegion : public ContiguousSpace {
static PaddedAllocSeqNum _alloc_seq_num;

// Never updated fields
ShenandoahHeap* _heap;
MemRegion _reserved;
size_t _region_number;
ShenandoahHeap* const _heap;
MemRegion const _reserved;
size_t const _region_number;
HeapWord* const _bottom;
HeapWord* const _end;

// Rarely updated fields
HeapWord* _new_top;
@@ -249,6 +251,8 @@ class ShenandoahHeapRegion : public ContiguousSpace {
RegionState _state;

// Frequently updated fields
HeapWord* _top;

size_t _tlab_allocs;
size_t _gclab_allocs;
size_t _shared_allocs;
@@ -356,8 +360,6 @@ class ShenandoahHeapRegion : public ContiguousSpace {
// Allocation (return NULL if full)
inline HeapWord* allocate(size_t word_size, ShenandoahAllocRequest::Type type);

HeapWord* allocate(size_t word_size) shenandoah_not_implemented_return(NULL)

void clear_live_data();
void set_live_data(size_t s);

@@ -379,20 +381,25 @@ class ShenandoahHeapRegion : public ContiguousSpace {

void oop_iterate(OopIterateClosure* cl);

HeapWord* block_start_const(const void* p) const;

bool in_collection_set() const;
HeapWord* block_start(const void* p) const;
size_t block_size(const HeapWord* p) const;
bool block_is_obj(const HeapWord* p) const { return p < top(); }

// Find humongous start region that this region belongs to
ShenandoahHeapRegion* humongous_start_region() const;

CompactibleSpace* next_compaction_space() const shenandoah_not_implemented_return(NULL);
void prepare_for_compaction(CompactPoint* cp) shenandoah_not_implemented;
void adjust_pointers() shenandoah_not_implemented;
void compact() shenandoah_not_implemented;
HeapWord* top() const { return _top; }
void set_top(HeapWord* v) { _top = v; }

HeapWord* new_top() const { return _new_top; }
void set_new_top(HeapWord* v) { _new_top = v; }

HeapWord* bottom() const { return _bottom; }
HeapWord* end() const { return _end; }

void set_new_top(HeapWord* new_top) { _new_top = new_top; }
HeapWord* new_top() const { return _new_top; }
size_t capacity() const { return byte_size(bottom(), end()); }
size_t used() const { return byte_size(bottom(), top()); }
size_t free() const { return byte_size(top(), end()); }

inline void adjust_alloc_metadata(ShenandoahAllocRequest::Type type, size_t);
void reset_alloc_metadata_to_shared();
@@ -37,7 +37,10 @@
static_field(ShenandoahHeapRegion, RegionSizeBytes, size_t) \
static_field(ShenandoahHeapRegion, RegionSizeBytesShift, size_t) \
nonstatic_field(ShenandoahHeapRegion, _state, ShenandoahHeapRegion::RegionState) \
nonstatic_field(ShenandoahHeapRegion, _region_number, size_t) \
nonstatic_field(ShenandoahHeapRegion, _region_number, size_t const) \
nonstatic_field(ShenandoahHeapRegion, _bottom, HeapWord* const) \
nonstatic_field(ShenandoahHeapRegion, _top, HeapWord*) \
nonstatic_field(ShenandoahHeapRegion, _end, HeapWord* const) \

#define VM_INT_CONSTANTS_SHENANDOAH(declare_constant, declare_constant_with_value) \
declare_constant(ShenandoahHeapRegion::_empty_uncommitted) \
@@ -55,7 +58,7 @@
declare_toplevel_type, \
declare_integer_type) \
declare_type(ShenandoahHeap, CollectedHeap) \
declare_type(ShenandoahHeapRegion, ContiguousSpace) \
declare_toplevel_type(ShenandoahHeapRegion) \
declare_toplevel_type(ShenandoahHeap*) \
declare_toplevel_type(ShenandoahHeapRegion*) \
declare_toplevel_type(ShenandoahHeapRegion::RegionState) \
@@ -33,6 +33,7 @@
import sun.jvm.hotspot.oops.UnknownOopException;
import sun.jvm.hotspot.types.*;
import sun.jvm.hotspot.runtime.VM;
import sun.jvm.hotspot.runtime.VMObject;
import sun.jvm.hotspot.debugger.Address;
import sun.jvm.hotspot.utilities.AddressOps;

@@ -42,7 +43,7 @@
import java.util.Observer;


public class ShenandoahHeapRegion extends ContiguousSpace implements LiveRegionsProvider {
public class ShenandoahHeapRegion extends VMObject implements LiveRegionsProvider {
private static int EmptyUncommitted;
private static int EmptyCommitted;
private static int Regular;
@@ -59,6 +60,10 @@
private static CIntegerField RegionNumberField;
private static CIntegerField RegionSizeBytesShiftField;

private static AddressField BottomField;
private static AddressField TopField;
private static AddressField EndField;

private ShenandoahHeap heap;

static {
@@ -74,6 +79,9 @@ static private synchronized void initialize(TypeDataBase db) {
RegionSizeBytesField = type.getCIntegerField("RegionSizeBytes");
RegionStateField = type.getField("_state");
RegionNumberField = type.getCIntegerField("_region_number");
BottomField = type.getAddressField("_bottom");
TopField = type.getAddressField("_top");
EndField = type.getAddressField("_end");

RegionSizeBytesShiftField = type.getCIntegerField("RegionSizeBytesShift");

@@ -105,6 +113,18 @@ public void setHeap(ShenandoahHeap heap) {
this.heap = heap;
}

public Address bottom() {
return BottomField.getValue(addr);
}

public Address top() {
return TopField.getValue(addr);
}

public Address end() {
return EndField.getValue(addr);
}

@Override
public int hashCode() {
return (int)regionNumber();

0 comments on commit 8c5531b

Please sign in to comment.