Skip to content

Commit eb1d4f4

Browse files
committed
[GR-71271] Don't do an incremental GC before a forced full GC with CompactingOldGen.
PullRequest: graal/22581
2 parents 25e8c9f + c8182c1 commit eb1d4f4

File tree

5 files changed

+24
-11
lines changed

5 files changed

+24
-11
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,13 @@ public String getName() {
162162
}
163163

164164
@Override
165-
public boolean shouldCollectCompletely(boolean followingIncrementalCollection) { // should_attempt_scavenge
165+
public boolean shouldCollectCompletely(boolean followingIncrementalCollection, boolean forcedCompleteCollection) { // should_attempt_scavenge
166166
guaranteeSizeParametersInitialized();
167167

168168
boolean collectYoungSeparately = shouldCollectYoungGenSeparately(!SerialGCOptions.useCompactingOldGen());
169+
if (forcedCompleteCollection && !collectYoungSeparately) {
170+
return true;
171+
}
169172
if (!followingIncrementalCollection && collectYoungSeparately) {
170173
/*
171174
* With a copying collector, default to always doing an incremental collection first

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ public void onCollectionEnd(boolean completeCollection, GCCause cause) {
207207
public static final class OnlyIncrementally extends BasicPolicy {
208208

209209
@Override
210-
public boolean shouldCollectCompletely(boolean followingIncrementalCollection) {
210+
public boolean shouldCollectCompletely(boolean followingIncrementalCollection, boolean forcedCompleteCollection) {
211211
return false;
212212
}
213213

@@ -220,7 +220,7 @@ public String getName() {
220220
public static final class OnlyCompletely extends BasicPolicy {
221221

222222
@Override
223-
public boolean shouldCollectCompletely(boolean followingIncrementalCollection) {
223+
public boolean shouldCollectCompletely(boolean followingIncrementalCollection, boolean forcedCompleteCollection) {
224224
return followingIncrementalCollection || !shouldCollectYoungGenSeparately(false);
225225
}
226226

@@ -238,7 +238,7 @@ public boolean shouldCollectOnAllocation() {
238238
}
239239

240240
@Override
241-
public boolean shouldCollectCompletely(boolean followingIncrementalCollection) {
241+
public boolean shouldCollectCompletely(boolean followingIncrementalCollection, boolean forcedCompleteCollection) {
242242
throw VMError.shouldNotReachHere("Collection must not be initiated in the first place");
243243
}
244244

@@ -255,8 +255,12 @@ public String getName() {
255255
public static final class BySpaceAndTime extends BasicPolicy {
256256

257257
@Override
258-
public boolean shouldCollectCompletely(boolean followingIncrementalCollection) {
259-
if (!followingIncrementalCollection && shouldCollectYoungGenSeparately(false)) {
258+
public boolean shouldCollectCompletely(boolean followingIncrementalCollection, boolean forcedCompleteCollection) {
259+
boolean collectYoungSeparately = shouldCollectYoungGenSeparately(false);
260+
if (forcedCompleteCollection && !collectYoungSeparately) {
261+
return true;
262+
}
263+
if (!followingIncrementalCollection && collectYoungSeparately) {
260264
return false;
261265
}
262266
return estimateUsedHeapAtNextIncrementalCollection().aboveThan(getMaximumHeapSize()) ||

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ static boolean shouldCollectYoungGenSeparately(boolean defaultValue) {
138138
* @param followingIncrementalCollection whether an incremental collection has just finished in
139139
* the same safepoint. Implementations would typically decide whether to follow up
140140
* with a full collection based on whether enough memory was reclaimed.
141+
* @param forcedCompleteCollection whether a complete collection will eventually be forced. The
142+
* policy can still return {@code false} to do an incremental collection first.
141143
*/
142-
boolean shouldCollectCompletely(boolean followingIncrementalCollection);
144+
boolean shouldCollectCompletely(boolean followingIncrementalCollection, boolean forcedCompleteCollection);
143145

144146
/**
145147
* The current limit for the size of the entire heap, which is less than or equal to

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ private boolean doCollectImpl(GCCause cause, long initialBeginNanoTime, boolean
319319

320320
ChunkBasedCommittedMemoryProvider.get().beforeGarbageCollection();
321321

322-
boolean incremental = !forceNoIncremental && !policy.shouldCollectCompletely(false);
322+
boolean incremental = !forceNoIncremental && !policy.shouldCollectCompletely(false, forceFullGC);
323323
boolean outOfMemory = false;
324324

325325
if (incremental) {
@@ -330,7 +330,7 @@ private boolean doCollectImpl(GCCause cause, long initialBeginNanoTime, boolean
330330
JfrGCEvents.emitGCPhasePauseEvent(getCollectionEpoch(), "Incremental GC", startTicks);
331331
}
332332
}
333-
if (!incremental || outOfMemory || forceFullGC || policy.shouldCollectCompletely(incremental)) {
333+
if (!incremental || outOfMemory || forceFullGC || policy.shouldCollectCompletely(incremental, forceFullGC)) {
334334
long beginNanoTime = initialBeginNanoTime;
335335
if (incremental) {
336336
beginNanoTime = System.nanoTime();

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,14 @@ public String getName() {
6464
}
6565

6666
@Override
67-
public boolean shouldCollectCompletely(boolean followingIncrementalCollection) {
67+
public boolean shouldCollectCompletely(boolean followingIncrementalCollection, boolean forcedCompleteCollection) {
6868
guaranteeSizeParametersInitialized();
6969

70-
if (!followingIncrementalCollection && shouldCollectYoungGenSeparately(false)) {
70+
boolean collectYoungSeparately = shouldCollectYoungGenSeparately(false);
71+
if (forcedCompleteCollection && !collectYoungSeparately) {
72+
return true;
73+
}
74+
if (!followingIncrementalCollection && collectYoungSeparately) {
7175
// Note that for non-ParallelGC, HotSpot resets the default of ScavengeBeforeFullGC to
7276
// false, see GCArguments::initialize.
7377
return false;

0 commit comments

Comments
 (0)