Search in sources :

Example 6 with GraphBuilderConfiguration

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

the class VerifyVirtualizableTest method testVirtualizableEffects.

@SuppressWarnings("try")
private static void testVirtualizableEffects(Class<?> c) {
    RuntimeProvider rt = Graal.getRequiredCapability(RuntimeProvider.class);
    Providers providers = rt.getHostBackend().getProviders();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    PhaseSuite<HighTierContext> graphBuilderSuite = new PhaseSuite<>();
    Plugins plugins = new Plugins(new InvocationPlugins());
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
    graphBuilderSuite.appendPhase(new GraphBuilderPhase(config));
    HighTierContext context = new HighTierContext(providers, graphBuilderSuite, OptimisticOptimizations.NONE);
    OptionValues options = getInitialOptions();
    DebugContext debug = DebugContext.create(options, DebugHandlersFactory.LOADER);
    for (Method m : c.getDeclaredMethods()) {
        if (!Modifier.isNative(m.getModifiers()) && !Modifier.isAbstract(m.getModifiers())) {
            ResolvedJavaMethod method = metaAccess.lookupJavaMethod(m);
            StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).build();
            graphBuilderSuite.apply(graph, context);
            try (DebugCloseable s = debug.disableIntercept()) {
                new VerifyVirtualizableUsage().apply(graph, context);
            }
        }
    }
}
Also used : InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) OptionValues(org.graalvm.compiler.options.OptionValues) RuntimeProvider(org.graalvm.compiler.runtime.RuntimeProvider) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Providers(org.graalvm.compiler.phases.util.Providers) VerifyVirtualizableUsage(org.graalvm.compiler.phases.verify.VerifyVirtualizableUsage) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) PhaseSuite(org.graalvm.compiler.phases.PhaseSuite) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 7 with GraphBuilderConfiguration

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

the class UnbalancedMonitorsTest method checkForBailout.

private void checkForBailout(String name) throws ClassNotFoundException {
    ResolvedJavaMethod method = getResolvedJavaMethod(LOADER.findClass(INNER_CLASS_NAME), name);
    try {
        OptionValues options = getInitialOptions();
        StructuredGraph graph = new StructuredGraph.Builder(options, getDebugContext(options, null, method)).method(method).build();
        Plugins plugins = new Plugins(new InvocationPlugins());
        GraphBuilderConfiguration graphBuilderConfig = GraphBuilderConfiguration.getDefault(plugins).withEagerResolving(true).withUnresolvedIsError(true);
        OptimisticOptimizations optimisticOpts = OptimisticOptimizations.NONE;
        GraphBuilderPhase.Instance graphBuilder = new GraphBuilderPhase.Instance(getMetaAccess(), getProviders().getStampProvider(), null, null, graphBuilderConfig, optimisticOpts, null);
        graphBuilder.apply(graph);
    } catch (BailoutException e) {
        if (e.getMessage().contains("unbalanced monitors")) {
            return;
        }
        throw e;
    }
    assertTrue("should have bailed out", false);
}
Also used : BailoutException(jdk.vm.ci.code.BailoutException) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) OptionValues(org.graalvm.compiler.options.OptionValues) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) OptimisticOptimizations(org.graalvm.compiler.phases.OptimisticOptimizations) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 8 with GraphBuilderConfiguration

use of org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration 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 9 with GraphBuilderConfiguration

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

the class SnippetStub method getGraph.

