Search in sources :

Example 16 with AnalysisMethod

use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.

the class JNIFunctionTablesFeature method beforeAnalysis.

@Override
public void beforeAnalysis(BeforeAnalysisAccess arg) {
    BeforeAnalysisAccessImpl access = (BeforeAnalysisAccessImpl) arg;
    AnalysisMetaAccess metaAccess = access.getMetaAccess();
    JNIFunctionTables.create();
    NativeLibraries nativeLibraries = access.getNativeLibraries();
    AnalysisType invokeInterface = metaAccess.lookupJavaType(JNIInvokeInterface.class);
    invokeInterfaceMetadata = (StructInfo) nativeLibraries.findElementInfo(invokeInterface);
    AnalysisType functionTable = metaAccess.lookupJavaType(JNINativeInterface.class);
    functionTableMetadata = (StructInfo) nativeLibraries.findElementInfo(functionTable);
    // Manually add functions as entry points so this is only done when JNI features are enabled
    AnalysisType invokes = metaAccess.lookupJavaType(JNIInvocationInterface.class);
    AnalysisType exports = metaAccess.lookupJavaType(JNIInvocationInterface.Exports.class);
    AnalysisType functions = metaAccess.lookupJavaType(JNIFunctions.class);
    Stream<AnalysisMethod> analysisMethods = Stream.of(invokes, functions, exports).flatMap(t -> Stream.of(t.getDeclaredMethods()));
    Stream<AnalysisMethod> unimplementedMethods = Stream.of((AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJNIEnvArgument.class), (AnalysisMethod) getSingleMethod(metaAccess, UnimplementedWithJavaVMArgument.class));
    Stream.concat(analysisMethods, unimplementedMethods).forEach(method -> {
        CEntryPoint annotation = method.getAnnotation(CEntryPoint.class);
        assert annotation != null : "only entry points allowed in class";
        CEntryPointCallStubSupport.singleton().registerStubForMethod(method, () -> CEntryPointData.create(method));
    });
    ArrayList<ResolvedJavaMethod> generated = new ArrayList<>();
    MetaAccessProvider wrappedMetaAccess = metaAccess.getWrapped();
    ResolvedJavaType generatedMethodClass = wrappedMetaAccess.lookupJavaType(JNIFunctions.class);
    ConstantPool constantPool = generatedMethodClass.getDeclaredMethods()[0].getConstantPool();
    // Generate JNI field accessors
    EnumSet<JavaKind> fldKinds = jniKinds.clone();
    fldKinds.remove(JavaKind.Void);
    for (JavaKind kind : fldKinds) {
        boolean[] trueFalse = { true, false };
        for (boolean isSetter : trueFalse) {
            for (boolean isStatic : trueFalse) {
                JNIFieldAccessorMethod method = new JNIFieldAccessorMethod(kind, isSetter, isStatic, generatedMethodClass, constantPool, wrappedMetaAccess);
                AnalysisMethod analysisMethod = access.getUniverse().lookup(method);
                access.getBigBang().addRootMethod(analysisMethod).registerAsEntryPoint(method.createEntryPointData());
                generated.add(method);
            }
        }
    }
    // Generate JNI primitive array operations
    EnumSet<JavaKind> primitiveArrayKinds = jniKinds.clone();
    primitiveArrayKinds.remove(JavaKind.Void);
    primitiveArrayKinds.remove(JavaKind.Object);
    for (JavaKind kind : primitiveArrayKinds) {
        for (Operation op : Operation.values()) {
            JNIPrimitiveArrayOperationMethod method = new JNIPrimitiveArrayOperationMethod(kind, op, generatedMethodClass, constantPool, wrappedMetaAccess);
            AnalysisMethod analysisMethod = access.getUniverse().lookup(method);
            access.getBigBang().addRootMethod(analysisMethod).registerAsEntryPoint(method.createEntryPointData());
            generated.add(method);
        }
    }
    generatedMethods = generated.toArray(new ResolvedJavaMethod[0]);
}
Also used : BeforeAnalysisAccessImpl(com.oracle.svm.hosted.FeatureImpl.BeforeAnalysisAccessImpl) AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) ArrayList(java.util.ArrayList) AnalysisMetaAccess(com.oracle.graal.pointsto.meta.AnalysisMetaAccess) Operation(com.oracle.svm.jni.hosted.JNIPrimitiveArrayOperationMethod.Operation) JNIFieldAccessorMethod(com.oracle.svm.jni.hosted.JNIFieldAccessorMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) ConstantPool(jdk.vm.ci.meta.ConstantPool) JNIPrimitiveArrayOperationMethod(com.oracle.svm.jni.hosted.JNIPrimitiveArrayOperationMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 17 with AnalysisMethod

use of com.oracle.graal.pointsto.meta.AnalysisMethod 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)

