Skip to content

Commit 955de4d

Browse files
committed
introduce ReportFatalErroronOutOfMemoryError
1 parent 7dd9362 commit 955de4d

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateGCOptions.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, Object> values, Long oldV
8484
@Option(help = "Exit on the first occurrence of an out-of-memory error that is thrown because the Java heap is out of memory.", type = OptionType.Expert)//
8585
public static final RuntimeOptionKey<Boolean> ExitOnOutOfMemoryError = new NotifyGCRuntimeOptionKey<>(false);
8686

87+
@Option(help = "Report a fatal error on the first occurrence of an out-of-memory error that is thrown because the Java heap is out of memory.", type = OptionType.Expert)//
88+
public static final RuntimeOptionKey<Boolean> ReportFatalErrorOnOutOfMemoryError = new RuntimeOptionKey<>(false);
89+
8790
@Option(help = "Ignore calls to System.gc().", type = OptionType.Expert)//
8891
public static final RuntimeOptionKey<Boolean> DisableExplicitGC = new NotifyGCRuntimeOptionKey<>(false);
8992

substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/OutOfMemoryUtil.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@
2424
*/
2525
package com.oracle.svm.core.heap;
2626

27+
import org.graalvm.nativeimage.ImageSingletons;
28+
import org.graalvm.nativeimage.LogHandler;
29+
import org.graalvm.nativeimage.Platform;
30+
import org.graalvm.nativeimage.impl.InternalPlatform;
31+
2732
import com.oracle.svm.core.SubstrateGCOptions;
2833
import com.oracle.svm.core.SubstrateOptions;
2934
import com.oracle.svm.core.Uninterruptible;
@@ -68,6 +73,16 @@ public static OutOfMemoryError reportOutOfMemoryError(OutOfMemoryError error) {
6873
VMError.shouldNotReachHere("ExitOnOutOfMemoryError can only be used if the LibC support is present.");
6974
}
7075
}
76+
77+
if (SubstrateGCOptions.ReportFatalErrorOnOutOfMemoryError.getValue()) {
78+
if (Platform.includedIn(InternalPlatform.NATIVE_ONLY.class)) {
79+
Log.log().string("Reporting Fatal Error due to java.lang.OutOfMemoryError: ").exception(error);
80+
} else {
81+
Log.log().string("Reporting Fatal Error due to java.lang.OutOfMemoryError").newline();
82+
}
83+
ImageSingletons.lookup(LogHandler.class).fatalError();
84+
}
85+
7186
throw error;
7287
}
7388
}

0 commit comments

Comments
 (0)