Search in sources :

Example 1 with SubstrateForeignCallTarget

use of com.oracle.svm.core.snippets.SubstrateForeignCallTarget in project graal by oracle.

the class PosixCEntryPointSnippets method failFatally.

@Uninterruptible(reason = "Unknown thread state.")
@SubstrateForeignCallTarget
private static void failFatally(int code, CCharPointer message) {
    FILE stderr = fdopen(2, FAIL_FATALLY_FDOPEN_MODE.get());
    fprintfSD(stderr, FAIL_FATALLY_MESSAGE_FORMAT.get(), message, code);
    LibC.exit(code);
}
Also used : FILE(com.oracle.svm.core.posix.headers.Stdio.FILE) SubstrateForeignCallTarget(com.oracle.svm.core.snippets.SubstrateForeignCallTarget) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 2 with SubstrateForeignCallTarget

use of com.oracle.svm.core.snippets.SubstrateForeignCallTarget in project graal by oracle.

the class PosixCEntryPointSnippets method createIsolate.

@Uninterruptible(reason = "Thread state not yet set up.")
@SubstrateForeignCallTarget
private static int createIsolate(CEntryPointCreateIsolateParameters parameters, int vmThreadSize) {
    WordPointer isolate = StackValue.get(SizeOf.get(WordPointer.class));
    isolate.write(Word.nullPointer());
    int error = PosixIsolates.create(isolate, parameters);
    if (error != Errors.NO_ERROR) {
        return error;
    }
    if (UseHeapBaseRegister.getValue()) {
        setHeapBase(PosixIsolates.getHeapBase(isolate.read()));
    }
    if (MultiThreaded.getValue()) {
        PosixVMThreads.ensureInitialized();
    }
    return attachThread(isolate.read(), vmThreadSize);
}
Also used : WordPointer(org.graalvm.nativeimage.c.type.WordPointer) Safepoint(com.oracle.svm.core.thread.Safepoint) SubstrateForeignCallTarget(com.oracle.svm.core.snippets.SubstrateForeignCallTarget) Uninterruptible(com.oracle.svm.core.annotate.Uninterruptible)

Example 3 with SubstrateForeignCallTarget

use of com.oracle.svm.core.snippets.SubstrateForeignCallTarget 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 4 with SubstrateForeignCallTarget

use of com.oracle.svm.core.snippets.SubstrateForeignCallTarget 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)

Example 5 with SubstrateForeignCallTarget

use of com.oracle.svm.core.snippets.SubstrateForeignCallTarget in project graal by oracle.

the class ArraycopySnippets method doArraycopy.

/**
 * The actual implementation of {@link System#arraycopy}, called via the foreign call
 * {@link #ARRAYCOPY}.
 */
@SubstrateForeignCallTarget
private static void doArraycopy(Object fromArray, int fromIndex, Object toArray, int toIndex, int length) {
    if (fromArray == null || toArray == null) {
        throw new NullPointerException();
    }
    DynamicHub fromHub = KnownIntrinsics.readHub(fromArray);
    DynamicHub toHub = KnownIntrinsics.readHub(toArray);
    if (LayoutEncoding.isPrimitiveArray(fromHub.getLayoutEncoding())) {
        if (fromArray == toArray && fromIndex < toIndex) {
            boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
            primitiveCopyBackward(fromArray, fromIndex, fromArray, toIndex, length, fromHub.getLayoutEncoding());
            return;
        } else if (fromHub == toHub) {
            boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
            primitiveCopyForward(fromArray, fromIndex, toArray, toIndex, length, fromHub.getLayoutEncoding());
            return;
        }
    } else if (LayoutEncoding.isObjectArray(fromHub.getLayoutEncoding())) {
        if (fromArray == toArray && fromIndex < toIndex) {
            boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
            objectCopyBackward(fromArray, fromIndex, fromArray, toIndex, length, fromHub.getLayoutEncoding());
            return;
        } else if (fromHub == toHub || toHub.isAssignableFrom(fromHub)) {
            boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
            objectCopyForward(fromArray, fromIndex, toArray, toIndex, length, fromHub.getLayoutEncoding());
            return;
        } else if (LayoutEncoding.isObjectArray(toHub.getLayoutEncoding())) {
            boundsCheck(fromArray, fromIndex, toArray, toIndex, length);
            objectStoreCheckCopyForward(fromArray, fromIndex, toArray, toIndex, length);
            return;
        }
    }
    throw new ArrayStoreException();
}
Also used : DynamicHub(com.oracle.svm.core.hub.DynamicHub) SubstrateForeignCallTarget(com.oracle.svm.core.snippets.SubstrateForeignCallTarget)

Aggregations

SubstrateForeignCallTarget (com.oracle.svm.core.snippets.SubstrateForeignCallTarget)11 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)5 Safepoint (com.oracle.svm.core.thread.Safepoint)4 FastThreadLocalObject (com.oracle.svm.core.threadlocal.FastThreadLocalObject)2 IsolateThread (org.graalvm.nativeimage.IsolateThread)2 UnsignedWord (org.graalvm.word.UnsignedWord)2 NeverInline (com.oracle.svm.core.annotate.NeverInline)1 RestrictHeapAccess (com.oracle.svm.core.annotate.RestrictHeapAccess)1 DynamicHub (com.oracle.svm.core.hub.DynamicHub)1 FILE (com.oracle.svm.core.posix.headers.Stdio.FILE)1 CodePointer (org.graalvm.nativeimage.c.function.CodePointer)1 WordPointer (org.graalvm.nativeimage.c.type.WordPointer)1 Pointer (org.graalvm.word.Pointer)1