Search in sources :

Example 26 with AnalysisMethod

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

the class SVMHost method handleForeignCall.

@Override
public Optional<AnalysisMethod> handleForeignCall(ForeignCallDescriptor foreignCallDescriptor, ForeignCallsProvider foreignCallsProvider) {
    SubstrateForeignCallsProvider foreignCalls = (SubstrateForeignCallsProvider) foreignCallsProvider;
    /* In unit tests, we run with no registered foreign calls. */
    Optional<AnalysisMethod> targetMethod = Optional.empty();
    if (foreignCalls.getForeignCalls().size() > 0) {
        SubstrateForeignCallLinkage linkage = foreignCalls.lookupForeignCall(foreignCallDescriptor);
        targetMethod = Optional.of((AnalysisMethod) linkage.getMethod());
    }
    return targetMethod;
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) SubstrateForeignCallsProvider(com.oracle.svm.core.graal.meta.SubstrateForeignCallsProvider) SubstrateForeignCallLinkage(com.oracle.svm.core.graal.meta.SubstrateForeignCallLinkage)

Example 27 with AnalysisMethod

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

the class RuntimeStrengthenStampsPhase method processMethod.

@SuppressWarnings("try")
private void processMethod(CallTreeNode node, Deque<CallTreeNode> worklist, BigBang bb) {
    AnalysisMethod method = node.implementationMethod;
    assert method.isImplementationInvoked();
    if (node.graph == null) {
        if (method.getAnnotation(Fold.class) != null || method.getAnnotation(NodeIntrinsic.class) != null) {
            VMError.shouldNotReachHere("Parsing method annotated with @Fold or @NodeIntrinsic: " + method.format("%H.%n(%p)"));
        }
        boolean parse = false;
        DebugContext debug = bb.getDebug();
        StructuredGraph graph = method.buildGraph(debug, method, hostedProviders, Purpose.PREPARE_RUNTIME_COMPILATION);
        if (graph == null) {
            if (!method.hasBytecodes()) {
                return;
            }
            parse = true;
            graph = new StructuredGraph.Builder(debug.getOptions(), debug, AllowAssumptions.YES).method(method).build();
        }
        try (DebugContext.Scope scope = debug.scope("RuntimeCompile", graph)) {
            if (parse) {
                RuntimeGraphBuilderPhase builderPhase = new RuntimeGraphBuilderPhase(hostedProviders.getMetaAccess(), hostedProviders.getStampProvider(), hostedProviders.getConstantReflection(), hostedProviders.getConstantFieldProvider(), graphBuilderConfig, optimisticOpts, null, hostedProviders.getWordTypes(), deoptimizeOnExceptionPredicate, node);
                builderPhase.apply(graph);
            }
            if (graph.getNodes(StackValueNode.TYPE).isNotEmpty()) {
                /*
                     * Stack allocated memory is not seen by the deoptimization code, i.e., it is
                     * not copied in case of deoptimization. Also, pointers to it can be used for
                     * arbitrary address arithmetic, so we would not know how to update derived
                     * pointers into stack memory during deoptimization. Therefore, we cannot allow
                     * methods that allocate stack memory for runtime compilation. To remove this
                     * limitation, we would need to change how we handle stack allocated memory in
                     * Graal.
                     */
                return;
            }
            PhaseContext phaseContext = new PhaseContext(hostedProviders);
            new CanonicalizerPhase().apply(graph, phaseContext);
            new ConvertDeoptimizeToGuardPhase().apply(graph, phaseContext);
            graphEncoder.prepare(graph);
            node.graph = graph;
        } catch (Throwable ex) {
            debug.handle(ex);
        }
    }
    assert node.graph != null;
    List<MethodCallTargetNode> callTargets = node.graph.getNodes(MethodCallTargetNode.TYPE).snapshot();
    callTargets.sort((t1, t2) -> Integer.compare(t1.invoke().bci(), t2.invoke().bci()));
    for (MethodCallTargetNode targetNode : callTargets) {
        AnalysisMethod targetMethod = (AnalysisMethod) targetNode.targetMethod();
        AnalysisMethod callerMethod = (AnalysisMethod) targetNode.invoke().stateAfter().getMethod();
        InvokeTypeFlow invokeFlow = callerMethod.getTypeFlow().getOriginalMethodFlows().getInvoke(targetNode.invoke().bci());
        if (invokeFlow == null) {
            continue;
        }
        Collection<AnalysisMethod> allImplementationMethods = invokeFlow.getCallees();
        /*
             * Eventually we want to remove all invokes that are unreachable, i.e., have no
             * implementation. But the analysis is iterative, and we don't know here if we have
             * already reached the fixed point. So we only collect unreachable invokes here, and
             * remove them after the analysis has finished.
             */
        if (allImplementationMethods.size() == 0) {
            node.unreachableInvokes.add(targetNode.invoke());
        } else {
            node.unreachableInvokes.remove(targetNode.invoke());
        }
        List<AnalysisMethod> implementationMethods = new ArrayList<>();
        for (AnalysisMethod implementationMethod : allImplementationMethods) {
            /* Filter out all the implementation methods that have already been processed. */
            if (!methods.containsKey(implementationMethod)) {
                implementationMethods.add(implementationMethod);
            }
        }
        if (implementationMethods.size() > 0) {
            /* Sort to make printing order and method discovery order deterministic. */
            implementationMethods.sort((m1, m2) -> m1.format("%H.%n(%p)").compareTo(m2.format("%H.%n(%p)")));
            String sourceReference = buildSourceReference(targetNode.invoke().stateAfter());
            for (AnalysisMethod implementationMethod : implementationMethods) {
                CallTreeNode calleeNode = new CallTreeNode(implementationMethod, targetMethod, node, node.level + 1, sourceReference);
                if (includeCalleePredicate.includeCallee(calleeNode, implementationMethods)) {
                    assert !methods.containsKey(implementationMethod);
                    methods.put(implementationMethod, calleeNode);
                    worklist.add(calleeNode);
                    node.children.add(calleeNode);
                    objectReplacer.createMethod(implementationMethod);
                }
                /*
                     * We must compile all methods which may be called. It may be the case that a
                     * call target does not reach the compile queue by default, e.g. if it is
                     * inlined at image generation but not at runtime compilation.
                     */
                CompilationInfoSupport.singleton().registerForcedCompilation(implementationMethod);
            }
        }
    }
}
Also used : ArrayList(java.util.ArrayList) DebugContext(org.graalvm.compiler.debug.DebugContext) InvokeTypeFlow(com.oracle.graal.pointsto.flow.InvokeTypeFlow) ConvertDeoptimizeToGuardPhase(org.graalvm.compiler.phases.common.ConvertDeoptimizeToGuardPhase) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase)

