Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.heap.GCCause;
import com.oracle.svm.core.heap.OutOfMemoryUtil;
import com.oracle.svm.core.heap.PhysicalMemory;
import com.oracle.svm.core.util.UserError;
import com.oracle.svm.util.ReflectionUtil;
Expand Down Expand Up @@ -217,4 +218,12 @@ static boolean shouldCollectYoungGenSeparately(boolean defaultValue) {
default boolean isOutOfMemory(UnsignedWord usedBytes) {
return usedBytes.aboveThan(getMaximumHeapSize());
}

/**
* Invoked after a garbage collection when the maximum heap size has been exceeded. Can be
* overridden to recover from OOM.
*/
default void onMaximumHeapSizeExceeded() {
throw OutOfMemoryUtil.heapSizeExceeded();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ public boolean isOutOfMemory(UnsignedWord usedBytes) {

return super.isOutOfMemory(usedBytes);
}

@Override
public void onMaximumHeapSizeExceeded() {
if (isOutOfMemory(HeapImpl.getAccounting().getUsedBytes())) {
super.onMaximumHeapSizeExceeded();
} else {
/* No longer out-of-memory - update the heap size parameters to reflect that. */
GCImpl.getPolicy().updateSizeParameters();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,7 @@ private void collect(GCCause cause, boolean forceFullGC) {
if (!hasNeverCollectPolicy()) {
boolean outOfMemory = collectWithoutAllocating(cause, forceFullGC);
if (outOfMemory) {
if (getPolicy().isOutOfMemory(HeapImpl.getAccounting().getUsedBytes())) {
throw OutOfMemoryUtil.heapSizeExceeded();
} else {
GCImpl.getPolicy().updateSizeParameters();
}
getPolicy().onMaximumHeapSizeExceeded();
}
}
}
Expand Down
Loading