Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GR-51074] Introduce ReportFatalErrorOnOutOfMemoryError #8091

Merged
merged 1 commit into from
Jan 5, 2024
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 @@ -84,6 +84,9 @@ protected void onValueUpdate(EconomicMap<OptionKey<?>, 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<Boolean> 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<Boolean> ReportFatalErrorOnOutOfMemoryError = new RuntimeOptionKey<>(false);

@Option(help = "Ignore calls to System.gc().", type = OptionType.Expert)//
public static final RuntimeOptionKey<Boolean> DisableExplicitGC = new NotifyGCRuntimeOptionKey<>(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}