Example 28 with AnalysisMethod

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

the class GraalObjectReplacer method updateDataDuringAnalysis.

/**
 * Some meta data must be updated during analysis. This is done here.
 */
public boolean updateDataDuringAnalysis(AnalysisMetaAccess metaAccess) {
    boolean result = false;
    List<AnalysisMethod> aMethods = new ArrayList<>();
    aMethods.addAll(methods.keySet());
    int index = 0;
    while (index < aMethods.size()) {
        AnalysisMethod aMethod = aMethods.get(index++);
        SubstrateMethod sMethod = methods.get(aMethod);
        SubstrateMethod[] implementations = new SubstrateMethod[aMethod.getImplementations().length];
        int idx = 0;
        for (AnalysisMethod impl : aMethod.getImplementations()) {
            SubstrateMethod sImpl = methods.get(impl);
            if (sImpl == null) {
                sImpl = createMethod(impl);
                aMethods.add(impl);
                result = true;
            }
            implementations[idx++] = sImpl;
        }
        if (sMethod.setImplementations(implementations)) {
            result = true;
        }
    }
    for (Map.Entry<AnalysisMethod, SubstrateMethod> entry : methods.entrySet()) {
        if (entry.getValue().setAnnotationsEncoding(Inflation.encodeAnnotations(metaAccess, entry.getKey().getAnnotations(), entry.getValue().getAnnotationsEncoding()))) {
            result = true;
        }
    }
    for (Map.Entry<AnalysisField, SubstrateField> entry : fields.entrySet()) {
        if (entry.getValue().setAnnotationsEncoding(Inflation.encodeAnnotations(metaAccess, entry.getKey().getAnnotations(), entry.getValue().getAnnotationsEncoding()))) {
            result = true;
        }
    }
    return result;
}
Also used : SubstrateMethod(com.oracle.svm.graal.meta.SubstrateMethod) AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) ArrayList(java.util.ArrayList) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) SubstrateField(com.oracle.svm.graal.meta.SubstrateField) HashMap(java.util.HashMap) Map(java.util.Map)

Example 29 with AnalysisMethod

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

the class BigBang method addRootMethod.

public AnalysisMethod addRootMethod(Executable method) {
    AnalysisMethod aMethod = metaAccess.lookupJavaMethod(method);
    addRootMethod(aMethod);
    return aMethod;
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod)

Example 30 with AnalysisMethod

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

the class ObjectScanner method unsupportedFeature.

private void unsupportedFeature(String key, String message, Object entry) {
    StringBuilder objectBacktrace = new StringBuilder();
    Object cur = entry;
    AnalysisMethod method = null;
    while (cur instanceof WorklistEntry) {
        WorklistEntry curEntry = (WorklistEntry) cur;
        objectBacktrace.append("\tobject ").append(bb.getMetaAccess().lookupJavaType(curEntry.constant).toJavaName(true)).append(System.lineSeparator());
        cur = curEntry.reason;
    }
    if (cur instanceof ResolvedJavaField) {
        objectBacktrace.append("\tfield ").append(((ResolvedJavaField) cur).format("%H.%n"));
    } else if (cur instanceof ResolvedJavaMethod) {
        objectBacktrace.append("\tmethod ").append(((ResolvedJavaMethod) cur).format("%H.%n(%p)"));
        method = (AnalysisMethod) cur;
    } else {
        objectBacktrace.append("\t[unknown] ").append(cur.toString());
    }
    bb.getUnsupportedFeatures().addMessage(key, method, message, objectBacktrace.toString());
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

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