--- old/src/share/vm/gc/g1/g1CollectedHeap.cpp 2015-08-13 12:06:31.371957148 -0400 +++ new/src/share/vm/gc/g1/g1CollectedHeap.cpp 2015-08-13 12:06:30.771922866 -0400 @@ -1185,7 +1185,7 @@ } else { curr_region = NULL; } - _hrm.shrink_at(curr_index); + _hrm.shrink_at(curr_index, 1); uncommitted_regions++; } --- old/src/share/vm/gc/g1/heapRegionManager.cpp 2015-08-13 12:06:34.492135417 -0400 +++ new/src/share/vm/gc/g1/heapRegionManager.cpp 2015-08-13 12:06:33.896101363 -0400 @@ -426,7 +426,7 @@ (num_last_found = find_empty_from_idx_reverse(cur, &idx_last_found)) > 0) { uint to_remove = MIN2(num_regions_to_remove - removed, num_last_found); - uncommit_regions(idx_last_found + num_last_found - to_remove, to_remove); + shrink_at(idx_last_found + num_last_found - to_remove, to_remove); cur -= num_last_found; removed += to_remove; @@ -437,11 +437,15 @@ return removed; } -void HeapRegionManager::shrink_at(uint index) { - assert(is_available(index), err_msg("Expected available region at index %u", index)); - HeapRegion* curr_region = _regions.get_by_index(index); - assert(curr_region->is_free(), err_msg("Expected free region at index %u", index)); - uncommit_regions(index, 1); +void HeapRegionManager::shrink_at(uint index, size_t num_regions) { +#ifdef ASSERT + for (uint i = index; i < (index + num_regions); i++) { + assert(is_available(i), err_msg("Expected available region at index %u", i)); + assert(at(i)->is_empty(), err_msg("Expected empty region at index %u", i)); + assert(at(i)->is_free(), err_msg("Expected free region at index %u", i)); + } +#endif + uncommit_regions(index, num_regions); } uint HeapRegionManager::find_empty_from_idx_reverse(uint start_idx, uint* res_idx) const { --- old/src/share/vm/gc/g1/heapRegionManager.hpp 2015-08-13 12:06:37.616313913 -0400 +++ new/src/share/vm/gc/g1/heapRegionManager.hpp 2015-08-13 12:06:37.016279631 -0400 @@ -241,8 +241,9 @@ // Return the actual number of uncommitted regions. uint shrink_by(uint num_regions_to_remove); - // Uncommit the region at the specified index, which must be available and free. - void shrink_at(uint index); + // Uncommit a number of regions starting at the specified index, which must be available, + // empty, and free. + void shrink_at(uint index, size_t num_regions); void verify();