Skip to content

Commit 59d0ce3

Browse files
committed
[GR-62544] Reinstate size-based full collection decision in adaptive policy.
PullRequest: graal/20152
2 parents d4f0b58 + 4e42860 commit 59d0ce3

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/AdaptiveCollectionPolicy.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626

2727
import static com.oracle.svm.core.genscavenge.CollectionPolicy.shouldCollectYoungGenSeparately;
2828

29-
import jdk.graal.compiler.word.Word;
3029
import org.graalvm.word.UnsignedWord;
3130

3231
import com.oracle.svm.core.Uninterruptible;
@@ -35,6 +34,8 @@
3534
import com.oracle.svm.core.util.TimeUtils;
3635
import com.oracle.svm.core.util.UnsignedUtils;
3736

37+
import jdk.graal.compiler.word.Word;
38+
3839
/**
3940
* A garbage collection policy that balances throughput and memory footprint.
4041
*
@@ -163,7 +164,8 @@ public String getName() {
163164
public boolean shouldCollectCompletely(boolean followingIncrementalCollection) { // should_attempt_scavenge
164165
guaranteeSizeParametersInitialized();
165166

166-
if (!followingIncrementalCollection && shouldCollectYoungGenSeparately(!SerialGCOptions.useCompactingOldGen())) {
167+
boolean collectYoungSeparately = shouldCollectYoungGenSeparately(!SerialGCOptions.useCompactingOldGen());
168+
if (!followingIncrementalCollection && collectYoungSeparately) {
167169
/*
168170
* With a copying collector, default to always doing an incremental collection first
169171
* because we expect most of the objects in the young generation to be garbage, and we
@@ -181,6 +183,12 @@ public boolean shouldCollectCompletely(boolean followingIncrementalCollection) {
181183
*/
182184
return true;
183185
}
186+
187+
if (!collectYoungSeparately && followingIncrementalCollection) {
188+
// Don't override the earlier decision to not do a full GC below (and prolong the pause)
189+
return false;
190+
}
191+
184192
if (minorCountSinceMajorCollection * avgMinorPause.getAverage() >= CONSECUTIVE_MINOR_TO_MAJOR_COLLECTION_PAUSE_TIME_RATIO * avgMajorPause.getPaddedAverage()) {
185193
/*
186194
* When we do many incremental collections in a row because they reclaim sufficient
@@ -190,7 +198,17 @@ public boolean shouldCollectCompletely(boolean followingIncrementalCollection) {
190198
return true;
191199
}
192200

193-
return false;
201+
UnsignedWord youngUsed = HeapImpl.getHeapImpl().getYoungGeneration().getChunkBytes();
202+
UnsignedWord oldUsed = HeapImpl.getHeapImpl().getOldGeneration().getChunkBytes();
203+
204+
/*
205+
* If the remaining free space in the old generation is less than what is expected to be
206+
* needed by the next collection, do a full collection now.
207+
*/
208+
UnsignedWord averagePromoted = UnsignedUtils.fromDouble(avgPromoted.getPaddedAverage());
209+
UnsignedWord promotionEstimate = UnsignedUtils.min(averagePromoted, youngUsed);
210+
UnsignedWord oldFree = oldSize.subtract(oldUsed);
211+
return promotionEstimate.aboveThan(oldFree);
194212
}
195213

196214
private void updateAverages(boolean isSurvivorOverflow, UnsignedWord survivedChunkBytes, UnsignedWord promotedChunkBytes) {

0 commit comments

Comments
 (0)