Search in sources :

Example 1 with IsolateThread

use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.

the class PosixCEntryPointSnippets method attachThread.

@Uninterruptible(reason = "Thread state not yet set up.")
@SubstrateForeignCallTarget
private static int attachThread(Isolate isolate, int vmThreadSize) {
    int sanityError = PosixIsolates.checkSanity(isolate);
    if (sanityError != Errors.NO_ERROR) {
        return sanityError;
    }
    if (UseHeapBaseRegister.getValue()) {
        setHeapBase(PosixIsolates.getHeapBase(isolate));
    }
    if (MultiThreaded.getValue()) {
        if (!PosixVMThreads.isInitialized()) {
            return Errors.UNINITIALIZED_ISOLATE;
        }
        IsolateThread thread = PosixVMThreads.VMThreadTL.get();
        if (VMThreads.isNullThread(thread)) {
            // not attached
            thread = LibC.calloc(WordFactory.unsigned(1), WordFactory.unsigned(vmThreadSize));
            VMThreads.attachThread(thread);
            // Store thread and isolate in thread-local variables.
            PosixVMThreads.VMThreadTL.set(thread);
            PosixVMThreads.IsolateTL.set(thread, isolate);
        }
        writeCurrentVMThread(thread);
    }
    return Errors.NO_ERROR;
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) Safepoint(com.oracle.svm.core.thread.Safepoint) SubstrateForeignCallTarget(com.oracle.svm.core.snippets.SubstrateForeignCallTarget) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 2 with IsolateThread

use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.

the class VMThreadCounterOperation method operate.

@Override
public void operate() {
    final Log trace = Log.noopLog().string("[ThreadListOperation.operate:").string("  queuingVMThread: ").hex(getQueuingVMThread()).string("  currentVMThread: ").hex(CEntryPointContext.getCurrentIsolateThread()).flush();
    list.clear();
    for (IsolateThread isolateThread = VMThreads.firstThread(); VMThreads.isNonNullThread(isolateThread); isolateThread = VMThreads.nextThread(isolateThread)) {
        final Thread thread = JavaThreads.singleton().fromVMThread(isolateThread);
        if (thread != null) {
            list.add(thread);
        }
    }
    trace.string("]").newline().flush();
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) Log(com.oracle.svm.core.log.Log) IsolateThread(org.graalvm.nativeimage.IsolateThread)

Example 3 with IsolateThread

use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.

the class SafepointFeature method slowPathSafepointCheck.

/**
 * Stop at a safepoint.
 */
@Uninterruptible(reason = "Must not contain safepoint checks.")
private static void slowPathSafepointCheck() {
    final IsolateThread myself = CEntryPointContext.getCurrentIsolateThread();
    if (VMThreads.StatusSupport.isStatusIgnoreSafepoints(myself) || VMThreads.StatusSupport.isStatusExited(myself)) {
        return;
    }
    boolean needsCallback = ThreadingSupportImpl.singleton().needsCallbackOnSafepointCheckSlowpath();
    boolean wasFrozen = false;
    long callbackTime = 0;
    int callbackValue = 0;
    do {
        IsolateThread requestingThread = Master.singleton().getRequestingThread();
        if (requestingThread.isNonNull()) {
            if (VMOperationControl.isLockOwner()) {
                /*
                     * This can happen when a VM operation executes so many safepoint checks that
                     * safepointRequested reaches zero and enters this slow path, so we just reset
                     * the counter and return. The counter is re-initialized after the safepoint is
                     * over and normal execution continues.
                     */
                setSafepointRequested(myself, SafepointRequestValues.RESET);
                return;
            }
            VMError.guarantee(requestingThread != myself, "Must be the LockOwner");
            if (needsCallback && !wasFrozen) {
                callbackTime = System.nanoTime();
                callbackValue = getSafepointRequestedValueBeforeSafepoint(myself);
                wasFrozen = true;
            }
            Statistics.incFrozen();
            freezeAtSafepoint();
            Statistics.incThawed();
        }
    /*
             * If we entered this code as slow path for a native-to-Java transition and no safepoint
             * is actually pending, we have to do the transition to Java before continuing. However,
             * the CAS can fail if another thread is currently initiating a safepoint and already
             * brought us into state IN_SAFEPOINT, in which case we have to start over.
             */
    } while (!VMThreads.StatusSupport.isStatusJava() && !VMThreads.StatusSupport.compareAndSetNativeToJava());
    if (needsCallback) {
        if (!wasFrozen) {
            callbackTime = System.nanoTime();
            callbackValue = getSafepointRequested(myself);
        // NOTE: a concurrent safepoint request can have overwritten safepointRequested
        }
        ThreadingSupportImpl.singleton().onSafepointCheckSlowpath(callbackTime, callbackValue);
    }
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 4 with IsolateThread

use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.

the class VMThreads method detachThread.

/**
 * Remove a {@link IsolateThread} from the list of VMThreads. This method must be the last
 * method called in every thread.
 */
@Uninterruptible(reason = "Manipulates the threads list; broadcasts on changes.")
public static void detachThread(IsolateThread vmThread) {
    // Manipulating the VMThread list requires the lock for
    // changing the status and for notification.
    VMThreads.THREAD_MUTEX.guaranteeIsLocked("Must hold the VMThreads mutex.");
    // Run down the current list and remove the given VMThread.
    IsolateThread previous = nullThread();
    IsolateThread current = head;
    while (isNonNullThread(current)) {
        IsolateThread next = nextTL.get(current);
        if (current == vmThread) {
            // Splice the current element out of the list.
            if (isNullThread(previous)) {
                head = next;
            } else {
                nextTL.set(previous, next);
            }
            break;
        } else {
            previous = current;
            current = next;
        }
    }
    // Signal that the VMThreads list has changed.
    VMThreads.THREAD_LIST_CONDITION.broadcast();
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 5 with IsolateThread

use of org.graalvm.nativeimage.IsolateThread in project graal by oracle.

the class VMThreadCounterOperation method getStackTrace.

static StackTraceElement[] getStackTrace(Thread thread) {
    StackTraceElement[][] result = new StackTraceElement[1][0];
    VMOperation.enqueueBlockingSafepoint("getStackTrace", () -> {
        for (IsolateThread cur = VMThreads.firstThread(); cur.isNonNull(); cur = VMThreads.nextThread(cur)) {
            if (JavaThreads.singleton().fromVMThread(cur) == thread) {
                result[0] = getStackTrace(cur);
                break;
            }
        }
    });
    return result[0];
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread)

Aggregations

IsolateThread (org.graalvm.nativeimage.IsolateThread)20 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)5 Log (com.oracle.svm.core.log.Log)3 Safepoint (com.oracle.svm.core.thread.Safepoint)3 NeverInline (com.oracle.svm.core.annotate.NeverInline)2 SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)2 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)2 CodePointer (org.graalvm.nativeimage.c.function.CodePointer)2 Pointer (org.graalvm.word.Pointer)2 RestrictHeapAccess (com.oracle.svm.core.annotate.RestrictHeapAccess)1 KnownIntrinsics.readCallerStackPointer (com.oracle.svm.core.snippets.KnownIntrinsics.readCallerStackPointer)1 StackFrameVisitor (com.oracle.svm.core.stack.StackFrameVisitor)1 HashMap (java.util.HashMap)1 Snippet (org.graalvm.compiler.api.replacements.Snippet)1