2929
3030import java .lang .ref .Reference ;
3131
32+ import com .oracle .svm .core .jdk .UninterruptibleUtils .AtomicBoolean ;
3233import org .graalvm .compiler .api .replacements .Fold ;
3334import org .graalvm .nativeimage .CurrentIsolate ;
3435import 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