Search in sources :

Example 46 with RequiredInvocationPlugin

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

the class CEntryPointSupport method registerEntryPointActionsPlugins.

private static void registerEntryPointActionsPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, CEntryPointActions.class);
    r.register(new RequiredInvocationPlugin("enterCreateIsolate", CEntryPointCreateIsolateParameters.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode parameters) {
            b.addPush(JavaKind.Int, CEntryPointEnterNode.createIsolate(parameters));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("enterAttachThread", Isolate.class, boolean.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate, ValueNode ensureJavaThreadNode) {
            if (!ensureJavaThreadNode.isConstant()) {
                b.bailout("Parameter ensureJavaThread of enterAttachThread must be a compile time constant");
            }
            b.addPush(JavaKind.Int, CEntryPointEnterNode.attachThread(isolate, ensureJavaThreadNode.asJavaConstant().asInt() != 0, false));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("enter", IsolateThread.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode thread) {
            b.addPush(JavaKind.Int, CEntryPointEnterNode.enter(thread));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("enterIsolate", Isolate.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate) {
            b.addPush(JavaKind.Int, CEntryPointEnterNode.enterIsolate(isolate));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("enterAttachThreadFromCrashHandler", Isolate.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate) {
            b.addPush(JavaKind.Int, CEntryPointEnterNode.attachThread(isolate, false, true));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("leave") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            StateSplitProxyNode proxy = new StateSplitProxyNode(null);
            b.add(proxy);
            b.setStateAfter(proxy);
            b.addPush(JavaKind.Int, new CEntryPointLeaveNode(LeaveAction.Leave));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("leaveDetachThread") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            StateSplitProxyNode proxy = new StateSplitProxyNode(null);
            b.add(proxy);
            b.setStateAfter(proxy);
            b.addPush(JavaKind.Int, new CEntryPointLeaveNode(LeaveAction.DetachThread));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("leaveTearDownIsolate") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            StateSplitProxyNode proxy = new StateSplitProxyNode(null);
            b.add(proxy);
            b.setStateAfter(proxy);
            b.addPush(JavaKind.Int, new CEntryPointLeaveNode(LeaveAction.TearDownIsolate));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("failFatally", int.class, CCharPointer.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
            b.add(new CEntryPointUtilityNode(UtilityAction.FailFatally, arg1, arg2));
            /*
                 * FailFatally does not return, so we can cut out any control flow afterwards and
                 * set the probability of the IfNode that leads to this branch.
                 */
            LoweredDeadEndNode deadEndNode = b.add(new LoweredDeadEndNode());
            AbstractBeginNode prevBegin = AbstractBeginNode.prevBegin(deadEndNode);
            if (prevBegin != null && prevBegin.predecessor() instanceof IfNode) {
                ((IfNode) prevBegin.predecessor()).setProbability(prevBegin, BranchProbabilityNode.EXTREMELY_SLOW_PATH_PROFILE);
            }
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("isCurrentThreadAttachedTo", Isolate.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode isolate) {
            b.addPush(JavaKind.Boolean, new CEntryPointUtilityNode(UtilityAction.IsAttached, isolate));
            return true;
        }
    });
}
Also used : RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) CEntryPointUtilityNode(com.oracle.svm.core.graal.nodes.CEntryPointUtilityNode) IfNode(org.graalvm.compiler.nodes.IfNode) LoweredDeadEndNode(com.oracle.svm.core.graal.nodes.LoweredDeadEndNode) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) IsolateThread(org.graalvm.nativeimage.IsolateThread) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) CEntryPointCreateIsolateParameters(com.oracle.svm.core.c.function.CEntryPointCreateIsolateParameters) StateSplitProxyNode(org.graalvm.compiler.nodes.extended.StateSplitProxyNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Isolate(org.graalvm.nativeimage.Isolate) CurrentIsolate(org.graalvm.nativeimage.CurrentIsolate) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer)

Example 47 with RequiredInvocationPlugin

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

the class StandardGraphBuilderPlugins method registerGraalDirectivesPlugins.

private static void registerGraalDirectivesPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection) {
    Registration r = new Registration(plugins, GraalDirectives.class);
    r.register(new DeoptimizePlugin(snippetReflection, None, TransferToInterpreter, false, "deoptimize"));
    r.register(new DeoptimizePlugin(snippetReflection, InvalidateReprofile, TransferToInterpreter, false, "deoptimizeAndInvalidate"));
    r.register(new DeoptimizePlugin(snippetReflection, null, null, null, "deoptimize", DeoptimizationAction.class, DeoptimizationReason.class, boolean.class));
    r.register(new DeoptimizePlugin(snippetReflection, null, null, null, "deoptimize", DeoptimizationAction.class, DeoptimizationReason.class, SpeculationReason.class));
    r.register(new RequiredInlineOnlyInvocationPlugin("inCompiledCode") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("inIntrinsic") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(b.parsingIntrinsic()));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("controlFlowAnchor") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new ControlFlowAnchorNode());
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("neverStripMine") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new NeverStripMineNode());
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("sideEffect") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new SideEffectNode());
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("sideEffect", int.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode a) {
            b.addPush(JavaKind.Int, new SideEffectNode(a));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("trustedBox", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode a) {
            b.addPush(JavaKind.Object, new TrustedBoxedValue(a));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("assumeStableDimension", Object.class, int.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode array, ValueNode dimension) {
            if (array instanceof ConstantNode && b.getMetaAccess().lookupJavaType(array.asJavaConstant()).isArray()) {
                if (dimension instanceof ConstantNode && dimension.stamp(NodeView.DEFAULT) instanceof IntegerStamp) {
                    int stableDim = dimension.asJavaConstant().asInt();
                    ConstantNode c = ConstantNode.forConstant(array.asJavaConstant(), stableDim, false, b.getMetaAccess());
                    b.addPush(JavaKind.Object, c);
                    return true;
                }
            }
            throw GraalError.shouldNotReachHere("Illegal usage of stable array intrinsic assumeStableDimension(array, dimension): " + "This compiler intrinsic can only be used iff array is a constant node (i.e., constant field) and iff " + "dimension is a constant int. It will replace the constant array with a new constant that additionally sets the stable" + "dimensions to the int parameter supplied.");
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("injectBranchProbability", double.class, boolean.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode probability, ValueNode condition) {
            b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probability, condition));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("injectIterationCount", double.class, boolean.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode iterations, ValueNode condition) {
            // injectBranchProbability(1. - 1. / iterations, condition)
            if (iterations.isJavaConstant()) {
                double iterationsConstant;
                if (iterations.stamp(NodeView.DEFAULT) instanceof IntegerStamp) {
                    iterationsConstant = iterations.asJavaConstant().asLong();
                } else if (iterations.stamp(NodeView.DEFAULT) instanceof FloatStamp) {
                    iterationsConstant = iterations.asJavaConstant().asDouble();
                } else {
                    return false;
                }
                double probability = 1. - 1. / iterationsConstant;
                ValueNode probabilityNode = b.add(ConstantNode.forDouble(probability));
                b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probabilityNode, condition));
                return true;
            }
            return false;
        }
    });
    for (JavaKind kind : JavaKind.values()) {
        if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
            Class<?> javaClass = getJavaClass(kind);
            r.register(new RequiredInlineOnlyInvocationPlugin("blackhole", javaClass) {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                    b.add(new BlackholeNode(value));
                    return true;
                }
            });
            r.register(new RequiredInlineOnlyInvocationPlugin("bindToRegister", javaClass) {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                    b.add(new BindToRegisterNode(value));
                    return true;
                }
            });
            r.register(new RequiredInvocationPlugin("opaque", javaClass) {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                    b.addPush(kind, new OpaqueNode(value));
                    return true;
                }
            });
        }
    }
    r.register(new RequiredInlineOnlyInvocationPlugin("spillRegisters") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new SpillRegistersNode());
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("guardingNonNull", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.addPush(value.getStackKind(), b.nullCheckedValue(value));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("ensureVirtualized", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.add(new EnsureVirtualizedNode(object, false));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("ensureVirtualizedHere", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.add(new EnsureVirtualizedNode(object, true));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("breakpoint") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new BreakpointNode());
            return true;
        }
    });
    for (JavaKind kind : JavaKind.values()) {
        if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
            Class<?> javaClass = getJavaClass(kind);
            r.register(new RequiredInlineOnlyInvocationPlugin("isCompilationConstant", javaClass) {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                    b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(value.isJavaConstant()));
                    return true;
                }
            });
        }
    }
}
Also used : EnsureVirtualizedNode(org.graalvm.compiler.nodes.virtual.EnsureVirtualizedNode) SpillRegistersNode(org.graalvm.compiler.nodes.debug.SpillRegistersNode) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) BreakpointNode(org.graalvm.compiler.nodes.BreakpointNode) OpaqueNode(org.graalvm.compiler.nodes.extended.OpaqueNode) SideEffectNode(org.graalvm.compiler.nodes.debug.SideEffectNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) NeverStripMineNode(org.graalvm.compiler.nodes.debug.NeverStripMineNode) JavaKind(jdk.vm.ci.meta.JavaKind) BindToRegisterNode(org.graalvm.compiler.nodes.debug.BindToRegisterNode) RequiredInlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInlineOnlyInvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) FloatStamp(org.graalvm.compiler.core.common.type.FloatStamp) SpeculationReason(jdk.vm.ci.meta.SpeculationLog.SpeculationReason) TrustedBoxedValue(org.graalvm.compiler.nodes.extended.BoxNode.TrustedBoxedValue) BlackholeNode(org.graalvm.compiler.nodes.debug.BlackholeNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) ControlFlowAnchorNode(org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)47 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)47 RequiredInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin)47 ValueNode (org.graalvm.compiler.nodes.ValueNode)38 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)37 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)34 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)14 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)9 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)8 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)6 JavaConstant (jdk.vm.ci.meta.JavaConstant)5 LogicNode (org.graalvm.compiler.nodes.LogicNode)5 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)5 IsolateThread (org.graalvm.nativeimage.IsolateThread)4 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)3 TruffleCompilerRuntime (org.graalvm.compiler.truffle.common.TruffleCompilerRuntime)3 AllowMaterializeNode (org.graalvm.compiler.truffle.compiler.nodes.frame.AllowMaterializeNode)3 NewFrameNode (org.graalvm.compiler.truffle.compiler.nodes.frame.NewFrameNode)3 VirtualFrameGetNode (org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameGetNode)3 VirtualFrameSetNode (org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameSetNode)3