Example 18 with AnalysisMethod

use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.

the class AnalysisMethodCalleeWalker method walkMethodAndCallees.

/**
 * Visit this method, and the methods it calls.
 */
VisitResult walkMethodAndCallees(AnalysisMethod method, AnalysisMethod caller, Invoke invoke, CallPathVisitor visitor) {
    if (path.contains(method)) {
        /*
             * If the method is already on the path then I am in the middle of visiting it, so just
             * keep walking.
             */
        return VisitResult.CUT;
    }
    path.add(method);
    try {
        /* Visit the method directly. */
        final VisitResult directResult = visitor.visitMethod(method, caller, invoke, path.size());
        if (directResult != VisitResult.CONTINUE) {
            return directResult;
        }
        /* Visit the callees of this method. */
        final VisitResult calleeResult = walkCallees(method, visitor);
        if (calleeResult != VisitResult.CONTINUE) {
            return calleeResult;
        }
        /* Visit all the implementations of this method, ignoring if any of them says CUT. */
        for (AnalysisMethod impl : method.getImplementations()) {
            walkMethodAndCallees(impl, caller, invoke, visitor);
        }
        return VisitResult.CONTINUE;
    } finally {
        path.remove(method);
    }
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) VisitResult(com.oracle.svm.hosted.code.AnalysisMethodCalleeWalker.CallPathVisitor.VisitResult)

Example 19 with AnalysisMethod

use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.

the class CEntryPointCallStubFeature method registerStubForMethod.

public AnalysisMethod registerStubForMethod(AnalysisMethod method, Supplier<CEntryPointData> entryPointDataSupplier) {
    assert !bigbang.getUniverse().sealed();
    return methodToStub.computeIfAbsent(method, m -> {
        CEntryPointData entryPointData = entryPointDataSupplier.get();
        CEntryPointCallStubMethod stub = CEntryPointCallStubMethod.create(method, entryPointData, bigbang.getMetaAccess());
        AnalysisMethod wrapped = bigbang.getUniverse().lookup(stub);
        bigbang.addRootMethod(wrapped).registerAsEntryPoint(entryPointData);
        return wrapped;
    });
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod)

Example 20 with AnalysisMethod

use of com.oracle.graal.pointsto.meta.AnalysisMethod in project graal by oracle.

the class NativeImageCodeCache method verifyDeoptEntries.

private void verifyDeoptEntries(ImageCodeInfo imageCodeInfo) {
    boolean hasError = false;
    List<Entry<AnalysisMethod, Set<Long>>> deoptEntries = new ArrayList<>(CompilationInfoSupport.singleton().getDeoptEntries().entrySet());
    deoptEntries.sort((e1, e2) -> e1.getKey().format("%H.%n(%p)").compareTo(e2.getKey().format("%H.%n(%p)")));
    for (Map.Entry<AnalysisMethod, Set<Long>> entry : deoptEntries) {
        HostedMethod method = imageHeap.getUniverse().lookup(entry.getKey());
        List<Long> encodedBcis = new ArrayList<>(entry.getValue());
        encodedBcis.sort((v1, v2) -> Long.compare(v1, v2));
        for (long encodedBci : encodedBcis) {
            hasError |= verifyDeoptEntry(imageCodeInfo, method, encodedBci);
        }
    }
    if (hasError) {
        VMError.shouldNotReachHere("Verification of deoptimization entry points failed");
    }
}
Also used : Entry(java.util.Map.Entry) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) Set(java.util.Set) ArrayList(java.util.ArrayList) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) HashMap(java.util.HashMap) Map(java.util.Map) NavigableMap(java.util.NavigableMap) TreeMap(java.util.TreeMap)

Aggregations

AnalysisMethod (com.oracle.graal.pointsto.meta.AnalysisMethod)31 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)7 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)6 HostedMethod (com.oracle.svm.hosted.meta.HostedMethod)6 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)5 Map (java.util.Map)5 JavaKind (jdk.vm.ci.meta.JavaKind)5 TypeState (com.oracle.graal.pointsto.typestate.TypeState)4 SubstrateMethod (com.oracle.svm.graal.meta.SubstrateMethod)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)3 CEntryPoint (org.graalvm.nativeimage.c.function.CEntryPoint)3 UnsupportedFeatureException (com.oracle.graal.pointsto.constraints.UnsupportedFeatureException)2 InvokeTypeFlow (com.oracle.graal.pointsto.flow.InvokeTypeFlow)2 AnalysisMetaAccess (com.oracle.graal.pointsto.meta.AnalysisMetaAccess)2 AnalysisUniverse (com.oracle.graal.pointsto.meta.AnalysisUniverse)2 HostedProviders (com.oracle.graal.pointsto.meta.HostedProviders)2 SubstrateForeignCallsProvider (com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider)2