Search in sources :

Example 56 with GraphBuilderContext

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

the class StandardGraphBuilderPlugins method registerJcovCollectPlugins.

/**
 * Registers a plugin to ignore {@code com.sun.tdk.jcov.runtime.Collect.hit} within an
 * intrinsic.
 */
private static void registerJcovCollectPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins, "com.sun.tdk.jcov.runtime.Collect", bytecodeProvider);
    r.register1("hit", int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            if (b.parsingIntrinsic()) {
                return true;
            }
            return false;
        }
    });
}
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) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 57 with GraphBuilderContext

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

the class StandardGraphBuilderPlugins method registerJMHBlackholePlugins.

private static void registerJMHBlackholePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
    InvocationPlugin blackholePlugin = new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver blackhole, ValueNode value) {
            blackhole.get();
            b.add(new BlackholeNode(value));
            return true;
        }
    };
    String[] names = { "org.openjdk.jmh.infra.Blackhole", "org.openjdk.jmh.logic.BlackHole" };
    for (String name : names) {
        Registration r = new Registration(plugins, name, bytecodeProvider);
        for (JavaKind kind : JavaKind.values()) {
            if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
                Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
                r.registerOptional2("consume", Receiver.class, javaClass, blackholePlugin);
            }
        }
        r.registerOptional2("consume", Receiver.class, Object[].class, blackholePlugin);
    }
}
Also used : BlackholeNode(org.graalvm.compiler.nodes.debug.BlackholeNode) 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) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 58 with GraphBuilderContext

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

the class StandardGraphBuilderPlugins method registerMethodHandleImplPlugins.

private static void registerMethodHandleImplPlugins(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins, "java.lang.invoke.MethodHandleImpl", bytecodeProvider);
    r.register2("profileBoolean", boolean.class, int[].class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode counters) {
            if (result.isConstant()) {
                b.push(JavaKind.Boolean, result);
                return true;
            }
            if (counters.isConstant()) {
                ValueNode newResult = result;
                int[] ctrs = snippetReflection.asObject(int[].class, (JavaConstant) counters.asConstant());
                if (ctrs != null && ctrs.length == 2) {
                    int falseCount = ctrs[0];
                    int trueCount = ctrs[1];
                    int totalCount = trueCount + falseCount;
                    if (totalCount == 0) {
                        b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.TransferToInterpreter));
                    } else if (falseCount == 0 || trueCount == 0) {
                        boolean expected = falseCount == 0;
                        LogicNode condition = b.addWithInputs(IntegerEqualsNode.create(b.getConstantReflection(), b.getMetaAccess(), b.getOptions(), null, result, b.add(ConstantNode.forBoolean(!expected)), NodeView.DEFAULT));
                        b.append(new FixedGuardNode(condition, DeoptimizationReason.UnreachedCode, DeoptimizationAction.InvalidateReprofile, true));
                        newResult = b.add(ConstantNode.forBoolean(expected));
                    } else {
                    // We cannot use BranchProbabilityNode here since there's no guarantee
                    // the result of MethodHandleImpl.profileBoolean() is used as the
                    // test in an `if` statement (as required by BranchProbabilityNode).
                    }
                }
                b.addPush(JavaKind.Boolean, newResult);
                return true;
            }
            return false;
        }
    });
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) 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) JavaConstant(jdk.vm.ci.meta.JavaConstant) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 59 with GraphBuilderContext

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

the class StandardGraphBuilderPlugins method registerArrayPlugins.

private static void registerArrayPlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins, Array.class, bytecodeProvider);
    r.register2("newInstance", Class.class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode componentType, ValueNode length) {
            b.addPush(JavaKind.Object, new DynamicNewArrayNode(componentType, length, true));
            return true;
        }
    });
    r.registerMethodSubstitution(ArraySubstitutions.class, "getLength", Object.class);
}
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) DynamicNewArrayNode(org.graalvm.compiler.nodes.java.DynamicNewArrayNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 60 with GraphBuilderContext

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

the class StandardGraphBuilderPlugins method registerShortPlugins.

private static void registerShortPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Short.class);
    r.register1("reverseBytes", short.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            // return (short) (Integer.reverse(i) >> 16);
            ReverseBytesNode reverse = b.add(new ReverseBytesNode(value));
            RightShiftNode rightShift = b.add(new RightShiftNode(reverse, b.add(ConstantNode.forInt(16))));
            SignExtendNode charCast = b.add(new SignExtendNode(b.add(new NarrowNode(rightShift, 16)), 32));
            b.push(JavaKind.Short, b.append(charCast.canonical(null)));
            return true;
        }
    });
}
Also used : SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ReverseBytesNode(org.graalvm.compiler.replacements.nodes.ReverseBytesNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)88 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)86 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)83 ValueNode (org.graalvm.compiler.nodes.ValueNode)76 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)66 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)13 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)13 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)10 LogicNode (org.graalvm.compiler.nodes.LogicNode)10 JavaKind (jdk.vm.ci.meta.JavaKind)9 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)8 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)6 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)6 Stamp (org.graalvm.compiler.core.common.type.Stamp)4 GetClassNode (org.graalvm.compiler.nodes.extended.GetClassNode)4 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)4