@@ -462,7 +462,7 @@ size_t ShenandoahHeapRegion::block_size(const HeapWord* p) const {
462462 }
463463}
464464
465- void ShenandoahHeapRegion::setup_sizes (size_t max_heap_size) {
465+ size_t ShenandoahHeapRegion::setup_sizes (size_t max_heap_size) {
466466 // Absolute minimums we should not ever break.
467467 static const size_t MIN_REGION_SIZE = 256 *K;
468468
@@ -537,14 +537,28 @@ void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
537537 region_size = ShenandoahRegionSize;
538538 }
539539
540- // Make sure region size is at least one large page, if enabled.
541- // The heap sizes would be rounded by heap initialization code by
542- // page size, so we need to round up the region size too, to cover
543- // the heap exactly.
540+ // Make sure region size and heap size are page aligned.
541+ // If large pages are used, we ensure that region size is aligned to large page size if
542+ // heap size is large enough to accommodate minimal number of regions. Otherwise, we align
543+ // region size to regular page size.
544+
545+ // Figure out page size to use, and aligns up heap to page size
546+ int page_size = os::vm_page_size ();
544547 if (UseLargePages) {
545- region_size = MAX2 (region_size, os::large_page_size ());
548+ size_t large_page_size = os::large_page_size ();
549+ max_heap_size = align_up (max_heap_size, large_page_size);
550+ if ((max_heap_size / align_up (region_size, large_page_size)) >= MIN_NUM_REGIONS) {
551+ page_size = (int )large_page_size;
552+ } else {
553+ // Should have been checked during argument initialization
554+ assert (!ShenandoahUncommit, " Uncommit requires region size aligns to large page size" );
555+ }
556+ } else {
557+ max_heap_size = align_up (max_heap_size, page_size);
546558 }
547559
560+ // Align region size to page size
561+ region_size = align_up (region_size, page_size);
548562 int region_size_log = log2_long ((jlong) region_size);
549563 // Recalculate the region size to make sure it's a power of
550564 // 2. This means that region_size is the largest power of 2 that's
@@ -614,6 +628,8 @@ void ShenandoahHeapRegion::setup_sizes(size_t max_heap_size) {
614628 byte_size_in_proper_unit (HumongousThresholdBytes), proper_unit_for_byte_size (HumongousThresholdBytes));
615629 log_info (gc, init)(" Max TLAB size: " SIZE_FORMAT " %s" ,
616630 byte_size_in_proper_unit (MaxTLABSizeBytes), proper_unit_for_byte_size (MaxTLABSizeBytes));
631+
632+ return max_heap_size;
617633}
618634
619635void ShenandoahHeapRegion::do_commit () {
0 commit comments