Search in sources :

Example 1 with InlineOnlyInvocationPlugin

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

the class ConditionalEliminationRegressionTest method editGraphBuilderConfiguration.

@Override
protected GraphBuilderConfiguration editGraphBuilderConfiguration(GraphBuilderConfiguration conf) {
    Registration r = new Registration(conf.getPlugins().getInvocationPlugins(), ConditionalEliminationRegressionTest.class);
    r.register(new InlineOnlyInvocationPlugin("deoptimizeAndInvalidateUnreached") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateReprofile, DeoptimizationReason.UnreachedCode));
            return true;
        }
    });
    r.register(new InlineOnlyInvocationPlugin("guardingBoolean", Object.class, boolean.class, boolean.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value, ValueNode condition, ValueNode negatedConstant) {
            if (!(condition instanceof ConditionalNode)) {
                return false;
            }
            LogicNode l = ((ConditionalNode) condition).condition();
            boolean isNullCheck = l instanceof IsNullNode;
            boolean negated = ((PrimitiveConstant) negatedConstant.asConstant()).asInt() == 1;
            GuardingNode guardingNode;
            if (isNullCheck) {
                guardingNode = b.append(new FixedGuardNode(l, DeoptimizationReason.NullCheckException, DeoptimizationAction.InvalidateRecompile, negated));
            } else {
                guardingNode = b.append(new FixedGuardNode(l, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateRecompile, negated));
            }
            b.addPush(value.getStackKind(), PiNode.create(value, objectNonNull(), guardingNode.asNode()));
            return true;
        }
    });
    return super.editGraphBuilderConfiguration(conf);
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) PrimitiveConstant(jdk.vm.ci.meta.PrimitiveConstant) 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) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode)

Example 2 with InlineOnlyInvocationPlugin

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

the class HotSpotGraphBuilderPlugins method registerSystemPlugins.

private static void registerSystemPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, System.class);
    r.register(new ForeignCallPlugin(HotSpotHostForeignCallsProvider.JAVA_TIME_MILLIS, "currentTimeMillis"));
    r.register(new ForeignCallPlugin(HotSpotHostForeignCallsProvider.JAVA_TIME_NANOS, "nanoTime"));
    r.register(new InlineOnlyInvocationPlugin("identityHashCode", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.addPush(JavaKind.Int, new HotSpotIdentityHashCodeNode(object, b.bci()));
            return true;
        }
    });
    ArrayCopySnippets.registerSystemArraycopyPlugin(r);
}
Also used : ForeignCallPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ForeignCallPlugin) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) HotSpotIdentityHashCodeNode(org.graalvm.compiler.hotspot.replacements.HotSpotIdentityHashCodeNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with InlineOnlyInvocationPlugin

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

the class HotSpotGraphBuilderPlugins method registerObjectPlugins.

private static void registerObjectPlugins(InvocationPlugins plugins, GraalHotSpotVMConfig config, Replacements replacements) {
    Registration r = new Registration(plugins, Object.class, replacements);
    r.register(new InlineOnlyInvocationPlugin("clone", Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            ValueNode object = receiver.get();
            b.addPush(JavaKind.Object, new ObjectCloneNode(MacroParams.of(b, targetMethod, object)));
            return true;
        }
    });
    r.register(new InlineOnlyInvocationPlugin("hashCode", Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            ValueNode object = receiver.get();
            b.addPush(JavaKind.Int, new HotSpotIdentityHashCodeNode(object, b.bci()));
            return true;
        }
    });
    if (config.inlineNotify()) {
        r.register(new InlineOnlyInvocationPlugin("notify", Receiver.class) {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
                ValueNode object = receiver.get();
                b.add(new FastNotifyNode(object, false, b.bci()));
                return true;
            }
        });
    }
    if (config.inlineNotifyAll()) {
        r.register(new InlineOnlyInvocationPlugin("notifyAll", Receiver.class) {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
                ValueNode object = receiver.get();
                b.add(new FastNotifyNode(object, true, b.bci()));
                return true;
            }
        });
    }
}
Also used : ObjectCloneNode(org.graalvm.compiler.hotspot.replacements.ObjectCloneNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) HotSpotIdentityHashCodeNode(org.graalvm.compiler.hotspot.replacements.HotSpotIdentityHashCodeNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) FastNotifyNode(org.graalvm.compiler.hotspot.replacements.FastNotifyNode)

Example 4 with InlineOnlyInvocationPlugin

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

the class HotSpotGraphBuilderPlugins method registerReflectionPlugins.

