Search in sources :

Example 1 with ProfileBooleanNode

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

the class StandardGraphBuilderPlugins method registerMethodHandleImplPlugins.

private static void registerMethodHandleImplPlugins(InvocationPlugins plugins, Replacements replacements) {
    Registration r = new Registration(plugins, "java.lang.invoke.MethodHandleImpl", replacements);
    // In later JDKs this no longer exists and the usage is replace by Class.cast which is
    // already an intrinsic
    r.register(new OptionalInvocationPlugin("castReference", Class.class, Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode javaClass, ValueNode object) {
            b.genCheckcastDynamic(object, javaClass);
            return true;
        }

        @Override
        public boolean inlineOnly() {
            return true;
        }
    });
    r.register(new InlineOnlyInvocationPlugin("profileBoolean", boolean.class, int[].class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode counters) {
            if (b.needsExplicitException()) {
                return false;
            }
            if (result.isConstant()) {
                b.push(JavaKind.Boolean, result);
                return true;
            }
            if (counters.isConstant()) {
                ValueNode newResult = result;
                int[] ctrs = ConstantReflectionUtil.loadIntArrayConstant(b.getConstantReflection(), (JavaConstant) counters.asConstant(), 2);
                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.add(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;
            }
            b.addPush(JavaKind.Boolean, new ProfileBooleanNode(b.getConstantReflection(), MacroParams.of(b, targetMethod, result, counters)));
            return true;
        }
    });
    r.register(new RequiredInlineOnlyInvocationPlugin("isCompileConstant", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode obj) {
            b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(obj.isConstant()));
            return true;
        }
    });
}
Also used : ProfileBooleanNode(org.graalvm.compiler.replacements.nodes.ProfileBooleanNode) RequiredInlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInlineOnlyInvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) JavaConstant(jdk.vm.ci.meta.JavaConstant) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) OptionalInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) RequiredInlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInlineOnlyInvocationPlugin) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

JavaConstant (jdk.vm.ci.meta.JavaConstant)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)1 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)1 LogicNode (org.graalvm.compiler.nodes.LogicNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1 InlineOnlyInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin)1 OptionalInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin)1 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1 RequiredInlineOnlyInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInlineOnlyInvocationPlugin)1 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)1 ProfileBooleanNode (org.graalvm.compiler.replacements.nodes.ProfileBooleanNode)1