From 319621c31ccb639f3fcaaa63585c0feb4c0e3bb2 Mon Sep 17 00:00:00 2001 From: Zhengyu Gu Date: Wed, 12 May 2021 19:12:07 +0000 Subject: [PATCH] 8265239: Shenandoah: Shenandoah heap region count could be off by 1 Backport-of: ff5bb8cf693c58a14063a351f535e3a55e51e8db --- src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp | 1 + src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp index f7d65771034..46616cb32be 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeap.cpp @@ -151,6 +151,7 @@ jint ShenandoahHeap::initialize() { Universe::check_alignment(init_byte_size, reg_size_bytes, "Shenandoah heap"); _num_regions = ShenandoahHeapRegion::region_count(); + assert(_num_regions == (max_byte_size / reg_size_bytes), "Must match"); // Now we know the number of regions, initialize the heuristics. initialize_heuristics(); diff --git a/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp b/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp index 2dd5f161d1d..ceba74d0544 100644 --- a/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp +++ b/src/hotspot/share/gc/shenandoah/shenandoahHeapRegion.cpp @@ -573,7 +573,7 @@ void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) { RegionSizeBytesMask = RegionSizeBytes - 1; guarantee(RegionCount == 0, "we should only set it once"); - RegionCount = max_heap_size / RegionSizeBytes; + RegionCount = align_up(max_heap_size, RegionSizeBytes) / RegionSizeBytes; guarantee(RegionCount >= MIN_NUM_REGIONS, "Should have at least minimum regions"); guarantee(HumongousThresholdWords == 0, "we should only set it once");