Search in sources :

Example 26 with InvocationPlugin

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

the class CountedLoopTest method registerPlugins.

private void registerPlugins(Registration r, JavaKind ivKind) {
    r.register2("get", IVProperty.class, ivKind.toJavaClass(), new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2) {
            IVProperty property = null;
            if (arg1.isConstant()) {
                property = getSnippetReflection().asObject(IVProperty.class, arg1.asJavaConstant());
            }
            if (property != null) {
                b.addPush(ivKind, new IVPropertyNode(property, null, null, arg2));
                return true;
            } else {
                return false;
            }
        }
    });
    r.register4("get", IVProperty.class, StaticIVProperty.class, IVPredicate.class, ivKind.toJavaClass(), new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode arg1, ValueNode arg2, ValueNode arg3, ValueNode arg4) {
            IVProperty property = null;
            StaticIVProperty staticProperty = null;
            IVPredicate staticCheck = null;
            if (arg1.isConstant()) {
                property = getSnippetReflection().asObject(IVProperty.class, arg1.asJavaConstant());
            }
            if (arg2.isConstant()) {
                staticProperty = getSnippetReflection().asObject(StaticIVProperty.class, arg2.asJavaConstant());
            }
            if (arg3.isConstant()) {
                staticCheck = getSnippetReflection().asObject(IVPredicate.class, arg3.asJavaConstant());
            }
            if (property != null && staticProperty != null && staticCheck != null) {
                b.addPush(ivKind, new IVPropertyNode(property, staticProperty, staticCheck, arg4));
                return true;
            } else {
                return false;
            }
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 27 with InvocationPlugin

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

the class SubstrateGraphBuilderPlugins method registerJFRThrowablePlugins.

/*
     * When Java Flight Recorder is enabled during image generation, the bytecodes of some methods
     * get instrumented. Undo the instrumentation so that it does not end up in the generated image.
     */
private static void registerJFRThrowablePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
    Registration r = new Registration(plugins, "oracle.jrockit.jfr.jdkevents.ThrowableTracer", bytecodeProvider).setAllowOverwrite(true);
    r.register2("traceError", Error.class, String.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode throwable, ValueNode message) {
            return true;
        }
    });
    r.register2("traceThrowable", Throwable.class, String.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode throwable, ValueNode message) {
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 28 with InvocationPlugin

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

the class SubstrateGraphBuilderPlugins method registerClassPlugins.

private static void registerClassPlugins(InvocationPlugins plugins) {
    /*
         * We have our own Java-level implementation of isAssignableFrom() in DynamicHub, so we do
         * not need to intrinsifiy that to a Graal node. Therefore, we overwrite and deactivate the
         * invocation plugin registered in StandardGraphBuilderPlugins.
         *
         * TODO we should remove the implementation from DynamicHub to a lowering of
         * ClassIsAssignableFromNode. Then we can remove this code.
         */
    Registration r = new Registration(plugins, Class.class).setAllowOverwrite(true);
    r.register2("isAssignableFrom", Receiver.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver type, ValueNode otherType) {
            return false;
        }
    });
    r.register2("cast", Receiver.class, Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            ValueNode toType = receiver.get();
            LogicNode condition = b.append(InstanceOfDynamicNode.create(b.getAssumptions(), b.getConstantReflection(), toType, object, true));
            if (condition.isTautology()) {
                b.addPush(JavaKind.Object, object);
            } else {
                FixedGuardNode fixedGuard = b.add(new FixedGuardNode(condition, DeoptimizationReason.ClassCastException, DeoptimizationAction.InvalidateReprofile, false));
                b.addPush(JavaKind.Object, DynamicPiNode.create(b.getAssumptions(), b.getConstantReflection(), object, fixedGuard, toType));
            }
            return true;
        }
    });
    r.register2("isInstance", Receiver.class, Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            ValueNode type = receiver.get();
            LogicNode condition = b.append(InstanceOfDynamicNode.create(null, b.getConstantReflection(), type, object, false));
            b.push(JavaKind.Boolean.getStackKind(), b.append(new ConditionalNode(condition).canonical(null)));
            return true;
        }
    });
}
Also used : FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) LogicNode(org.graalvm.compiler.nodes.LogicNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 29 with InvocationPlugin

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

the class SubstrateGraphBuilderPlugins method registerStackValuePlugins.

private static void registerStackValuePlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, StackValue.class);
    r.register1("get", int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode sizeNode) {
            long size = longValue(b, targetMethod, sizeNode, "size");
            StackSlotIdentity slotIdentity = new StackSlotIdentity(b.getGraph().method().asStackTraceElement(b.bci()).toString());
            b.addPush(JavaKind.Object, new StackValueNode(1, size, slotIdentity));
            return true;
        }
    });
    r.register2("get", int.class, int.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode numElementsNode, ValueNode elementSizeNode) {
            long numElements = longValue(b, targetMethod, numElementsNode, "numElements");
            long elementSize = longValue(b, targetMethod, elementSizeNode, "elementSize");
            StackSlotIdentity slotIdentity = new StackSlotIdentity(b.getGraph().method().asStackTraceElement(b.bci()).toString());
            b.addPush(JavaKind.Object, new StackValueNode(numElements, elementSize, slotIdentity));
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) StackSlotIdentity(com.oracle.svm.core.graal.stackvalue.StackValueNode.StackSlotIdentity) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 30 with InvocationPlugin

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

the class SubstrateGraphBuilderPlugins method registerUnsafePlugins.

private static void registerUnsafePlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Unsafe.class).setAllowOverwrite(true);
    r.register2("allocateInstance", Receiver.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode clazz) {
            ValueNode clazzNonNull = b.nullCheckedValue(clazz, DeoptimizationAction.None);
            b.addPush(JavaKind.Object, new SubstrateDynamicNewInstanceNode(clazzNonNull));
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) Unsafe(sun.misc.Unsafe) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) SubstrateDynamicNewInstanceNode(com.oracle.svm.core.graal.nodes.SubstrateDynamicNewInstanceNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)92 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)89 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)83 ValueNode (org.graalvm.compiler.nodes.ValueNode)74 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)9 LogicNode (org.graalvm.compiler.nodes.LogicNode)9 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)8 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7 JavaConstant (jdk.vm.ci.meta.JavaConstant)6 JavaKind (jdk.vm.ci.meta.JavaKind)6 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)6 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)6 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)5 GetClassNode (org.graalvm.compiler.nodes.extended.GetClassNode)4 AnalysisArraysCopyOfNode (com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode)3 Stamp (org.graalvm.compiler.core.common.type.Stamp)3