Skip to content

Commit

Permalink
Minor changes.
Browse files Browse the repository at this point in the history
  • Loading branch information
christianhaeubl committed Dec 17, 2019
1 parent 3f13571 commit edbcac3
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -856,7 +856,7 @@ public <T extends CodeInfo> boolean visitCode(T codeInfo, CodeAccess<T> access)
}
}

@TargetClass(value = java.lang.Runtime.class, onlyWith = TrueIfUseCardRememberedSetHeap.class)
@TargetClass(value = java.lang.Runtime.class, onlyWith = UseCardRememberedSetHeap.class)
@SuppressWarnings({"static-method"})
final class Target_java_lang_Runtime {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;

class TrueIfUseCardRememberedSetHeap implements BooleanSupplier {
@Platforms(Platform.HOSTED_ONLY.class)
TrueIfUseCardRememberedSetHeap() {
@Platforms(Platform.HOSTED_ONLY.class)
class UseCardRememberedSetHeap implements BooleanSupplier {
UseCardRememberedSetHeap() {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
*/
package com.oracle.svm.core;

import org.graalvm.nativeimage.hosted.Feature;
import org.graalvm.nativeimage.ImageSingletons;
import org.graalvm.nativeimage.Platform;
import org.graalvm.nativeimage.Platforms;
import org.graalvm.nativeimage.hosted.Feature;

import com.oracle.svm.core.annotate.AutomaticFeature;
import com.oracle.svm.core.annotate.Uninterruptible;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,12 @@ public static void transitionNativeToJava() {
}
}

public static void transitionNativeToVM() {
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static boolean fastTransitionNativeToVM() {
return StatusSupport.compareAndSetNativeToNewStatus(StatusSupport.STATUS_IN_VM);
}

public static void slowTransitionNativeToVM() {
int newStatus = StatusSupport.STATUS_IN_VM;
boolean needSlowPath = !StatusSupport.compareAndSetNativeToNewStatus(newStatus);
if (BranchProbabilityNode.probability(BranchProbabilityNode.VERY_SLOW_PATH_PROBABILITY, needSlowPath)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@
* </ul>
*/
public final class VMOperationControl {
private static final VMOperationThread dedicatedVMOperationThread = new VMOperationThread();

private final VMOperationThread dedicatedVMOperationThread;
private final WorkQueues mainQueues;
private final WorkQueues immediateQueues;
private final OpInProgress inProgress;

@Platforms(Platform.HOSTED_ONLY.class)
VMOperationControl() {
this.dedicatedVMOperationThread = new VMOperationThread();
this.mainQueues = new WorkQueues("main", true);
this.immediateQueues = new WorkQueues("immediate", false);
this.inProgress = new OpInProgress();
Expand All @@ -111,28 +111,32 @@ static VMOperationControl get() {

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static VMOperationThread getDedicatedVMOperationThread() {
assert dedicatedVMOperationThread != null;
return dedicatedVMOperationThread;
VMOperationControl control = get();
assert control.dedicatedVMOperationThread != null;
return control.dedicatedVMOperationThread;
}

public static void startVMOperationThread() {
assert UseDedicatedVMOperationThread.getValue();
assert get().mainQueues.isEmpty();

Thread thread = new Thread(dedicatedVMOperationThread, "VMOperationThread");
VMOperationControl control = get();
assert control.mainQueues.isEmpty();

Thread thread = new Thread(control.dedicatedVMOperationThread, "VMOperationThread");
thread.setDaemon(true);
thread.start();
dedicatedVMOperationThread.waitUntilStarted();
control.dedicatedVMOperationThread.waitUntilStarted();
}

public static void shutdownAndDetachVMOperationThread() {
assert UseDedicatedVMOperationThread.getValue();
VMOperationControl control = get();
JavaVMOperation.enqueueBlockingNoSafepoint("Stop VMOperationThread", () -> {
dedicatedVMOperationThread.shutdown();
control.dedicatedVMOperationThread.shutdown();
});

waitUntilVMOperationThreadDetached();
assert get().mainQueues.isEmpty();
assert control.mainQueues.isEmpty();
}

@RestrictHeapAccess(access = Access.NO_ALLOCATION, reason = "Called during teardown")
Expand Down Expand Up @@ -169,7 +173,7 @@ public static boolean isDedicatedVMOperationThread() {
@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static boolean isDedicatedVMOperationThread(IsolateThread thread) {
if (UseDedicatedVMOperationThread.getValue()) {
return thread == dedicatedVMOperationThread.getIsolateThread();
return thread == get().dedicatedVMOperationThread.getIsolateThread();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.graalvm.word.WordFactory;

import com.oracle.svm.core.annotate.ForceFixedRegisterReads;
import com.oracle.svm.core.annotate.NeverInline;
import com.oracle.svm.core.annotate.RestrictHeapAccess;
import com.oracle.svm.core.annotate.Uninterruptible;
import com.oracle.svm.core.c.function.CEntryPointErrors;
Expand Down Expand Up @@ -282,19 +283,7 @@ public void detachThread(IsolateThread thread) {

cleanupBeforeDetach(thread);

/*
* Make me immune to safepoints (the safepoint mechanism ignores me). We are calling
* functions that are not marked as @Uninterruptible during the detach process. We hold the
* THREAD_MUTEX, so we know that we are not going to be interrupted by a safepoint. But a
* safepoint can already be requested, or our safepoint counter can reach 0 - so it is still
* possible that we enter the safepoint slow path.
*
* Between setting the status and acquiring the TREAD_MUTEX, we must not access the heap.
* Otherwise, we risk a race with the GC as this thread will continue executing even though
* the VM is at a safepoint.
*/
StatusSupport.setStatusIgnoreSafepoints();
THREAD_MUTEX.lockNoTransition();
setStatusIgnoreSafepointsAndLock();
OSThreadHandle threadToCleanup;
try {
detachThreadInSafeContext(thread);
Expand All @@ -320,6 +309,24 @@ public void detachThread(IsolateThread thread) {
cleanupExitedOsThread(threadToCleanup);
}

/*
* Make me immune to safepoints (the safepoint mechanism ignores me). We are calling functions
* that are not marked as @Uninterruptible during the detach process. We hold the THREAD_MUTEX,
* so we know that we are not going to be interrupted by a safepoint. But a safepoint can
* already be requested, or our safepoint counter can reach 0 - so it is still possible that we
* enter the safepoint slow path.
*
* Between setting the status and acquiring the TREAD_MUTEX, we must not access the heap.
* Otherwise, we risk a race with the GC as this thread will continue executing even though the
* VM is at a safepoint.
*/
@Uninterruptible(reason = "Called from uninterruptible code.")
@NeverInline("Prevent that anything floats between setting the status and acquiring the mutex.")
private static void setStatusIgnoreSafepointsAndLock() {
StatusSupport.setStatusIgnoreSafepoints();
THREAD_MUTEX.lockNoTransition();
}

@Uninterruptible(reason = "Isolate thread will be freed.", calleeMustBe = false)
private static void releaseThread(IsolateThread thread) {
THREAD_MUTEX.guaranteeIsOwner("This mutex must be locked to prevent that a GC is triggered while detaching a thread from the heap");
Expand Down Expand Up @@ -505,7 +512,7 @@ public static class StatusSupport {
* {@link IsolateThread} memory has been allocated for the thread, but the thread is not on
* the VMThreads list yet.
*/
public static final int STATUS_CREATED = STATUS_ILLEGAL + 1;
public static final int STATUS_CREATED = 0;
/** The thread is running in Java code. */
public static final int STATUS_IN_JAVA = STATUS_CREATED + 1;
/** The thread has been requested to stop at a safepoint. */
Expand Down

0 comments on commit edbcac3

Please sign in to comment.