Search in sources :

Example 76 with StructuredGraph

use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.

the class AnalysisMethodCalleeWalker method walkCallees.

/**
 * Visit the callees of this method.
 */
VisitResult walkCallees(AnalysisMethod method, CallPathVisitor visitor) {
    final StructuredGraph graph = method.getTypeFlow().getGraph();
    if (graph != null) {
        for (Invoke invoke : graph.getInvokes()) {
            final CallTargetNode callTarget = invoke.callTarget();
            final AnalysisMethod callee = (AnalysisMethod) callTarget.targetMethod();
            walkMethodAndCallees(callee, method, invoke, visitor);
        }
    }
    return VisitResult.CONTINUE;
}
Also used : AnalysisMethod(com.oracle.graal.pointsto.meta.AnalysisMethod) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Invoke(org.graalvm.compiler.nodes.Invoke) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode)

Example 77 with StructuredGraph

use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.

the class CEntryPointCallStubMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    UniverseMetaAccess metaAccess = (UniverseMetaAccess) providers.getMetaAccess();
    NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries();
    HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
    StructuredGraph graph = kit.getGraph();
    JavaType[] parameterTypes = method.toParameterTypes();
    JavaType[] parameterLoadTypes = Arrays.copyOf(parameterTypes, parameterTypes.length);
    EnumInfo[] parameterEnumInfos;
    parameterEnumInfos = adaptParameterTypes(providers, nativeLibraries, kit, parameterTypes, parameterLoadTypes, purpose);
    ValueNode[] args = kit.loadArguments(parameterLoadTypes).toArray(new ValueNode[0]);
    InvokeNode prologueInvoke = generatePrologue(providers, kit, parameterLoadTypes, args);
    adaptArgumentValues(providers, kit, parameterTypes, parameterEnumInfos, args);
    ResolvedJavaMethod unwrappedTargetMethod = targetMethod;
    while (unwrappedTargetMethod instanceof WrappedJavaMethod) {
        unwrappedTargetMethod = ((WrappedJavaMethod) unwrappedTargetMethod).getWrapped();
    }
    ResolvedJavaMethod universeTargetMethod = lookupMethodInUniverse(metaAccess, unwrappedTargetMethod);
    int invokeBci = kit.bci();
    int exceptionEdgeBci = kit.bci();
    // Also support non-static test methods (they are not allowed to use the receiver)
    InvokeKind invokeKind = universeTargetMethod.isStatic() ? InvokeKind.Static : InvokeKind.Special;
    ValueNode[] invokeArgs = args;
    if (invokeKind != InvokeKind.Static) {
        invokeArgs = new ValueNode[args.length + 1];
        invokeArgs[0] = kit.createObject(null);
        System.arraycopy(args, 0, invokeArgs, 1, args.length);
    }
    InvokeWithExceptionNode invoke = kit.startInvokeWithException(universeTargetMethod, invokeKind, kit.getFrameState(), invokeBci, exceptionEdgeBci, invokeArgs);
    kit.exceptionPart();
    ExceptionObjectNode exception = kit.exceptionObject();
    generateExceptionHandler(providers, kit, exception, invoke.getStackKind());
    kit.endInvokeWithException();
    ValueNode returnValue = adaptReturnValue(method, providers, purpose, metaAccess, nativeLibraries, kit, invoke);
    InvokeNode epilogueInvoke = generateEpilogue(providers, kit);
    kit.createReturn(returnValue, returnValue.getStackKind());
    inlinePrologueAndEpilogue(kit, prologueInvoke, epilogueInvoke, invoke.getStackKind());
    assert graph.verify();
    return graph;
}
Also used : HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) UniverseMetaAccess(com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 78 with StructuredGraph

use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.

the class CompileQueue method defaultParseFunction.

@SuppressWarnings("try")
private void defaultParseFunction(DebugContext debug, HostedMethod method, CompileReason reason, RuntimeConfiguration config) {
    if (method.getAnnotation(Fold.class) != null || method.getAnnotation(NodeIntrinsic.class) != null) {
        throw VMError.shouldNotReachHere("Parsing method annotated with @Fold or @NodeIntrinsic: " + method.format("%H.%n(%p)"));
    }
    HostedProviders providers = (HostedProviders) config.lookupBackend(method).getProviders();
    boolean needParsing = false;
    OptionValues options = HostedOptionValues.singleton();
    StructuredGraph graph = method.buildGraph(debug, method, providers, Purpose.AOT_COMPILATION);
    if (graph == null) {
        InvocationPlugin plugin = providers.getGraphBuilderPlugins().getInvocationPlugins().lookupInvocation(method);
        if (plugin != null && !plugin.inlineOnly()) {
            Bytecode code = new ResolvedJavaMethodBytecode(method);
            // DebugContext debug = new DebugContext(options, providers.getSnippetReflection());
            graph = new SubstrateIntrinsicGraphBuilder(debug.getOptions(), debug, providers.getMetaAccess(), providers.getConstantReflection(), providers.getConstantFieldProvider(), providers.getStampProvider(), code).buildGraph(plugin);
        }
    }
    if (graph == null && method.isNative() && NativeImageOptions.ReportUnsupportedElementsAtRuntime.getValue()) {
        graph = DeletedMethod.buildGraph(debug, method, providers, DeletedMethod.NATIVE_MESSAGE);
    }
    if (graph == null) {
        needParsing = true;
        if (!method.compilationInfo.isDeoptTarget()) {
            /*
                 * Disabling liveness analysis preserves the values of local variables beyond the
                 * bytecode-liveness. This greatly helps debugging. When local variable numbers are
                 * reused by javac, local variables can still get illegal values. Since we cannot
                 * "restore" such illegal values during deoptimization, we must do liveness analysis
                 * for deoptimization target methods.
                 */
            options = new OptionValues(options, GraalOptions.OptClearNonLiveLocals, false);
        }
        graph = new StructuredGraph.Builder(options, debug).method(method).build();
    }
    try (DebugContext.Scope s = debug.scope("Parsing", graph, method, this)) {
        try {
            if (needParsing) {
                GraphBuilderConfiguration gbConf = createHostedGraphBuilderConfiguration(providers, method);
                new HostedGraphBuilderPhase(providers.getMetaAccess(), providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), gbConf, optimisticOpts, null, providers.getWordTypes()).apply(graph);
            } else {
                graph.setGuardsStage(GuardsStage.FIXED_DEOPTS);
            }
            new DeadStoreRemovalPhase().apply(graph);
            new DevirtualizeCallsPhase().apply(graph);
            new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
            /*
                 * The StrengthenStampsPhase may not insert type check nodes for specialized
                 * methods, because we would get type state mismatches regarding Const<Type> !=
                 * <Type>
                 */
            /*
                 * cwimmer: the old, commented out, condition always disabled checking of static
                 * analysis results. Therefore, the checks are broken right now.
                 */
            // new StrengthenStampsPhase(BootImageOptions.CheckStaticAnalysisResults.getValue()
            // && method.compilationInfo.deoptTarget != null &&
            // !method.compilationInfo.isDeoptTarget).apply(graph);
            new StrengthenStampsPhase(false).apply(graph);
            new CanonicalizerPhase().apply(graph, new PhaseContext(providers));
            /* Check that graph is in good shape after parsing. */
            assert GraphOrder.assertSchedulableGraph(graph);
            method.compilationInfo.graph = graph;
            for (Invoke invoke : graph.getInvokes()) {
                if (!canBeUsedForInlining(invoke)) {
                    invoke.setUseForInlining(false);
                }
                if (invoke.callTarget() instanceof MethodCallTargetNode) {
                    MethodCallTargetNode targetNode = (MethodCallTargetNode) invoke.callTarget();
                    HostedMethod invokeTarget = (HostedMethod) targetNode.targetMethod();
                    if (targetNode.invokeKind().isDirect()) {
                        if (invokeTarget.wrapped.isImplementationInvoked()) {
                            handleSpecialization(method, targetNode, invokeTarget, invokeTarget);
                            ensureParsed(invokeTarget, new DirectCallReason(method, reason));
                        }
                    } else {
                        for (HostedMethod invokeImplementation : invokeTarget.getImplementations()) {
                            handleSpecialization(method, targetNode, invokeTarget, invokeImplementation);
                            ensureParsed(invokeImplementation, new VirtualCallReason(method, invokeImplementation, reason));
                        }
                    }
                }
            }
        } catch (Throwable ex) {
            GraalError error = ex instanceof GraalError ? (GraalError) ex : new GraalError(ex);
            error.addContext("method: " + method.format("%r %H.%n(%p)"));
            throw error;
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : HostedOptionValues(com.oracle.svm.core.option.HostedOptionValues) OptionValues(org.graalvm.compiler.options.OptionValues) SubstrateIntrinsicGraphBuilder(com.oracle.graal.pointsto.phases.SubstrateIntrinsicGraphBuilder) HostedGraphBuilderPhase(com.oracle.svm.hosted.phases.HostedGraphBuilderPhase) DeadStoreRemovalPhase(com.oracle.svm.core.graal.phases.DeadStoreRemovalPhase) HostedProviders(com.oracle.graal.pointsto.meta.HostedProviders) Invoke(org.graalvm.compiler.nodes.Invoke) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) Bytecode(org.graalvm.compiler.bytecode.Bytecode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) DevirtualizeCallsPhase(com.oracle.svm.hosted.phases.DevirtualizeCallsPhase) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ResolvedJavaMethodBytecode(org.graalvm.compiler.bytecode.ResolvedJavaMethodBytecode) StrengthenStampsPhase(com.oracle.svm.hosted.phases.StrengthenStampsPhase)

Example 79 with StructuredGraph

use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.

the class CompileQueue method ensureCompiled.

protected void ensureCompiled(HostedMethod method, CompileReason reason) {
    CompileTask task = new CompileTask(method, reason);
    CompileTask oldTask = compilations.putIfAbsent(method, task);
    if (oldTask != null) {
        // Method is already scheduled for compilation.
        if (oldTask.allReasons != null) {
            oldTask.allReasons.add(reason);
        }
        return;
    }
    if (method.compilationInfo.specializedArguments != null) {
        // Do the specialization: replace the argument locals with the constant arguments.
        StructuredGraph graph = method.compilationInfo.graph;
        int idx = 0;
        for (ConstantNode argument : method.compilationInfo.specializedArguments) {
            ParameterNode local = graph.getParameter(idx++);
            if (local != null) {
                local.replaceAndDelete(ConstantNode.forConstant(argument.asJavaConstant(), runtimeConfig.getProviders().getMetaAccess(), graph));
            }
        }
    }
    executor.execute(task);
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) DeoptEntryInfopoint(com.oracle.svm.core.deopt.DeoptEntryInfopoint) Infopoint(jdk.vm.ci.code.site.Infopoint)

Example 80 with StructuredGraph

use of org.graalvm.compiler.nodes.StructuredGraph in project graal by oracle.

the class MustNotSynchronizeAnnotationChecker method synchronizesIndirectly.

/**
 * Does this method call a method that synchronizes?
 */
protected boolean synchronizesIndirectly(HostedMethod methodImpl) throws WarningException {
    boolean result = false;
    final StructuredGraph graph = methodImpl.compilationInfo.getGraph();
    if (graph != null) {
        for (Invoke invoke : graph.getInvokes()) {
            final HostedMethod callee = (HostedMethod) invoke.callTarget().targetMethod();
            if (invoke.callTarget().invokeKind().isDirect()) {
                result |= checkMethod(callee, callee);
                if (result) {
                    return result;
                }
            } else {
                for (HostedMethod calleeImpl : callee.getImplementations()) {
                    result |= checkMethod(callee, calleeImpl);
                    /* One violation is too many. */
                    if (result) {
                        return result;
                    }
                }
            }
        }
    }
    return result;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HostedMethod(com.oracle.svm.hosted.meta.HostedMethod) Invoke(org.graalvm.compiler.nodes.Invoke)

Aggregations

StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)360 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)97 Test (org.junit.Test)96 DebugContext (org.graalvm.compiler.debug.DebugContext)88 ValueNode (org.graalvm.compiler.nodes.ValueNode)70 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)62 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)62 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)57 Node (org.graalvm.compiler.graph.Node)39 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)37 OptionValues (org.graalvm.compiler.options.OptionValues)34 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)28 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)26 FixedNode (org.graalvm.compiler.nodes.FixedNode)26 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)25 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)24 InliningPhase (org.graalvm.compiler.phases.common.inlining.InliningPhase)24 LogicNode (org.graalvm.compiler.nodes.LogicNode)21 CompilationResult (org.graalvm.compiler.code.CompilationResult)19 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)19