Search in sources :

Example 1 with JNIAccessibleMethod

use of com.oracle.svm.jni.access.JNIAccessibleMethod in project graal by oracle.

the class JNIFunctions method ToReflectedMethod.

/*
     * jobject ToReflectedMethod(JNIEnv *env, jclass cls, jmethodID methodID, jboolean isStatic);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnNullHandle.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static JNIObjectHandle ToReflectedMethod(JNIEnvironment env, JNIObjectHandle classHandle, JNIMethodId methodId, boolean isStatic) {
    Executable result = null;
    if (JNIAccessFeature.singleton().haveJavaRuntimeReflectionSupport()) {
        JNIAccessibleMethod jniMethod = JNIReflectionDictionary.getMethodByID(methodId);
        JNIAccessibleMethodDescriptor descriptor = JNIReflectionDictionary.getMethodDescriptor(jniMethod);
        if (descriptor != null) {
            Class<?> clazz = jniMethod.getDeclaringClass().getClassObject();
            if (descriptor.isConstructor()) {
                for (Constructor<?> ctor : clazz.getDeclaredConstructors()) {
                    if (descriptor.equals(JNIAccessibleMethodDescriptor.of(ctor))) {
                        result = ctor;
                        break;
                    }
                }
            } else {
                for (Method method : clazz.getDeclaredMethods()) {
                    if (descriptor.getName().equals(method.getName())) {
                        if (descriptor.equals(JNIAccessibleMethodDescriptor.of(method))) {
                            result = method;
                            break;
                        }
                    }
                }
            }
        }
    }
    return JNIThreadLocalHandles.get().create(result);
}
Also used : JNIAccessibleMethodDescriptor(com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor) JNIAccessibleMethod(com.oracle.svm.jni.access.JNIAccessibleMethod) JNIAccessibleMethod(com.oracle.svm.jni.access.JNIAccessibleMethod) Method(java.lang.reflect.Method) JNINativeMethod(com.oracle.svm.jni.nativeapi.JNINativeMethod) Executable(java.lang.reflect.Executable) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions)

Aggregations

CEntryPointOptions (com.oracle.svm.core.c.function.CEntryPointOptions)1 JNIAccessibleMethod (com.oracle.svm.jni.access.JNIAccessibleMethod)1 JNIAccessibleMethodDescriptor (com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor)1 JNINativeMethod (com.oracle.svm.jni.nativeapi.JNINativeMethod)1 Executable (java.lang.reflect.Executable)1 Method (java.lang.reflect.Method)1 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)1