Skip to content

Commit 9a8c441

Browse files
committed
Generate only one heap dump on OOME
1 parent 3731936 commit 9a8c441

File tree

1 file changed

+9
-5
lines changed
  • substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge

1 file changed

+9
-5
lines changed

substratevm/src/com.oracle.svm.core.genscavenge/src/com/oracle/svm/core/genscavenge/GCImpl.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import java.lang.ref.Reference;
3131

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

121+
private final AtomicBoolean outOfMemoryReported = new AtomicBoolean(false);
122+
120123
@Platforms(Platform.HOSTED_ONLY.class)
121124
GCImpl() {
122125
this.policy = CollectionPolicy.getInitialPolicy();
@@ -151,15 +154,15 @@ public void maybeCollectOnAllocation() {
151154
outOfMemory = collectWithoutAllocating(GenScavengeGCCause.OnAllocation, false);
152155
}
153156
if (outOfMemory) {
154-
heapSizeExceeded();
157+
reportJavaOutOfMemory();
158+
throw OutOfMemoryUtil.heapSizeExceeded();
155159
}
156160
}
157161

158-
private static void heapSizeExceeded() {
159-
if (SubstrateOptions.isHeapDumpOnOutOfMemoryError()) {
162+
private void reportJavaOutOfMemory() {
163+
if (SubstrateOptions.isHeapDumpOnOutOfMemoryError() && outOfMemoryReported.compareAndSet(false, true)) {
160164
VMRuntime.dumpHeapOnOutOfMemoryError();
161165
}
162-
throw OutOfMemoryUtil.heapSizeExceeded();
163166
}
164167

165168
@Override
@@ -173,7 +176,8 @@ private void collect(GCCause cause, boolean forceFullGC) {
173176
if (!hasNeverCollectPolicy()) {
174177
boolean outOfMemory = collectWithoutAllocating(cause, forceFullGC);
175178
if (outOfMemory) {
176-
heapSizeExceeded();
179+
reportJavaOutOfMemory();
180+
throw OutOfMemoryUtil.heapSizeExceeded();
177181
}
178182
}
179183
}

0 commit comments

Comments
 (0)