private static void registerReflectionPlugins(InvocationPlugins plugins, Replacements replacements, GraalHotSpotVMConfig config) {
    Registration r = new Registration(plugins, reflectionClass, replacements);
    r.register(new InlineOnlyInvocationPlugin("getCallerClass") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new HotSpotReflectionGetCallerClassNode(MacroParams.of(b, targetMethod)));
            return true;
        }
    });
    r.register(new InvocationPlugin("getClassAccessFlags", Class.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg) {
            try (HotSpotInvocationPluginHelper helper = new HotSpotInvocationPluginHelper(b, targetMethod, config)) {
                ValueNode klass = helper.readKlassFromClass(b.nullCheckedValue(arg));
                // Primitive Class case
                ValueNode klassNonNull = helper.emitNullReturnGuard(klass, ConstantNode.forInt(Modifier.ABSTRACT | Modifier.FINAL | Modifier.PUBLIC), GraalDirectives.UNLIKELY_PROBABILITY);
                // Return (Klass::_access_flags & jvmAccWrittenFlags)
                ValueNode accessFlags = helper.readKlassAccessFlags(klassNonNull);
                helper.emitFinalReturn(JavaKind.Int, new AndNode(accessFlags, ConstantNode.forInt(config.jvmAccWrittenFlags)));
            }
            return true;
        }
    });
}
Also used : HotSpotReflectionGetCallerClassNode(org.graalvm.compiler.hotspot.replacements.HotSpotReflectionGetCallerClassNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) SnippetSubstitutionInvocationPlugin(org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) AndNode(org.graalvm.compiler.nodes.calc.AndNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) HotSpotInvocationPluginHelper(org.graalvm.compiler.hotspot.replacements.HotSpotInvocationPluginHelper)

Example 5 with InlineOnlyInvocationPlugin

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

the class AArch64GraphBuilderPlugins method registerMathPlugins.

private static void registerMathPlugins(InvocationPlugins plugins, boolean registerForeignCallMath) {
    Registration r = new Registration(plugins, Math.class);
    if (registerForeignCallMath) {
        registerUnaryMath(r, "sin", SIN);
        registerUnaryMath(r, "cos", COS);
        registerUnaryMath(r, "tan", TAN);
        registerUnaryMath(r, "exp", EXP);
        registerUnaryMath(r, "log", LOG);
        registerUnaryMath(r, "log10", LOG10);
        r.register(new InlineOnlyInvocationPlugin("pow", double.class, double.class) {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
                b.push(JavaKind.Double, b.append(BinaryMathIntrinsicNode.create(x, y, BinaryMathIntrinsicNode.BinaryOperation.POW)));
                return true;
            }
        });
    }
    registerFMA(r);
    registerIntegerAbs(r);
    r.register(new InvocationPlugin("multiplyHigh", long.class, long.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode x, ValueNode y) {
            b.push(JavaKind.Long, b.append(new IntegerMulHighNode(x, y)));
            return true;
        }
    });
    registerMinMax(r);
    r.register(new InvocationPlugin("copySign", float.class, float.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode magnitude, ValueNode sign) {
            b.addPush(JavaKind.Float, new CopySignNode(magnitude, sign));
            return true;
        }
    });
    r.register(new InvocationPlugin("copySign", double.class, double.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode magnitude, ValueNode sign) {
            b.addPush(JavaKind.Double, new CopySignNode(magnitude, sign));
            return true;
        }
    });
}
Also used : CopySignNode(org.graalvm.compiler.nodes.calc.CopySignNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) SnippetSubstitutionInvocationPlugin(org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) InlineOnlyInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin) IntegerMulHighNode(org.graalvm.compiler.nodes.calc.IntegerMulHighNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)13 ValueNode (org.graalvm.compiler.nodes.ValueNode)13 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)13 InlineOnlyInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.InlineOnlyInvocationPlugin)13 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)12 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)11 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)6 RequiredInlineOnlyInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInlineOnlyInvocationPlugin)6 LogicNode (org.graalvm.compiler.nodes.LogicNode)5 OptionalInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.OptionalInvocationPlugin)4 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)3 RequiredInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin)3 SnippetSubstitutionInvocationPlugin (org.graalvm.compiler.replacements.SnippetSubstitutionInvocationPlugin)3 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 HotSpotIdentityHashCodeNode (org.graalvm.compiler.hotspot.replacements.HotSpotIdentityHashCodeNode)2 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)2 ConditionalNode (org.graalvm.compiler.nodes.calc.ConditionalNode)2 JavaReadNode (org.graalvm.compiler.nodes.extended.JavaReadNode)2 PhantomReference (java.lang.ref.PhantomReference)1 BiFunction (java.util.function.BiFunction)1