Search in sources :

Example 1 with JNIObjectHandle

use of com.oracle.svm.jni.nativeapi.JNIObjectHandle in project graal by oracle.

the class JNIFunctions method NewGlobalRef.

/*
     * jobject NewGlobalRef(JNIEnv *env, jobject obj);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullHandle.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIObjectHandle NewGlobalRef(JNIEnvironment env, JNIObjectHandle handle) {
    JNIObjectHandle result = JNIObjectHandles.nullHandle();
    Object obj = JNIObjectHandles.getObject(handle);
    if (obj != null) {
        result = (JNIObjectHandle) JNIGlobalHandles.singleton().create(obj);
    }
    return result;
}
Also used : JNIObjectHandle(com.oracle.svm.jni.nativeapi.JNIObjectHandle) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 2 with JNIObjectHandle

use of com.oracle.svm.jni.nativeapi.JNIObjectHandle in project graal by oracle.

the class JNIFunctions method NewWeakGlobalRef.

/*
     * jweak NewWeakGlobalRef(JNIEnv *env, jobject obj);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullHandle.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIObjectHandle NewWeakGlobalRef(JNIEnvironment env, JNIObjectHandle handle) {
    JNIObjectHandle result = JNIObjectHandles.nullHandle();
    Object obj = JNIObjectHandles.getObject(handle);
    if (obj != null) {
        result = (JNIObjectHandle) JNIGlobalHandles.singleton().createWeak(obj);
    }
    return result;
}
Also used : JNIObjectHandle(com.oracle.svm.jni.nativeapi.JNIObjectHandle) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 3 with JNIObjectHandle

use of com.oracle.svm.jni.nativeapi.JNIObjectHandle in project graal by oracle.

the class JNIFunctions method ThrowNew.

/*
     * jint ThrowNew(JNIEnv *env, jclass clazz, const char *message);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerVoid.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static void ThrowNew(JNIEnvironment env, JNIObjectHandle clazzHandle, CCharPointer message) throws Throwable {
    Class<?> clazz = JNIObjectHandles.getObject(clazzHandle);
    JNIMethodId ctor = JNIReflectionDictionary.singleton().getMethodID(clazz, "<init>", "(Ljava/lang/String;)V", false);
    JNIObjectHandle messageHandle = NewStringUTF(env, message);
    NewObjectWithObjectArgFunctionPointer newObject = (NewObjectWithObjectArgFunctionPointer) env.getFunctions().getNewObject();
    JNIObjectHandle exception = newObject.invoke(env, clazzHandle, ctor, messageHandle);
    throw (Throwable) JNIObjectHandles.getObject(exception);
}
Also used : JNIMethodId(com.oracle.svm.jni.nativeapi.JNIMethodId) JNIObjectHandle(com.oracle.svm.jni.nativeapi.JNIObjectHandle) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Aggregations

CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)3 JNIObjectHandle (com.oracle.svm.jni.nativeapi.JNIObjectHandle)3 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)3 JNIMethodId (com.oracle.svm.jni.nativeapi.JNIMethodId)1