Search in sources :

Example 1 with JNIAccessibleMethodDescriptor

use of com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor 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)

Example 2 with JNIAccessibleMethodDescriptor

use of com.oracle.svm.jni.access.JNIAccessibleMethodDescriptor 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)

Aggregations

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