@Override
@SuppressWarnings("try")
protected StructuredGraph getGraph(DebugContext debug, CompilationIdentifier compilationId) {
    Plugins defaultPlugins = providers.getGraphBuilderPlugins();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    SnippetReflectionProvider snippetReflection = providers.getSnippetReflection();
    Plugins plugins = new Plugins(defaultPlugins);
    plugins.prependParameterPlugin(new ConstantBindingParameterPlugin(makeConstArgs(), metaAccess, snippetReflection));
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
    // Stubs cannot have optimistic assumptions since they have
    // to be valid for the entire run of the VM.
    final StructuredGraph graph = new StructuredGraph.Builder(options, debug).method(method).compilationId(compilationId).build();
    try (DebugContext.Scope outer = debug.scope("SnippetStub", graph)) {
        graph.disableUnsafeAccessTracking();
        IntrinsicContext initialIntrinsicContext = new IntrinsicContext(method, method, getReplacementsBytecodeProvider(), INLINE_AFTER_PARSING);
        GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialIntrinsicContext);
        instance.apply(graph);
        for (ParameterNode param : graph.getNodes(ParameterNode.TYPE)) {
            int index = param.index();
            if (method.getParameterAnnotation(NonNullParameter.class, index) != null) {
                param.setStamp(param.stamp(NodeView.DEFAULT).join(StampFactory.objectNonNull()));
            }
        }
        new RemoveValueProxyPhase().apply(graph);
        graph.setGuardsStage(GuardsStage.FLOATING_GUARDS);
        CanonicalizerPhase canonicalizer = new CanonicalizerPhase();
        PhaseContext context = new PhaseContext(providers);
        canonicalizer.apply(graph, context);
        new LoweringPhase(canonicalizer, LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, context);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
    return graph;
}
Also used : RemoveValueProxyPhase(org.graalvm.compiler.phases.common.RemoveValueProxyPhase) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) DebugContext(org.graalvm.compiler.debug.DebugContext) ConstantBindingParameterPlugin(org.graalvm.compiler.replacements.ConstantBindingParameterPlugin) NonNullParameter(org.graalvm.compiler.api.replacements.Snippet.NonNullParameter) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) SnippetReflectionProvider(org.graalvm.compiler.api.replacements.SnippetReflectionProvider) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Example 10 with GraphBuilderConfiguration

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

the class GraphKit method inline.

/**
 * Inlines a given invocation to a method. The graph of the inlined method is processed in the
 * same manner as for snippets and method substitutions.
 */
public void inline(InvokeNode invoke) {
    ResolvedJavaMethod method = ((MethodCallTargetNode) invoke.callTarget()).targetMethod();
    MetaAccessProvider metaAccess = providers.getMetaAccess();
    Plugins plugins = new Plugins(graphBuilderPlugins);
    GraphBuilderConfiguration config = GraphBuilderConfiguration.getSnippetDefault(plugins);
    StructuredGraph calleeGraph = new StructuredGraph.Builder(invoke.getOptions(), invoke.getDebug()).method(method).build();
    if (invoke.graph().trackNodeSourcePosition()) {
        calleeGraph.setTrackNodeSourcePosition();
    }
    IntrinsicContext initialReplacementContext = new IntrinsicContext(method, method, providers.getReplacements().getDefaultReplacementBytecodeProvider(), INLINE_AFTER_PARSING);
    GraphBuilderPhase.Instance instance = new GraphBuilderPhase.Instance(metaAccess, providers.getStampProvider(), providers.getConstantReflection(), providers.getConstantFieldProvider(), config, OptimisticOptimizations.NONE, initialReplacementContext);
    instance.apply(calleeGraph);
    // Remove all frame states from inlinee
    calleeGraph.clearAllStateAfter();
    new DeadCodeEliminationPhase(Optionality.Required).apply(calleeGraph);
    InliningUtil.inline(invoke, calleeGraph, false, method);
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) Plugins(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)

Aggregations

GraphBuilderConfiguration (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration)21 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)16 GraphBuilderPhase (org.graalvm.compiler.java.GraphBuilderPhase)15 Plugins (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration.Plugins)12 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)11 DebugContext (org.graalvm.compiler.debug.DebugContext)11 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)11 OptionValues (org.graalvm.compiler.options.OptionValues)10 HighTierContext (org.graalvm.compiler.phases.tiers.HighTierContext)10 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)9 Providers (org.graalvm.compiler.phases.util.Providers)7 Method (java.lang.reflect.Method)6 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)6 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)5 PhaseSuite (org.graalvm.compiler.phases.PhaseSuite)5 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)5 RuntimeProvider (org.graalvm.compiler.runtime.RuntimeProvider)5 SnippetReflectionProvider (org.graalvm.compiler.api.replacements.SnippetReflectionProvider)3 Bytecode (org.graalvm.compiler.bytecode.Bytecode)3 IntrinsicContext (org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext)3