Search in sources :

Example 36 with Receiver

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

the class StandardGraphBuilderPlugins method registerMathPlugins.

private static void registerMathPlugins(InvocationPlugins plugins, boolean allowDeoptimization) {
    Registration r = new Registration(plugins, Math.class);
    if (allowDeoptimization) {
        for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long }) {
            Class<?> type = kind.toJavaClass();
            r.register1("decrementExact", type, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) {
                    b.addPush(kind, new IntegerSubExactNode(x, ConstantNode.forIntegerKind(kind, 1)));
                    return true;
                }
            });
            r.register1("incrementExact", type, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x) {
                    b.addPush(kind, new IntegerAddExactNode(x, ConstantNode.forIntegerKind(kind, 1)));
                    return true;
                }
            });
            r.register2("addExact", type, type, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
                    b.addPush(kind, new IntegerAddExactNode(x, y));
                    return true;
                }
            });
            r.register2("subtractExact", type, type, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
                    b.addPush(kind, new IntegerSubExactNode(x, y));
                    return true;
                }
            });
            r.register2("multiplyExact", type, type, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
                    b.addPush(kind, new IntegerMulExactNode(x, y));
                    return true;
                }
            });
        }
    }
    r.register1("abs", Float.TYPE, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(JavaKind.Float, b.append(new AbsNode(value).canonical(null)));
            return true;
        }
    });
    r.register1("abs", Double.TYPE, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(JavaKind.Double, b.append(new AbsNode(value).canonical(null)));
            return true;
        }
    });
    r.register1("sqrt", Double.TYPE, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.push(JavaKind.Double, b.append(SqrtNode.create(value, NodeView.DEFAULT)));
            return true;
        }
    });
}
Also used : IntegerAddExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerAddExactNode) IntegerSubExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerSubExactNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) IntegerMulExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerMulExactNode) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) AbsNode(org.graalvm.compiler.nodes.calc.AbsNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 37 with Receiver

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

the class StandardGraphBuilderPlugins method registerJFRThrowablePlugins.

private static void registerJFRThrowablePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins, "oracle.jrockit.jfr.jdkevents.ThrowableTracer", bytecodeProvider);
    r.register2("traceThrowable", Throwable.class, String.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode throwable, ValueNode message) {
            b.add(new VirtualizableInvokeMacroNode(b.getInvokeKind(), targetMethod, b.bci(), b.getInvokeReturnStamp(b.getAssumptions()), throwable, message));
            return true;
        }

        @Override
        public boolean inlineOnly() {
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) VirtualizableInvokeMacroNode(org.graalvm.compiler.replacements.nodes.VirtualizableInvokeMacroNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 38 with Receiver

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

the class StandardGraphBuilderPlugins method registerGraalDirectivesPlugins.

private static void registerGraalDirectivesPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, GraalDirectives.class);
    r.register0("deoptimize", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter));
            return true;
        }
    });
    r.register0("deoptimizeAndInvalidate", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
            return true;
        }
    });
    r.register0("deoptimizeAndInvalidateWithSpeculation", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            GraalError.guarantee(b.getGraph().getSpeculationLog() != null, "A speculation log is need to use `deoptimizeAndInvalidateWithSpeculation`");
            BytecodePosition pos = new BytecodePosition(null, b.getMethod(), b.bci());
            DirectiveSpeculationReason reason = new DirectiveSpeculationReason(pos);
            JavaConstant speculation;
            if (b.getGraph().getSpeculationLog().maySpeculate(reason)) {
                speculation = b.getGraph().getSpeculationLog().speculate(reason);
            } else {
                speculation = JavaConstant.defaultForKind(JavaKind.Object);
            }
            b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter, speculation));
            return true;
        }
    });
    r.register0("inCompiledCode", new InvocationPlugin() {

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

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new ControlFlowAnchorNode());
            return true;
        }
    });
    r.register2("injectBranchProbability", double.class, boolean.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode probability, ValueNode condition) {
            b.addPush(JavaKind.Boolean, new BranchProbabilityNode(probability, condition));
            return true;
        }
    });
    InvocationPlugin blackholePlugin = new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.add(new BlackholeNode(value));
            return true;
        }
    };
    InvocationPlugin bindToRegisterPlugin = new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.add(new BindToRegisterNode(value));
            return true;
        }
    };
    for (JavaKind kind : JavaKind.values()) {
        if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
            Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
            r.register1("blackhole", javaClass, blackholePlugin);
            r.register1("bindToRegister", javaClass, bindToRegisterPlugin);
            r.register1("opaque", javaClass, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
                    b.addPush(kind, new OpaqueNode(value));
                    return true;
                }
            });
        }
    }
    InvocationPlugin spillPlugin = new InvocationPlugin() {

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

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

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

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.add(new EnsureVirtualizedNode(object, true));
            return true;
        }
    });
}
Also used : BindToRegisterNode(org.graalvm.compiler.nodes.debug.BindToRegisterNode) EnsureVirtualizedNode(org.graalvm.compiler.nodes.virtual.EnsureVirtualizedNode) BytecodePosition(jdk.vm.ci.code.BytecodePosition) SpillRegistersNode(org.graalvm.compiler.nodes.debug.SpillRegistersNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) JavaConstant(jdk.vm.ci.meta.JavaConstant) OpaqueNode(org.graalvm.compiler.nodes.debug.OpaqueNode) BlackholeNode(org.graalvm.compiler.nodes.debug.BlackholeNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ControlFlowAnchorNode(org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 39 with Receiver

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

the class StandardGraphBuilderPlugins method registerEdgesPlugins.

/**
 * Substitutions for improving the performance of some critical methods in {@link Edges}. These
 * substitutions improve the performance by forcing the relevant methods to be inlined
 * (intrinsification being a special form of inlining) and removing a checked cast.
 */
private static void registerEdgesPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Edges.class);
    for (Class<?> c : new Class<?>[] { Node.class, NodeList.class }) {
        r.register2("get" + c.getSimpleName() + "Unsafe", Node.class, long.class, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode node, ValueNode offset) {
                ObjectStamp stamp = StampFactory.object(TypeReference.createTrusted(b.getAssumptions(), metaAccess.lookupJavaType(c)));
                RawLoadNode value = b.add(new RawLoadNode(stamp, node, offset, LocationIdentity.any(), JavaKind.Object));
                b.addPush(JavaKind.Object, value);
                return true;
            }
        });
        r.register3("put" + c.getSimpleName() + "Unsafe", Node.class, long.class, c, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode node, ValueNode offset, ValueNode value) {
                b.add(new RawStoreNode(node, offset, value, JavaKind.Object, LocationIdentity.any()));
                return true;
            }
        });
    }
}
Also used : RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) DynamicNewInstanceNode(org.graalvm.compiler.nodes.java.DynamicNewInstanceNode) OpaqueNode(org.graalvm.compiler.nodes.debug.OpaqueNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) BindToRegisterNode(org.graalvm.compiler.nodes.debug.BindToRegisterNode) IntegerMulExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerMulExactNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) RegisterFinalizerNode(org.graalvm.compiler.nodes.java.RegisterFinalizerNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) IntegerAddExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerAddExactNode) EnsureVirtualizedNode(org.graalvm.compiler.nodes.virtual.EnsureVirtualizedNode) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualizableInvokeMacroNode(org.graalvm.compiler.replacements.nodes.VirtualizableInvokeMacroNode) DynamicNewArrayNode(org.graalvm.compiler.nodes.java.DynamicNewArrayNode) UnsignedDivNode(org.graalvm.compiler.nodes.calc.UnsignedDivNode) UnsafeCompareAndSwapNode(org.graalvm.compiler.nodes.java.UnsafeCompareAndSwapNode) CompareNode(org.graalvm.compiler.nodes.calc.CompareNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) IntegerSubExactNode(org.graalvm.compiler.replacements.nodes.arithmetic.IntegerSubExactNode) BranchProbabilityNode(org.graalvm.compiler.nodes.extended.BranchProbabilityNode) UnsafeMemoryStoreNode(org.graalvm.compiler.nodes.extended.UnsafeMemoryStoreNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ReinterpretNode(org.graalvm.compiler.nodes.calc.ReinterpretNode) ClassIsAssignableFromNode(org.graalvm.compiler.nodes.java.ClassIsAssignableFromNode) ControlFlowAnchorNode(org.graalvm.compiler.nodes.debug.ControlFlowAnchorNode) InstanceOfDynamicNode(org.graalvm.compiler.nodes.java.InstanceOfDynamicNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) AbsNode(org.graalvm.compiler.nodes.calc.AbsNode) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) SpillRegistersNode(org.graalvm.compiler.nodes.debug.SpillRegistersNode) UnsafeMemoryLoadNode(org.graalvm.compiler.nodes.extended.UnsafeMemoryLoadNode) BlackholeNode(org.graalvm.compiler.nodes.debug.BlackholeNode) UnsignedRemNode(org.graalvm.compiler.nodes.calc.UnsignedRemNode) SqrtNode(org.graalvm.compiler.nodes.calc.SqrtNode) ReverseBytesNode(org.graalvm.compiler.replacements.nodes.ReverseBytesNode) MembarNode(org.graalvm.compiler.nodes.extended.MembarNode) GetClassNode(org.graalvm.compiler.nodes.extended.GetClassNode) Node(org.graalvm.compiler.graph.Node) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) NodeList(org.graalvm.compiler.graph.NodeList) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 40 with Receiver

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

