8031538: G1 eden usage is sometimes higher than target eden (printed Eden size)
Summary: When recalculating the number of target eden size, correctly consider the amount of existing eden regions in the target calculation.
Reviewed-by: tschatzl
Contributed-by: Staffan Friberg <staffan.friberg@oracle.com>
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Thu Mar 05 16:43:26 2015 +0100
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectedHeap.hpp Fri Mar 06 09:07:33 2015 +0100
@@ -110,6 +110,7 @@
void empty_list();
bool is_empty() { return _length == 0; }
uint length() { return _length; }
+ uint eden_length() { return length() - survivor_length(); }
uint survivor_length() { return _survivor_length; }
// Currently we do not keep track of the used byte sum for the
@@ -119,7 +120,7 @@
// we'll report the more accurate information then.
size_t eden_used_bytes() {
assert(length() >= survivor_length(), "invariant");
- return (size_t) (length() - survivor_length()) * HeapRegion::GrainBytes;
+ return (size_t) eden_length() * HeapRegion::GrainBytes;
}
size_t survivor_used_bytes() {
return (size_t) survivor_length() * HeapRegion::GrainBytes;
--- a/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp Thu Mar 05 16:43:26 2015 +0100
+++ b/hotspot/src/share/vm/gc_implementation/g1/g1CollectorPolicy.cpp Fri Mar 06 09:07:33 2015 +0100
@@ -537,15 +537,12 @@
// This is how many young regions we already have (currently: the survivors).
uint base_min_length = recorded_survivor_regions();
- // This is the absolute minimum young length, which ensures that we
- // can allocate one eden region in the worst-case.
- uint absolute_min_length = base_min_length + 1;
- uint desired_min_length =
- calculate_young_list_desired_min_length(base_min_length);
- if (desired_min_length < absolute_min_length) {
- desired_min_length = absolute_min_length;
- }
-
+ uint desired_min_length = calculate_young_list_desired_min_length(base_min_length);
+ // This is the absolute minimum young length. Ensure that we
+ // will at least have one eden region available for allocation.
+ uint absolute_min_length = base_min_length + MAX2(_g1->young_list()->eden_length(), (uint)1);
+ // If we shrank the young list target it should not shrink below the current size.
+ desired_min_length = MAX2(desired_min_length, absolute_min_length);
// Calculate the absolute and desired max bounds.
// We will try our best not to "eat" into the reserve.
@@ -1925,7 +1922,7 @@
// [Newly Young Regions ++ Survivors from last pause].
uint survivor_region_length = young_list->survivor_length();
- uint eden_region_length = young_list->length() - survivor_region_length;
+ uint eden_region_length = young_list->eden_length();
init_cset_region_lengths(eden_region_length, survivor_region_length);
HeapRegion* hr = young_list->first_survivor_region();