Search in sources :

Example 1 with JNIMethodId

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

the class JNIReflectionDictionary method getMethodID.

public JNIMethodId getMethodID(Class<?> classObject, JNIAccessibleMethodDescriptor descriptor, boolean isStatic) {
    JNIMethodId methodID = WordFactory.nullPointer();
    JNIAccessibleClass clazz = classesByClassObject.get(classObject);
    if (clazz != null) {
        JNIAccessibleMethod method = clazz.getMethod(descriptor);
        if (method != null && method.isStatic() == isStatic) {
            // safe because JNIAccessibleMethod is immutable (non-movable)
            methodID = (JNIMethodId) Word.objectToUntrackedPointer(method);
        }
    }
    return methodID;
}
Also used : JNIMethodId(com.oracle.svm.jni.nativeapi.JNIMethodId)

Example 2 with JNIMethodId

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

the class JNIFunctions method FromReflectedMethod.

/*
     * jmethodID FromReflectedMethod(JNIEnv *env, jobject method);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullWord.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIMethodId FromReflectedMethod(JNIEnvironment env, JNIObjectHandle methodHandle) {
    JNIMethodId methodId = Word.nullPointer();
    if (JNIAccessFeature.singleton().haveJavaRuntimeReflectionSupport()) {
        Executable method = JNIObjectHandles.getObject(methodHandle);
        if (method != null) {
            boolean isStatic = Modifier.isStatic(method.getModifiers());
            JNIAccessibleMethodDescriptor descriptor = JNIAccessibleMethodDescriptor.of(method);
            methodId = JNIReflectionDictionary.singleton().getMethodID(method.getDeclaringClass(), descriptor, isStatic);
        }
    }
    return methodId;
}
Also used : JNIAccessibleMethodDescriptor(com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor) Executable(java.lang.reflect.Executable) JNIMethodId(com.oracle.svm.jni.nativeapi.JNIMethodId) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Example 3 with JNIMethodId

use of com.oracle.svm.jni.nativeapi.JNIMethodId 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

JNIMethodId (com.oracle.svm.jni.nativeapi.JNIMethodId)3 CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)2 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)2 JNIAccessibleMethodDescriptor (com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor)1 JNIObjectHandle (com.oracle.svm.jni.nativeapi.JNIObjectHandle)1 Executable (java.lang.reflect.Executable)1