Skip to content

Commit

Permalink
[GR-53541] [GR-53407] OutOfMemoryError-related fixes.
Browse files Browse the repository at this point in the history
PullRequest: graal/17649
  • Loading branch information
christianhaeubl committed May 13, 2024
2 parents 259b37b + 7922f87 commit 6be3d60
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
Expand Up @@ -24,6 +24,7 @@
*/
package com.oracle.svm.core.genscavenge;

import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;
import static com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer;
import static com.oracle.svm.core.snippets.KnownIntrinsics.readReturnAddress;

Expand Down Expand Up @@ -73,6 +74,7 @@
import com.oracle.svm.core.heap.OutOfMemoryUtil;
import com.oracle.svm.core.heap.PhysicalMemory;
import com.oracle.svm.core.heap.ReferenceHandler;
import com.oracle.svm.core.heap.ReferenceHandlerThread;
import com.oracle.svm.core.heap.ReferenceMapIndex;
import com.oracle.svm.core.heap.RestrictHeapAccess;
import com.oracle.svm.core.heap.RuntimeCodeCacheCleaner;
Expand All @@ -86,6 +88,7 @@
import com.oracle.svm.core.snippets.ImplicitExceptions;
import com.oracle.svm.core.stack.JavaStackWalk;
import com.oracle.svm.core.stack.JavaStackWalker;
import com.oracle.svm.core.stack.StackOverflowCheck;
import com.oracle.svm.core.thread.JavaVMOperation;
import com.oracle.svm.core.thread.NativeVMOperation;
import com.oracle.svm.core.thread.NativeVMOperationData;
Expand Down Expand Up @@ -192,12 +195,19 @@ boolean collectWithoutAllocating(GCCause cause, boolean forceFullGC) {
enqueueCollectOperation(data);

boolean outOfMemory = data.getOutOfMemory();
if (outOfMemory && SerialGCOptions.IgnoreMaxHeapSizeWhileInVMOperation.getValue() && VMOperation.isInProgress()) {
if (outOfMemory && SerialGCOptions.IgnoreMaxHeapSizeWhileInVMOperation.getValue() && inVMInternalCode()) {
outOfMemory = false;
}
return outOfMemory;
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
private static boolean inVMInternalCode() {
return VMOperation.isInProgress() ||
ReferenceHandlerThread.isReferenceHandlerThread() ||
StackOverflowCheck.singleton().isYellowZoneAvailable();
}

@Uninterruptible(reason = "Used as a transition between uninterruptible and interruptible code", calleeMustBe = false)
private void enqueueCollectOperation(CollectionVMOperationData data) {
collectOperation.enqueue(data);
Expand Down
Expand Up @@ -103,7 +103,8 @@ public Integer getValue(OptionValues values) {
@Option(help = "Develop demographics of the object references visited. Serial GC only.", type = OptionType.Debug)//
public static final HostedOptionKey<Boolean> GreyToBlackObjRefDemographics = new HostedOptionKey<>(false, SerialGCOptions::serialGCOnly);

@Option(help = "Ignore the maximum heap size while a VM operation is executed.", type = OptionType.Expert)//
/* Option should be renamed, see GR-53798. */
@Option(help = "Ignore the maximum heap size while in VM-internal code.", type = OptionType.Expert)//
public static final HostedOptionKey<Boolean> IgnoreMaxHeapSizeWhileInVMOperation = new HostedOptionKey<>(false, SerialGCOptions::serialGCOnly);

private SerialGCOptions() {
Expand Down
Expand Up @@ -24,6 +24,7 @@
*/
package com.oracle.svm.core.graal.snippets;

import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;
import static jdk.graal.compiler.core.common.spi.ForeignCallDescriptor.CallSideEffect.NO_SIDE_EFFECT;
import static jdk.graal.compiler.nodes.extended.BranchProbabilityNode.EXTREMELY_SLOW_PATH_PROBABILITY;
import static jdk.graal.compiler.nodes.extended.BranchProbabilityNode.probability;
Expand Down Expand Up @@ -210,6 +211,7 @@ private static void onYellowZoneMadeAvailable(int oldState, int newState) {
}

@Override
@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public boolean isYellowZoneAvailable() {
return yellowZoneStateTL.get() > STATE_YELLOW_ENABLED;
}
Expand Down
Expand Up @@ -24,13 +24,16 @@
*/
package com.oracle.svm.core.heap;

import static com.oracle.svm.core.Uninterruptible.CALLED_FROM_UNINTERRUPTIBLE_CODE;

import org.graalvm.nativeimage.CurrentIsolate;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.IsolateThread;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

import com.oracle.svm.core.SubstrateOptions;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.feature.AutomaticallyRegisteredFeature;
import com.oracle.svm.core.feature.InternalFeature;
import com.oracle.svm.core.thread.ThreadingSupportImpl;
Expand All @@ -56,6 +59,7 @@ public static void start() {
}
}

@Uninterruptible(reason = CALLED_FROM_UNINTERRUPTIBLE_CODE, mayBeInlined = true)
public static boolean isReferenceHandlerThread() {
if (isSupported()) {
return CurrentIsolate.getCurrentThread() == singleton().isolateThread;
Expand Down
Expand Up @@ -40,6 +40,7 @@

import org.graalvm.nativeimage.Platforms;

import com.oracle.svm.core.NeverInline;
import com.oracle.svm.core.Uninterruptible;
import com.oracle.svm.core.WeakIdentityHashMap;
import com.oracle.svm.core.annotate.Alias;
Expand Down Expand Up @@ -504,17 +505,22 @@ protected JavaMonitor getOrCreateMonitorFromMap(Object obj, boolean createIfNotE
if (existingMonitor != null || !createIfNotExisting) {
return existingMonitor;
}
long startTicks = JfrTicks.elapsedTicks();
JavaMonitor newMonitor = newMonitorLock();
JavaMonitor previousEntry = additionalMonitors.put(obj, newMonitor);
VMError.guarantee(previousEntry == null, "Replaced monitor in secondary storage map");
JavaMonitorInflateEvent.emit(obj, startTicks, cause);
return newMonitor;
return createMonitorAndAddToMap(obj, cause);
} finally {
additionalMonitorsLock.unlock();
}
}

@NeverInline("Prevent deadlocks in case of an OutOfMemoryError.")
private JavaMonitor createMonitorAndAddToMap(Object obj, MonitorInflationCause cause) {
long startTicks = JfrTicks.elapsedTicks();
JavaMonitor newMonitor = newMonitorLock();
JavaMonitor previousEntry = additionalMonitors.put(obj, newMonitor);
VMError.guarantee(previousEntry == null, "Replaced monitor in secondary storage map");
JavaMonitorInflateEvent.emit(obj, startTicks, cause);
return newMonitor;
}

protected JavaMonitor newMonitorLock() {
return new JavaMonitor();
}
Expand Down

0 comments on commit 6be3d60

Please sign in to comment.