Skip to content

Commit 4e5107d

Browse files
committed
8339960: GenShen: Fix inconsistencies in generational Shenandoah behavior
Reviewed-by: ysr Backport-of: 1a7d597dad0fb3560f88f582ab760cca28cf54fd
1 parent e966cef commit 4e5107d

File tree

2 files changed

+31
-9
lines changed

2 files changed

+31
-9
lines changed

src/hotspot/share/gc/shenandoah/shenandoahFreeSet.cpp

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,7 +1314,8 @@ void ShenandoahFreeSet::find_regions_with_alloc_capacity(size_t &young_cset_regi
13141314
size_t old_collector_regions = 0;
13151315
size_t old_collector_used = 0;
13161316

1317-
for (size_t idx = 0; idx < _heap->num_regions(); idx++) {
1317+
size_t num_regions = _heap->num_regions();
1318+
for (size_t idx = 0; idx < num_regions; idx++) {
13181319
ShenandoahHeapRegion* region = _heap->get_region(idx);
13191320
if (region->is_trash()) {
13201321
// Trashed regions represent regions that had been in the collection partition but have not yet been "cleaned up".
@@ -1399,10 +1400,14 @@ void ShenandoahFreeSet::find_regions_with_alloc_capacity(size_t &young_cset_regi
13991400
old_collector_leftmost, old_collector_rightmost, old_collector_leftmost_empty, old_collector_rightmost_empty,
14001401
old_collector_regions, old_collector_used);
14011402

1402-
_partitions.establish_mutator_intervals(mutator_leftmost, mutator_rightmost, mutator_leftmost_empty, mutator_rightmost_empty,
1403+
idx_t rightmost_idx = (mutator_leftmost == max_regions)? -1: (idx_t) mutator_rightmost;
1404+
idx_t rightmost_empty_idx = (mutator_leftmost_empty == max_regions)? -1: (idx_t) mutator_rightmost_empty;
1405+
_partitions.establish_mutator_intervals(mutator_leftmost, rightmost_idx, mutator_leftmost_empty, rightmost_empty_idx,
14031406
mutator_regions, mutator_used);
1404-
_partitions.establish_old_collector_intervals(old_collector_leftmost, old_collector_rightmost, old_collector_leftmost_empty,
1405-
old_collector_rightmost_empty, old_collector_regions, old_collector_used);
1407+
rightmost_idx = (old_collector_leftmost == max_regions)? -1: (idx_t) old_collector_rightmost;
1408+
rightmost_empty_idx = (old_collector_leftmost_empty == max_regions)? -1: (idx_t) old_collector_rightmost_empty;
1409+
_partitions.establish_old_collector_intervals(old_collector_leftmost, rightmost_idx, old_collector_leftmost_empty,
1410+
rightmost_empty_idx, old_collector_regions, old_collector_used);
14061411
log_debug(gc)(" After find_regions_with_alloc_capacity(), Mutator range [" SSIZE_FORMAT ", " SSIZE_FORMAT "],"
14071412
" Old Collector range [" SSIZE_FORMAT ", " SSIZE_FORMAT "]",
14081413
_partitions.leftmost(ShenandoahFreeSetPartitionId::Mutator),
@@ -1519,8 +1524,23 @@ void ShenandoahFreeSet::establish_generation_sizes(size_t young_region_count, si
15191524
ShenandoahYoungGeneration* young_gen = heap->young_generation();
15201525
size_t region_size_bytes = ShenandoahHeapRegion::region_size_bytes();
15211526

1522-
old_gen->set_capacity(old_region_count * region_size_bytes);
1523-
young_gen->set_capacity(young_region_count * region_size_bytes);
1527+
size_t original_old_capacity = old_gen->max_capacity();
1528+
size_t new_old_capacity = old_region_count * region_size_bytes;
1529+
size_t new_young_capacity = young_region_count * region_size_bytes;
1530+
old_gen->set_capacity(new_old_capacity);
1531+
young_gen->set_capacity(new_young_capacity);
1532+
1533+
if (new_old_capacity > original_old_capacity) {
1534+
size_t region_count = (new_old_capacity - original_old_capacity) / region_size_bytes;
1535+
log_info(gc)("Transfer " SIZE_FORMAT " region(s) from %s to %s, yielding increased size: " PROPERFMT,
1536+
region_count, young_gen->name(), old_gen->name(), PROPERFMTARGS(new_old_capacity));
1537+
} else if (new_old_capacity < original_old_capacity) {
1538+
size_t region_count = (original_old_capacity - new_old_capacity) / region_size_bytes;
1539+
log_info(gc)("Transfer " SIZE_FORMAT " region(s) from %s to %s, yielding increased size: " PROPERFMT,
1540+
region_count, old_gen->name(), young_gen->name(), PROPERFMTARGS(new_young_capacity));
1541+
}
1542+
// This balances generations, so clear any pending request to balance.
1543+
old_gen->set_region_balance(0);
15241544
}
15251545
}
15261546

@@ -1687,12 +1707,12 @@ void ShenandoahFreeSet::reserve_regions(size_t to_reserve, size_t to_reserve_old
16871707
}
16881708

16891709
if (LogTarget(Info, gc, free)::is_enabled()) {
1690-
size_t old_reserve = _partitions.capacity_of(ShenandoahFreeSetPartitionId::OldCollector);
1710+
size_t old_reserve = _partitions.available_in(ShenandoahFreeSetPartitionId::OldCollector);
16911711
if (old_reserve < to_reserve_old) {
16921712
log_info(gc, free)("Wanted " PROPERFMT " for old reserve, but only reserved: " PROPERFMT,
16931713
PROPERFMTARGS(to_reserve_old), PROPERFMTARGS(old_reserve));
16941714
}
1695-
size_t reserve = _partitions.capacity_of(ShenandoahFreeSetPartitionId::Collector);
1715+
size_t reserve = _partitions.available_in(ShenandoahFreeSetPartitionId::Collector);
16961716
if (reserve < to_reserve) {
16971717
log_debug(gc)("Wanted " PROPERFMT " for young reserve, but only reserved: " PROPERFMT,
16981718
PROPERFMTARGS(to_reserve), PROPERFMTARGS(reserve));

test/hotspot/jtreg/ProblemList.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,10 @@ gc/stress/gclocker/TestGCLockerWithParallel.java 8180622 generic-all
9393
gc/stress/gclocker/TestGCLockerWithG1.java 8180622 generic-all
9494
gc/stress/TestJNIBlockFullGC/TestJNIBlockFullGC.java 8192647 generic-all
9595
gc/stress/TestStressG1Humongous.java 8286554 windows-x64
96-
gc/shenandoah/TestAllocIntArrays.java#iu-aggressive 8289220 generic-all
96+
gc/shenandoah/TestAllocIntArrays.java#iu-aggressive 8289220 generic-all # Will probably not backport this PR to JDK21
9797
gc/shenandoah/TestAllocIntArrays.java#aggressive 8289220 generic-all
98+
gc/shenandoah/TestSieveObjects.java#aggressive 8289220 generic-all
99+
gc/shenandoah/TestJcmdHeapDump.java#iu-aggressive 8336685 generic-all # Experimental IU mode to be removed
98100

99101
#############################################################################
100102

0 commit comments

Comments
 (0)