Skip to content

Commit

Permalink
[GR-8829] Java code can execute during ongoing safepoint in newly att…
Browse files Browse the repository at this point in the history
…ached thread.

PullRequest: graal/1225
  • Loading branch information
peter-hofer committed Mar 27, 2018
2 parents bec1dc9 + e972d4c commit 1011454
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,11 @@ public static int attachThreadSnippet(Isolate isolate, @ConstantParameter int vm
if (MultiThreaded.getValue()) {
writeCurrentVMThread(VMThreads.nullThread());
}
return runtimeCall(ATTACH_THREAD, isolate, vmThreadSize);
int result = runtimeCall(ATTACH_THREAD, isolate, vmThreadSize);
if (MultiThreaded.getValue() && result == Errors.NO_ERROR) {
Safepoint.transitionNativeToJava();
}
return result;
}

@Uninterruptible(reason = "Thread state not yet set up.")
Expand All @@ -219,7 +223,6 @@ private static int attachThread(Isolate isolate, int vmThreadSize) {
PosixVMThreads.IsolateTL.set(thread, isolate);
}
writeCurrentVMThread(thread);
VMThreads.StatusSupport.setStatusJavaUnguarded(thread);
}
return Errors.NO_ERROR;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,33 +111,20 @@ public static IsolateThread nextThreadFromList(IsolateThread cur) {
* must be the first method called in every thread.
*/
@Uninterruptible(reason = "Reason: Thread register not yet set up.")
public static void attachThread(IsolateThread vmThread) {
assert StatusSupport.isStatusCreated(vmThread) : "Status should be initialized on creation.";
// Manipulating the VMThread list requires the lock for
// changing the status and for notification.
// But the VMThread for the current thread is not set up yet,
// so the locking must be without transitions.
attachThreadUnderLock(vmThread);
}

/**
* The body of {@link #attachThread} that is executed under the VMThreads mutex. With that mutex
* held, callees do not need to be annotated with {@link Uninterruptible}.
* <p>
* Using try-finally rather than a try-with-resources to avoid implicitly calling
* {@link Throwable#addSuppressed(Throwable)}, which I can not annotate as uninterruptible.
*/
@Uninterruptible(reason = "Reason: Thread register not yet set up.")
public static void attachThreadUnderLock(IsolateThread vmThread) {
VMMutex lock = VMThreads.THREAD_MUTEX;
public static void attachThread(IsolateThread thread) {
assert StatusSupport.isStatusCreated(thread) : "Status should be initialized on creation.";
// Manipulating the VMThread list requires the lock, but the IsolateThread is not set up
// yet, so the locking must be without transitions. Not using try-with-resources to avoid
// implicitly calling addSuppressed(), which is not uninterruptible.
VMThreads.THREAD_MUTEX.lockNoTransition();
try {
lock.lockNoTransition();
VMThreads.THREAD_MUTEX.guaranteeIsLocked("Must hold the VMThreads lock.");
nextTL.set(vmThread, head);
head = vmThread;
nextTL.set(thread, head);
head = thread;
StatusSupport.setStatusNative(thread);
VMThreads.THREAD_LIST_CONDITION.broadcast();
} finally {
lock.unlock();
VMThreads.THREAD_MUTEX.unlock();
}
}

Expand Down Expand Up @@ -240,6 +227,7 @@ public static void setStatusNative() {
statusTL.set(STATUS_IN_NATIVE);
}

@Uninterruptible(reason = "Called from uninterruptible code.", mayBeInlined = true)
public static void setStatusNative(IsolateThread vmThread) {
statusTL.setVolatile(vmThread, STATUS_IN_NATIVE);
}
Expand Down

0 comments on commit 1011454

Please sign in to comment.