the class StandardGraphBuilderPlugins method registerObjectPlugins.

private static void registerObjectPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Object.class);
    r.register1("<init>", Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            /*
                 * Object.<init> is a common instrumentation point so only perform this rewrite if
                 * the current definition is the normal empty method with a single return bytecode.
                 * The finalizer registration will instead be performed by the BytecodeParser.
                 */
            if (targetMethod.getCodeSize() == 1) {
                ValueNode object = receiver.get();
                if (RegisterFinalizerNode.mayHaveFinalizer(object, b.getAssumptions())) {
                    b.add(new RegisterFinalizerNode(object));
                }
                return true;
            }
            return false;
        }
    });
    r.register1("getClass", Receiver.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            ValueNode object = receiver.get();
            ValueNode folded = GetClassNode.tryFold(b.getMetaAccess(), b.getConstantReflection(), NodeView.DEFAULT, GraphUtil.originalValue(object));
            if (folded != null) {
                b.addPush(JavaKind.Object, folded);
            } else {
                Stamp stamp = StampFactory.objectNonNull(TypeReference.createTrusted(b.getAssumptions(), b.getMetaAccess().lookupJavaType(Class.class)));
                b.addPush(JavaKind.Object, new GetClassNode(stamp, object));
            }
            return true;
        }
    });
}
Also used : ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) GetClassNode(org.graalvm.compiler.nodes.extended.GetClassNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) RegisterFinalizerNode(org.graalvm.compiler.nodes.java.RegisterFinalizerNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)57 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)57 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)57 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 ValueNode (org.graalvm.compiler.nodes.ValueNode)52 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)52 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)13 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)13 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 LogicNode (org.graalvm.compiler.nodes.LogicNode)8 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)7 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)6 JavaConstant (jdk.vm.ci.meta.JavaConstant)5 JavaKind (jdk.vm.ci.meta.JavaKind)5 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)4 GetClassNode (org.graalvm.compiler.nodes.extended.GetClassNode)4 AnalysisArraysCopyOfNode (com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode)3 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)3 BlackholeNode (org.graalvm.compiler.nodes.debug.BlackholeNode)3