From 2526100c7da8162e0341313d4d33d7b2f8230ab4 Mon Sep 17 00:00:00 2001 From: Ivan Walulya Date: Mon, 24 Mar 2025 10:38:43 +0100 Subject: [PATCH 1/3] init --- src/hotspot/share/gc/g1/g1Policy.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/hotspot/share/gc/g1/g1Policy.cpp b/src/hotspot/share/gc/g1/g1Policy.cpp index 8e81327b42df6..9de7c562ded86 100644 --- a/src/hotspot/share/gc/g1/g1Policy.cpp +++ b/src/hotspot/share/gc/g1/g1Policy.cpp @@ -345,6 +345,8 @@ uint G1Policy::calculate_young_target_length(uint desired_young_length) const { uint receiving_young = MIN3(_free_regions_at_end_of_collection, desired_young_length, max_to_eat_into_reserve); + // Ensure that we provision for at least one Eden region. + receiving_young = MAX2(receiving_young, _g1h->survivor_regions_count() + 1); // We could already have allocated more regions than what we could get // above. receiving_additional_eden = allocated_young_length < receiving_young ? @@ -364,6 +366,8 @@ uint G1Policy::calculate_young_target_length(uint desired_young_length) const { uint receiving_within_reserve = MIN2(desired_young_length - free_outside_reserve, max_to_eat_into_reserve); uint receiving_young = free_outside_reserve + receiving_within_reserve; + + assert(receiving_young > _g1h->survivor_regions_count(), "We should provision for at least 1 Eden region"); // Again, we could have already allocated more than we could get. receiving_additional_eden = allocated_young_length < receiving_young ? receiving_young - allocated_young_length : 0; From 7eea1ee348ff408a3bb2a14d3a75e6c81e7cfa59 Mon Sep 17 00:00:00 2001 From: Ivan Walulya Date: Tue, 25 Mar 2025 10:09:10 +0100 Subject: [PATCH 2/3] init --- src/hotspot/share/gc/g1/g1Policy.cpp | 32 +++++++++++++++------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1Policy.cpp b/src/hotspot/share/gc/g1/g1Policy.cpp index 9de7c562ded86..87f93523dafb4 100644 --- a/src/hotspot/share/gc/g1/g1Policy.cpp +++ b/src/hotspot/share/gc/g1/g1Policy.cpp @@ -340,37 +340,39 @@ uint G1Policy::calculate_young_target_length(uint desired_young_length) const { _reserve_regions, max_to_eat_into_reserve); + uint desired_eden_length = desired_young_length - _g1h->survivor_regions_count(); + uint allocated_eden_length = allocated_young_length - _g1h->survivor_regions_count(); + if (_free_regions_at_end_of_collection <= _reserve_regions) { // Fully eat (or already eating) into the reserve, hand back at most absolute_min_length regions. - uint receiving_young = MIN3(_free_regions_at_end_of_collection, - desired_young_length, + uint receiving_eden = MIN3(_free_regions_at_end_of_collection, + desired_eden_length, max_to_eat_into_reserve); // Ensure that we provision for at least one Eden region. - receiving_young = MAX2(receiving_young, _g1h->survivor_regions_count() + 1); + receiving_eden = MAX2(receiving_eden, 1u); // We could already have allocated more regions than what we could get // above. - receiving_additional_eden = allocated_young_length < receiving_young ? - receiving_young - allocated_young_length : 0; + receiving_additional_eden = allocated_eden_length < receiving_eden ? + receiving_eden - allocated_eden_length : 0; log_trace(gc, ergo, heap)("Young target length: Fully eat into reserve " "receiving young %u receiving additional eden %u", - receiving_young, + receiving_eden, receiving_additional_eden); - } else if (_free_regions_at_end_of_collection < (desired_young_length + _reserve_regions)) { + } else if (_free_regions_at_end_of_collection < (desired_eden_length + _reserve_regions)) { // Partially eat into the reserve, at most max_to_eat_into_reserve regions. uint free_outside_reserve = _free_regions_at_end_of_collection - _reserve_regions; - assert(free_outside_reserve < desired_young_length, + assert(free_outside_reserve < desired_eden_length, "must be %u %u", - free_outside_reserve, desired_young_length); + free_outside_reserve, desired_eden_length); - uint receiving_within_reserve = MIN2(desired_young_length - free_outside_reserve, + uint receiving_within_reserve = MIN2(desired_eden_length - free_outside_reserve, max_to_eat_into_reserve); - uint receiving_young = free_outside_reserve + receiving_within_reserve; + uint receiving_eden = free_outside_reserve + receiving_within_reserve; - assert(receiving_young > _g1h->survivor_regions_count(), "We should provision for at least 1 Eden region"); // Again, we could have already allocated more than we could get. - receiving_additional_eden = allocated_young_length < receiving_young ? - receiving_young - allocated_young_length : 0; + receiving_additional_eden = allocated_eden_length < receiving_eden ? + receiving_eden - allocated_eden_length : 0; log_trace(gc, ergo, heap)("Young target length: Partially eat into reserve " "free outside reserve %u " @@ -378,7 +380,7 @@ uint G1Policy::calculate_young_target_length(uint desired_young_length) const { "receiving young %u " "receiving additional eden %u", free_outside_reserve, receiving_within_reserve, - receiving_young, receiving_additional_eden); + receiving_eden, receiving_additional_eden); } else { // No need to use the reserve. receiving_additional_eden = desired_young_length - allocated_young_length; From 041b478c3199bb6f919a3a7dc47bc9d1a9dfa6af Mon Sep 17 00:00:00 2001 From: Ivan Walulya Date: Thu, 27 Mar 2025 15:30:28 +0100 Subject: [PATCH 3/3] Thomas Review --- src/hotspot/share/gc/g1/g1Policy.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/hotspot/share/gc/g1/g1Policy.cpp b/src/hotspot/share/gc/g1/g1Policy.cpp index 87f93523dafb4..efd57581066a8 100644 --- a/src/hotspot/share/gc/g1/g1Policy.cpp +++ b/src/hotspot/share/gc/g1/g1Policy.cpp @@ -340,8 +340,9 @@ uint G1Policy::calculate_young_target_length(uint desired_young_length) const { _reserve_regions, max_to_eat_into_reserve); - uint desired_eden_length = desired_young_length - _g1h->survivor_regions_count(); - uint allocated_eden_length = allocated_young_length - _g1h->survivor_regions_count(); + uint survivor_regions_count = _g1h->survivor_regions_count(); + uint desired_eden_length = desired_young_length - survivor_regions_count; + uint allocated_eden_length = allocated_young_length - survivor_regions_count; if (_free_regions_at_end_of_collection <= _reserve_regions) { // Fully eat (or already eating) into the reserve, hand back at most absolute_min_length regions. @@ -356,9 +357,8 @@ uint G1Policy::calculate_young_target_length(uint desired_young_length) const { receiving_eden - allocated_eden_length : 0; log_trace(gc, ergo, heap)("Young target length: Fully eat into reserve " - "receiving young %u receiving additional eden %u", - receiving_eden, - receiving_additional_eden); + "receiving eden %u receiving additional eden %u", + receiving_eden, receiving_additional_eden); } else if (_free_regions_at_end_of_collection < (desired_eden_length + _reserve_regions)) { // Partially eat into the reserve, at most max_to_eat_into_reserve regions. uint free_outside_reserve = _free_regions_at_end_of_collection - _reserve_regions; @@ -377,7 +377,7 @@ uint G1Policy::calculate_young_target_length(uint desired_young_length) const { log_trace(gc, ergo, heap)("Young target length: Partially eat into reserve " "free outside reserve %u " "receiving within reserve %u " - "receiving young %u " + "receiving eden %u " "receiving additional eden %u", free_outside_reserve, receiving_within_reserve, receiving_eden, receiving_additional_eden);