Search in sources :

Example 1 with Safepoint

use of com.oracle.svm.core.thread.Safepoint in project graal by oracle.

the class PosixCEntryPointSnippets method detachThreadMT.

@SubstrateForeignCallTarget
@Uninterruptible(reason = "Thread state going away.")
@RestrictHeapAccess(access = RestrictHeapAccess.Access.NO_ALLOCATION, reason = "Must not (thread-local) allocate while detaching a thread.")
private static int detachThreadMT(IsolateThread thread) {
    int result = Errors.NO_ERROR;
    /*
         * Set thread status to exited. This makes me immune to safepoints (the safepoint mechanism
         * ignores me). Also clear any pending safepoint requests, since I will not honor them.
         */
    VMThreads.StatusSupport.setStatusExited();
    Safepoint.setSafepointRequested(Safepoint.SafepointRequestValues.RESET);
    // try-finally because try-with-resources can call interruptible code
    VMThreads.THREAD_MUTEX.lockNoTransition();
    try {
        detachJavaLangThreadMT(thread);
        // clear references to thread to avoid unintended use
        writeCurrentVMThread(VMThreads.nullThread());
        PosixVMThreads.VMThreadTL.set(VMThreads.nullThread());
        VMThreads.detachThread(thread);
    } catch (Throwable t) {
        result = Errors.UNSPECIFIED;
    } finally {
        VMThreads.THREAD_MUTEX.unlock();
        LibC.free(thread);
    }
    return result;
}
Also used : Safepoint(com.oracle.svm.core.thread.Safepoint) SubstrateForeignCallTarget(com.oracle.svm.core.snippets.SubstrateForeignCallTarget) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible) RestrictHeapAccess(com.oracle.svm.core.annotate.RestrictHeapAccess)

Aggregations

RestrictHeapAccess (com.oracle.svm.core.annotate.RestrictHeapAccess)1 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)1 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)1 Safepoint (com.oracle.svm.core.thread.Safepoint)1