Skip to content

Commit c911fd7

Browse files
committed
introduce ReportFatalErroronOutOfMemoryError
1 parent 7dd9362 commit c911fd7

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-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: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@
2424
*/
2525
package com.oracle.svm.core.heap;
2626

27+
import org.graalvm.nativeimage.ImageSingletons;
28+
import org.graalvm.nativeimage.LogHandler;
29+
2730
import com.oracle.svm.core.SubstrateGCOptions;
2831
import com.oracle.svm.core.SubstrateOptions;
2932
import com.oracle.svm.core.Uninterruptible;
@@ -68,6 +71,12 @@ public static OutOfMemoryError reportOutOfMemoryError(OutOfMemoryError error) {
6871
VMError.shouldNotReachHere("ExitOnOutOfMemoryError can only be used if the LibC support is present.");
6972
}
7073
}
74+
75+
if (SubstrateGCOptions.ReportFatalErrorOnOutOfMemoryError.getValue()) {
76+
Log.log().string("Reporting Fatal Error due to java.lang.OutOfMemoryError: ").exception(error);
77+
ImageSingletons.lookup(LogHandler.class).fatalError();
78+
}
79+
7180
throw error;
7281
}
7382
}

0 commit comments

Comments
 (0)