Skip to content

Commit 41271d9

Browse files
[GR-70010] Only call updateSizeParameters() if DynamicCollectionPolicy is used.
PullRequest: graal/22250
2 parents 183ed23 + 0d81f9d commit 41271d9

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import com.oracle.svm.core.SubstrateOptions;
3232
import com.oracle.svm.core.Uninterruptible;
3333
import com.oracle.svm.core.heap.GCCause;
34+
import com.oracle.svm.core.heap.OutOfMemoryUtil;
3435
import com.oracle.svm.core.heap.PhysicalMemory;
3536
import com.oracle.svm.core.util.UserError;
3637
import com.oracle.svm.util.ReflectionUtil;
@@ -217,4 +218,12 @@ static boolean shouldCollectYoungGenSeparately(boolean defaultValue) {
217218
default boolean isOutOfMemory(UnsignedWord usedBytes) {
218219
return usedBytes.aboveThan(getMaximumHeapSize());
219220
}
221+
222+
/**
223+
* Invoked after a garbage collection when the maximum heap size has been exceeded. Can be
224+
* overridden to recover from OOM.
225+
*/
226+
default void onMaximumHeapSizeExceeded() {
227+
throw OutOfMemoryUtil.heapSizeExceeded();
228+
}
220229
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,14 @@ public boolean isOutOfMemory(UnsignedWord usedBytes) {
5858

5959
return super.isOutOfMemory(usedBytes);
6060
}
61+
62+
@Override
63+
public void onMaximumHeapSizeExceeded() {
64+
if (isOutOfMemory(HeapImpl.getAccounting().getUsedBytes())) {
65+
super.onMaximumHeapSizeExceeded();
66+
} else {
67+
/* No longer out-of-memory - update the heap size parameters to reflect that. */
68+
GCImpl.getPolicy().updateSizeParameters();
69+
}
70+
}
6171
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,7 @@ private void collect(GCCause cause, boolean forceFullGC) {
190190
if (!hasNeverCollectPolicy()) {
191191
boolean outOfMemory = collectWithoutAllocating(cause, forceFullGC);
192192
if (outOfMemory) {
193-
if (getPolicy().isOutOfMemory(HeapImpl.getAccounting().getUsedBytes())) {
194-
throw OutOfMemoryUtil.heapSizeExceeded();
195-
} else {
196-
GCImpl.getPolicy().updateSizeParameters();
197-
}
193+
getPolicy().onMaximumHeapSizeExceeded();
198194
}
199195
}
200196
}

0 commit comments

Comments
 (0)