diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateGCOptions.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateGCOptions.java index 88b3d02101a7..f302e0a11452 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateGCOptions.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/SubstrateGCOptions.java @@ -84,6 +84,9 @@ protected void onValueUpdate(EconomicMap, Object> values, Long oldV @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)// public static final RuntimeOptionKey ExitOnOutOfMemoryError = new NotifyGCRuntimeOptionKey<>(false); + @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)// + public static final RuntimeOptionKey ReportFatalErrorOnOutOfMemoryError = new RuntimeOptionKey<>(false); + @Option(help = "Ignore calls to System.gc().", type = OptionType.Expert)// public static final RuntimeOptionKey DisableExplicitGC = new NotifyGCRuntimeOptionKey<>(false); diff --git a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/OutOfMemoryUtil.java b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/OutOfMemoryUtil.java index 5ab7d43ebeb5..21b8448fab59 100644 --- a/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/OutOfMemoryUtil.java +++ b/substratevm/src/com.oracle.svm.core/src/com/oracle/svm/core/heap/OutOfMemoryUtil.java @@ -24,6 +24,11 @@ */ package com.oracle.svm.core.heap; +import org.graalvm.nativeimage.ImageSingletons; +import org.graalvm.nativeimage.LogHandler; +import org.graalvm.nativeimage.Platform; +import org.graalvm.nativeimage.impl.InternalPlatform; + import com.oracle.svm.core.SubstrateGCOptions; import com.oracle.svm.core.SubstrateOptions; import com.oracle.svm.core.Uninterruptible; @@ -68,6 +73,16 @@ public static OutOfMemoryError reportOutOfMemoryError(OutOfMemoryError error) { VMError.shouldNotReachHere("ExitOnOutOfMemoryError can only be used if the LibC support is present."); } } + + if (SubstrateGCOptions.ReportFatalErrorOnOutOfMemoryError.getValue()) { + if (Platform.includedIn(InternalPlatform.NATIVE_ONLY.class)) { + Log.log().string("Reporting Fatal Error due to java.lang.OutOfMemoryError: ").exception(error); + } else { + Log.log().string("Reporting Fatal Error due to java.lang.OutOfMemoryError").newline(); + } + ImageSingletons.lookup(LogHandler.class).fatalError(); + } + throw error; } }