@@ -467,7 +467,7 @@ size_t ShenandoahHeapRegion::block_size(const HeapWord* p) const {
467467 }
468468}
469469
470- void ShenandoahHeapRegion::setup_sizes (size_t max_heap_size) {
470+ size_t ShenandoahHeapRegion::setup_sizes (size_t max_heap_size) {
471471 // Absolute minimums we should not ever break.
472472 static const size_t MIN_REGION_SIZE = 256 *K;
473473
@@ -542,14 +542,29 @@ void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
542542 region_size = ShenandoahRegionSize;
543543 }
544544
545- // Make sure region size is at least one large page, if enabled.
546- // The heap sizes would be rounded by heap initialization code by
547- // page size, so we need to round up the region size too, to cover
548- // the heap exactly.
545+ // Make sure region size and heap size are page aligned.
546+ // If large pages are used, we ensure that region size is aligned to large page size if
547+ // heap size is large enough to accommodate minimal number of regions. Otherwise, we align
548+ // region size to regular page size.
549+
550+ // Figure out page size to use, and aligns up heap to page size
551+ int page_size = os::vm_page_size ();
549552 if (UseLargePages) {
550- region_size = MAX2 (region_size, os::large_page_size ());
553+ size_t large_page_size = os::large_page_size ();
554+ max_heap_size = align_up (max_heap_size, large_page_size);
555+ if ((max_heap_size / align_up (region_size, large_page_size)) >= MIN_NUM_REGIONS) {
556+ page_size = (int )large_page_size;
557+ } else {
558+ // Should have been checked during argument initialization
559+ assert (!ShenandoahUncommit, " Uncommit requires region size aligns to large page size" );
560+ }
561+ } else {
562+ max_heap_size = align_up (max_heap_size, page_size);
551563 }
552564
565+ // Align region size to page size
566+ region_size = align_up (region_size, page_size);
567+
553568 int region_size_log = log2i (region_size);
554569 // Recalculate the region size to make sure it's a power of
555570 // 2. This means that region_size is the largest power of 2 that's
@@ -612,6 +627,8 @@ void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
612627 guarantee (MaxTLABSizeBytes == 0 , " we should only set it once" );
613628 MaxTLABSizeBytes = MaxTLABSizeWords * HeapWordSize;
614629 assert (MaxTLABSizeBytes > MinTLABSize, " should be larger" );
630+
631+ return max_heap_size;
615632}
616633
617634void ShenandoahHeapRegion::do_commit () {
0 commit comments