Search in sources :

Example 6 with IsolateThread

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

the class VMThreadCounterOperation method createThread.

private static Thread createThread(IsolateThread isolateThread) {
    /*
         * Either the main thread, or VMThread was started a different way. Create a new Thread
         * object and remember it for future calls, so that currentThread always returns the same
         * object.
         */
    // The thread has not been launched as java.lang.Thread, so we consider it a daemon thread.
    boolean isDaemon = true;
    final Thread thread = JavaThreads.fromTarget(new Target_java_lang_Thread(null, null, isDaemon));
    if (!assignJavaThread(isolateThread, thread, true)) {
        return currentThread.get(isolateThread);
    }
    return thread;
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread)

Example 7 with IsolateThread

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

the class Deoptimizer method deoptimizeFrame.

/**
 * Deoptimizes the given frame.
 *
 * @param ignoreNonDeoptimizable if set to true, a frame that cannot be deoptimized is ignored
 *            instead of raising an error (use for deoptimzation testing only).
 */
@NeverInline("Inlining of this method would require that we have deopt targets for callees of this method (SVM internals).")
public static void deoptimizeFrame(Pointer sourceSp, boolean ignoreNonDeoptimizable, SpeculationReason speculation) {
    DeoptimizedFrame deoptFrame = Deoptimizer.checkDeoptimized(sourceSp);
    if (deoptFrame != null) {
        /* Already deoptimized, so nothing to do. */
        registerSpeculationFailure(deoptFrame.getSourceInstalledCode(), speculation);
        return;
    }
    IsolateThread currentThread = CEntryPointContext.getCurrentIsolateThread();
    VMOperation.enqueueBlockingSafepoint("DeoptimizeFrame", () -> Deoptimizer.deoptimizeFrameOperation(sourceSp, ignoreNonDeoptimizable, speculation, currentThread));
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) NeverInline(com.oracle.svm.core.annotate.NeverInline)

Example 8 with IsolateThread

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

the class PinnedAllocatorImpl method open.

@Override
public PinnedAllocator open() {
    if (phase != LifeCyclePhase.INITIALIZED) {
        throw new PinnedAllocationLifecycleError("PinnedAllocatorImpl.open: Already opened.");
    }
    if (openPinnedAllocator.get() != null) {
        throw new PinnedAllocationLifecycleError("PinnedAllocatorImpl.open: Only one PinnedAllocator can be open per thread");
    }
    /*
         * Push this pinnedAllocatorImpl to the list of pinned allocators and try to find a pinned
         * chunk to reuse.
         */
    /* Capture "this", the tlab, and the current VMThread for the VMOperation. */
    final PinnedAllocatorImpl pinnedAllocatorImpl = this;
    final ThreadLocalAllocation.Descriptor tlab = ThreadLocalAllocation.pinnedTLAB.getAddress();
    final IsolateThread requestingVMThread = CEntryPointContext.getCurrentIsolateThread();
    VMOperation.enqueueBlockingSafepoint("PinnedAllocatorImpl.open", () -> {
        openPinnedAllocator.set(requestingVMThread, this);
        pinnedAllocatorImpl.phase = LifeCyclePhase.OPENED;
        pinnedAllocatorImpl.pushPinnedAllocatorImpl();
        pinnedAllocatorImpl.tryReuseExistingChunk(tlab);
    });
    assert phase == LifeCyclePhase.OPENED : "PinnedAllocatorImpl.open: VMOperation failed to open.";
    return this;
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread)

Example 9 with IsolateThread

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

the class VMThreadCounterOperation method detachThread.

/**
 * Detach the provided Java thread. Note that the Java thread might not have been created, in
 * which case it is null and we have nothing to do.
 */
public static void detachThread(IsolateThread vmThread) {
    /*
         * Caller must hold the lock or I, and my callees, would have to be annotated as
         * Uninterruptible.
         */
    VMThreads.THREAD_MUTEX.assertIsLocked("Should hold the VMThreads mutex.");
    // Disable thread-local allocation for this thread.
    Heap.getHeap().disableAllocation(vmThread);
    // Detach ParkEvents for this thread, if any.
    final Thread thread = currentThread.get(vmThread);
    if (thread == null) {
        return;
    }
    detachParkEvent(getUnsafeParkEvent(thread));
    detachParkEvent(getSleepParkEvent(thread));
    if (!thread.isDaemon()) {
        singleton().nonDaemonThreads.decrementAndGet();
    }
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread)

Example 10 with IsolateThread

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

the class VMThreadCounterOperation method getAllStackTraces.

static Map<Thread, StackTraceElement[]> getAllStackTraces() {
    Map<Thread, StackTraceElement[]> result = new HashMap<>();
    VMOperation.enqueueBlockingSafepoint("getAllStackTraces", () -> {
        for (IsolateThread cur = VMThreads.firstThread(); cur.isNonNull(); cur = VMThreads.nextThread(cur)) {
            result.put(JavaThreads.singleton().createIfNotExisting(cur), getStackTrace(cur));
        }
    });
    return result;
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) HashMap(java.util.HashMap) 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