Search in sources :

Example 1 with JNINativeMethod

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

the class JNIFunctions method RegisterNatives.

/*
     * jint RegisterNatives(JNIEnv *env, jclass clazz, const JNINativeMethod *methods, jint
     * nMethods);
     */
@CEntryPoint
@CEntryPointOptions(prologue = JNIEnvironmentEnterPrologue.class, exceptionHandler = JNIExceptionHandlerReturnJniErr.class, publishAs = Publish.NotPublished, include = CEntryPointOptions.NotIncludedAutomatically.class)
static int RegisterNatives(JNIEnvironment env, JNIObjectHandle hclazz, JNINativeMethod methods, int nmethods) {
    Class<?> clazz = JNIObjectHandles.getObject(hclazz);
    Pointer p = (Pointer) methods;
    for (int i = 0; i < nmethods; i++) {
        JNINativeMethod entry = (JNINativeMethod) p;
        String name = CTypeConversion.toJavaString(entry.name());
        String signature = CTypeConversion.toJavaString(entry.signature());
        CFunctionPointer fnPtr = entry.fnPtr();
        String declaringClass = MetaUtil.toInternalName(clazz.getName());
        JNINativeLinkage linkage = JNIReflectionDictionary.singleton().getLinkage(declaringClass, name, signature);
        if (linkage != null) {
            linkage.setEntryPoint(fnPtr);
        } else {
            return JNIErrors.JNI_ERR();
        }
        p = p.add(SizeOf.get(JNINativeMethod.class));
    }
    return JNIErrors.JNI_OK();
}
Also used : JNINativeMethod(com.oracle.svm.jni.nativeapi.JNINativeMethod) InvokeCFunctionPointer(org.graalvm.nativeimage.c.function.InvokeCFunctionPointer) CIntPointer(org.graalvm.nativeimage.c.type.CIntPointer) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer) CShortPointer(org.graalvm.nativeimage.c.type.CShortPointer) JNIJavaVMPointer(com.oracle.svm.jni.nativeapi.JNIJavaVMPointer) Pointer(org.graalvm.word.Pointer) InvokeCFunctionPointer(org.graalvm.nativeimage.c.function.InvokeCFunctionPointer) CFunctionPointer(org.graalvm.nativeimage.c.function.CFunctionPointer) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) JNINativeLinkage(com.oracle.svm.jni.access.JNINativeLinkage) 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 JNINativeLinkage (com.oracle.svm.jni.access.JNINativeLinkage)1 JNIJavaVMPointer (com.oracle.svm.jni.nativeapi.JNIJavaVMPointer)1 JNINativeMethod (com.oracle.svm.jni.nativeapi.JNINativeMethod)1 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)1 CFunctionPointer (org.graalvm.nativeimage.c.function.CFunctionPointer)1 InvokeCFunctionPointer (org.graalvm.nativeimage.c.function.InvokeCFunctionPointer)1 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)1 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)1 CShortPointer (org.graalvm.nativeimage.c.type.CShortPointer)1 WordPointer (org.graalvm.nativeimage.c.type.WordPointer)1 Pointer (org.graalvm.word.Pointer)1