Skip to content
Permalink
Browse files

8241845: Shenandoah: align ShenandoahHeapRegions to cache lines

Reviewed-by: rkennke
  • Loading branch information
shipilev committed Mar 31, 2020
1 parent 83a9afa commit de7ea8db9204b60e353eb9889926bb3de35e4e3d
@@ -181,6 +181,7 @@ jint ShenandoahHeap::initialize() {

size_t heap_page_size = UseLargePages ? (size_t)os::large_page_size() : (size_t)os::vm_page_size();
size_t bitmap_page_size = UseLargePages ? (size_t)os::large_page_size() : (size_t)os::vm_page_size();
size_t region_page_size = UseLargePages ? (size_t)os::large_page_size() : (size_t)os::vm_page_size();

//
// Reserve and commit memory for heap
@@ -279,6 +280,15 @@ jint ShenandoahHeap::initialize() {
//
// Create regions and region sets
//
size_t region_align = align_up(sizeof(ShenandoahHeapRegion), SHENANDOAH_CACHE_LINE_SIZE);
size_t region_storage_size = align_up(region_align * _num_regions, region_page_size);

ReservedSpace region_storage(region_storage_size, region_page_size);
MemTracker::record_virtual_memory_type(region_storage.base(), mtGC);
if (!region_storage.special()) {
os::commit_memory_or_exit(region_storage.base(), region_storage_size, region_page_size, false,
"Cannot commit region memory");
}

_regions = NEW_C_HEAP_ARRAY(ShenandoahHeapRegion*, _num_regions, mtGC);
_free_set = new ShenandoahFreeSet(this, _num_regions);
@@ -290,7 +300,10 @@ jint ShenandoahHeap::initialize() {
for (size_t i = 0; i < _num_regions; i++) {
HeapWord* start = (HeapWord*)sh_rs.base() + ShenandoahHeapRegion::region_size_words() * i;
bool is_committed = i < num_committed_regions;
ShenandoahHeapRegion* r = new ShenandoahHeapRegion(start, i, is_committed);
void* loc = region_storage.base() + i * region_align;

ShenandoahHeapRegion* r = new (loc) ShenandoahHeapRegion(start, i, is_committed);
assert(is_aligned(r, SHENANDOAH_CACHE_LINE_SIZE), "Sanity");

_marking_context->initialize_top_at_mark_start(r);
_regions[i] = r;
@@ -36,7 +36,7 @@
class VMStructs;
class ShenandoahHeapRegionStateConstant;

class ShenandoahHeapRegion : public CHeapObj<mtGC> {
class ShenandoahHeapRegion {
friend class VMStructs;
friend class ShenandoahHeapRegionStateConstant;
private:
@@ -262,9 +262,6 @@ class ShenandoahHeapRegion : public CHeapObj<mtGC> {

HeapWord* _update_watermark;

// Claim some space at the end to protect next region
shenandoah_padding(0);

public:
ShenandoahHeapRegion(HeapWord* start, size_t index, bool committed);

@@ -30,7 +30,9 @@
// versions here. Shared code provides DEFAULT_CACHE_LINE_SIZE, which is
// inconveniently large by default.

#define SHENANDOAH_CACHE_LINE_SIZE 64

#define shenandoah_padding(id) \
DEFINE_PAD_MINUS_SIZE(id, 64, 0)
DEFINE_PAD_MINUS_SIZE(id, SHENANDOAH_CACHE_LINE_SIZE, 0)

#endif // SHARE_GC_SHENANDOAH_SHENANDOAHPADDING_INLINE_HPP

0 comments on commit de7ea8d

Please sign in to comment.