Search in sources :

Example 1 with JNIJavaCallWrapperMethod

use of com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod in project graal by oracle.

the class JNIAccessFeature method addMethod.

private void addMethod(Executable method, DuringAnalysisAccessImpl access) {
    JNIAccessibleClass jniClass = addClass(method.getDeclaringClass(), access);
    JNIAccessibleMethodDescriptor descriptor = JNIAccessibleMethodDescriptor.of(method);
    jniClass.addMethodIfAbsent(descriptor, d -> {
        MetaAccessProvider wrappedMetaAccess = access.getMetaAccess().getWrapped();
        JNIJavaCallWrapperMethod varargsCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VARARGS, false, wrappedMetaAccess, nativeLibraries);
        JNIJavaCallWrapperMethod arrayCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.ARRAY, false, wrappedMetaAccess, nativeLibraries);
        JNIJavaCallWrapperMethod valistCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VA_LIST, false, wrappedMetaAccess, nativeLibraries);
        Stream<JNIJavaCallWrapperMethod> wrappers = Stream.of(varargsCallWrapper, arrayCallWrapper, valistCallWrapper);
        JNIJavaCallWrapperMethod varargsNonvirtualCallWrapper = null;
        JNIJavaCallWrapperMethod arrayNonvirtualCallWrapper = null;
        JNIJavaCallWrapperMethod valistNonvirtualCallWrapper = null;
        if (!Modifier.isStatic(method.getModifiers())) {
            varargsNonvirtualCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VARARGS, true, wrappedMetaAccess, nativeLibraries);
            arrayNonvirtualCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.ARRAY, true, wrappedMetaAccess, nativeLibraries);
            valistNonvirtualCallWrapper = new JNIJavaCallWrapperMethod(method, CallVariant.VA_LIST, true, wrappedMetaAccess, nativeLibraries);
            wrappers = Stream.concat(wrappers, Stream.of(varargsNonvirtualCallWrapper, arrayNonvirtualCallWrapper, valistNonvirtualCallWrapper));
        }
        JNIAccessibleMethod jniMethod = new JNIAccessibleMethod(method.getModifiers(), jniClass, varargsCallWrapper, arrayCallWrapper, valistCallWrapper, varargsNonvirtualCallWrapper, arrayNonvirtualCallWrapper, valistNonvirtualCallWrapper);
        wrappers.forEach(wrapper -> {
            AnalysisMethod analysisWrapper = access.getUniverse().lookup(wrapper);
            access.getBigBang().addRootMethod(analysisWrapper);
            // ensures C calling convention
            analysisWrapper.registerAsEntryPoint(jniMethod);
        });
        return jniMethod;
    });
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) JNIJavaCallWrapperMethod(com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Aggregations

AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)1 JNIJavaCallWrapperMethod (com.oracle.svm.jni.hosted.JNIJavaCallWrapperMethod)1 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)1