Search in sources :

Example 31 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class JNIInvocationInterface method DetachCurrentThread.

/*
     * jint DetachCurrentThread(JavaVM *vm);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIJavaVMEnterAttachThreadPrologue.class, epilogue = LeaveDetachThreadEpilogue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int DetachCurrentThread(JNIJavaVM vm) {
    int result = JNIErrors.JNI_OK();
    if (!vm.equal(JNIFunctionTables.singleton().getGlobalJavaVM())) {
        result = JNIErrors.JNI_ERR();
    }
    // JNI specification requires releasing all owned monitors
    Support.releaseCurrentThreadOwnedMonitors();
    return result;
}
Also used : CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 32 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class NativeAPIImpl method isSameObject.

@CEntryPoint
@CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int isSameObject(@SuppressWarnings("unused") NativeTruffleEnv env, TruffleObjectHandle handle1, TruffleObjectHandle handle2) {
    TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class);
    Object object1 = support.resolveHandle(handle1);
    Object object2 = support.resolveHandle(handle2);
    return object1 == object2 ? 1 : 0;
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 33 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class NativeAPIImpl method getClosureObject.

@CEntryPoint
@CEntryPointOptions(prologue = EnterNativeTruffleEnvPrologue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static TruffleObjectHandle getClosureObject(NativeTruffleEnv env, PointerBase closure) {
    TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class);
    Target_com_oracle_truffle_nfi_impl_NFIContext context = lookupContext(env.context());
    TruffleObject ret = context.getClosureObject(closure.rawValue());
    return support.createGlobalHandle(ret);
}
Also used : TruffleObject(com.oracle.truffle.api.interop.TruffleObject) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 34 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class NFIInitialization method initializeNativeSimpleType.

@CEntryPoint
@CEntryPointOptions(publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void initializeNativeSimpleType(@SuppressWarnings("unused") IsolateThread thread, NativeTruffleContext ctx, CCharPointer typeName, ffi_type ffiType) {
    NativeSimpleType simpleType = NativeSimpleType.valueOf(CTypeConversion.toJavaString(typeName));
    int size = (int) ffiType.size().rawValue();
    int alignment = ffiType.alignment();
    TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class);
    Target_com_oracle_truffle_nfi_impl_NFIContext context = support.resolveContextHandle(ctx.contextHandle());
    context.initializeSimpleType(simpleType, size, alignment, ffiType.rawValue());
}
Also used : CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) NativeSimpleType(com.oracle.truffle.nfi.types.NativeSimpleType) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 35 with CEntryPoint

use of org.graalvm.nativeimage.c.function.CEntryPoint in project graal by oracle.

the class PosixThreadsFeature method pthreadStartRoutine.

@CEntryPoint
@CEntryPointOptions(prologue = PthreadStartRoutinePrologue.class, epilogue = LeaveDetachThreadEpilogue.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static WordBase pthreadStartRoutine(ThreadStartData data) {
    ObjectHandle threadHandle = data.getThreadHandle();
    UnmanagedMemory.free(data);
    Thread thread = ObjectHandles.getGlobal().get(threadHandle);
    boolean status = singleton().assignJavaThread(thread, false);
    VMError.guarantee(status, "currentThread already initialized");
    /*
         * Destroy the handle only after setting currentThread, since the lock used by destroy
         * requires the current thread.
         */
    ObjectHandles.getGlobal().destroy(threadHandle);
    /* Complete the initialization of the thread, now that it is (nearly) running. */
    setPthreadIdentifier(thread, Pthread.pthread_self());
    singleton().setNativeName(thread, thread.getName());
    singleton().noteThreadStart(thread);
    try {
        thread.run();
    } catch (Throwable ex) {
        SnippetRuntime.reportUnhandledExceptionJava(ex);
    } finally {
        exit(thread);
        singleton().noteThreadFinish(thread);
    }
    return WordFactory.nullPointer();
}
Also used : ObjectHandle(org.graalvm.nativeimage.ObjectHandle) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Aggregations

CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)81 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)26 Value (org.graalvm.polyglot.Value)23 CEntryPointContext (org.graalvm.nativeimage.c.function.CEntryPointContext)19 Context (org.graalvm.polyglot.Context)19 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)7 ObjectHandle (org.graalvm.nativeimage.ObjectHandle)5 TruffleObject (com.oracle.truffle.api.interop.TruffleObject)4 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)4 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)4 JNIObjectHandle (com.oracle.svm.jni.nativeapi.JNIObjectHandle)3 PinnedObject (org.graalvm.nativeimage.PinnedObject)3 Log (com.oracle.svm.core.log.Log)2 JNIAccessibleMethodDescriptor (com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor)2 JNINativeLinkage (com.oracle.svm.jni.access.JNINativeLinkage)2 JNIMethodId (com.oracle.svm.jni.nativeapi.JNIMethodId)2 JNINativeMethod (com.oracle.svm.jni.nativeapi.JNINativeMethod)2 Executable (java.lang.reflect.Executable)2 Method (java.lang.reflect.Method)2 ByteBuffer (java.nio.ByteBuffer)2