8314573: G1: Heap resizing at Remark does not take existing eden regions into account
Backport-of: 762b652912939b37fbd68955617705c62b9fc3a5
diff --git a/src/hotspot/share/gc/g1/g1HeapSizingPolicy.cpp b/src/hotspot/share/gc/g1/g1HeapSizingPolicy.cpp
index 1a7c11a..8645b84 100644
--- a/src/hotspot/share/gc/g1/g1HeapSizingPolicy.cpp
+++ b/src/hotspot/share/gc/g1/g1HeapSizingPolicy.cpp
@@ -217,7 +217,14 @@
// Capacity, free and used after the GC counted as full regions to
// include the waste in the following calculations.
const size_t capacity_after_gc = _g1h->capacity();
- const size_t used_after_gc = capacity_after_gc - _g1h->unused_committed_regions_in_bytes();
+ const size_t used_after_gc = capacity_after_gc -
+ _g1h->unused_committed_regions_in_bytes() -
+ // Discount space used by current Eden to establish a
+ // situation during Remark similar to at the end of full
+ // GC where eden is empty. During Remark there can be an
+ // arbitrary number of eden regions which would skew the
+ // results.
+ _g1h->eden_regions_count() * HeapRegion::GrainBytes;
size_t minimum_desired_capacity = target_heap_capacity(used_after_gc, MinHeapFreeRatio);
size_t maximum_desired_capacity = target_heap_capacity(used_after_gc, MaxHeapFreeRatio);