Skip to content

Commit

Permalink
Generate only one heap dump on OOME
Browse files Browse the repository at this point in the history
  • Loading branch information
galderz committed Jul 26, 2023
1 parent 3731936 commit 9a8c441
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import java.lang.ref.Reference;

import com.oracle.svm.core.jdk.UninterruptibleUtils.AtomicBoolean;
import org.graalvm.compiler.api.replacements.Fold;
import org.graalvm.nativeimage.CurrentIsolate;
import org.graalvm.nativeimage.IsolateThread;
Expand Down Expand Up @@ -117,6 +118,8 @@ public final class GCImpl implements GC {
private UnsignedWord collectionEpoch = WordFactory.zero();
private long lastWholeHeapExaminedTimeMillis = -1;

private final AtomicBoolean outOfMemoryReported = new AtomicBoolean(false);

@Platforms(Platform.HOSTED_ONLY.class)
GCImpl() {
this.policy = CollectionPolicy.getInitialPolicy();
Expand Down Expand Up @@ -151,15 +154,15 @@ public void maybeCollectOnAllocation() {
outOfMemory = collectWithoutAllocating(GenScavengeGCCause.OnAllocation, false);
}
if (outOfMemory) {
heapSizeExceeded();
reportJavaOutOfMemory();
throw OutOfMemoryUtil.heapSizeExceeded();
}
}

private static void heapSizeExceeded() {
if (SubstrateOptions.isHeapDumpOnOutOfMemoryError()) {
private void reportJavaOutOfMemory() {
if (SubstrateOptions.isHeapDumpOnOutOfMemoryError() && outOfMemoryReported.compareAndSet(false, true)) {
VMRuntime.dumpHeapOnOutOfMemoryError();
}
throw OutOfMemoryUtil.heapSizeExceeded();
}

@Override
Expand All @@ -173,7 +176,8 @@ private void collect(GCCause cause, boolean forceFullGC) {
if (!hasNeverCollectPolicy()) {
boolean outOfMemory = collectWithoutAllocating(cause, forceFullGC);
if (outOfMemory) {
heapSizeExceeded();
reportJavaOutOfMemory();
throw OutOfMemoryUtil.heapSizeExceeded();
}
}
}
Expand Down

0 comments on commit 9a8c441

Please sign in to comment.