Search in sources :

Example 36 with RequiredInvocationPlugin

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

the class VMThreadMTFeature method registerAccessors.

private void registerAccessors(Registration r, Class<?> valueClass, boolean isVolatile) {
    String suffix = isVolatile ? "Volatile" : "";
    /* get() method without the VMThread parameter. */
    r.register(new RequiredInvocationPlugin("get" + suffix, Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            ValueNode threadNode = currentThread(b);
            return handleGet(b, targetMethod, receiver, threadNode, isVolatile);
        }
    });
    /* get() method with the VMThread parameter. */
    r.register(new RequiredInvocationPlugin("get" + suffix, Receiver.class, IsolateThread.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode) {
            return handleGet(b, targetMethod, receiver, threadNode, isVolatile);
        }
    });
    /* set() method without the VMThread parameter. */
    r.register(new RequiredInvocationPlugin("set" + suffix, Receiver.class, valueClass) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode valueNode) {
            ValueNode threadNode = currentThread(b);
            return handleSet(b, receiver, threadNode, valueNode, isVolatile);
        }
    });
    /* set() method with the VMThread parameter. */
    r.register(new RequiredInvocationPlugin("set" + suffix, Receiver.class, IsolateThread.class, valueClass) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode threadNode, ValueNode valueNode) {
            return handleSet(b, receiver, threadNode, valueNode, isVolatile);
        }
    });
}
Also used : IsolateThread(org.graalvm.nativeimage.IsolateThread) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 37 with RequiredInvocationPlugin

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

the class StaticFieldBaseNode method registerInvocationPlugins.

@Override
public void registerInvocationPlugins(Providers providers, SnippetReflectionProvider snippetReflection, Plugins plugins, ParsingReason reason) {
    Registration r = new Registration(plugins.getInvocationPlugins(), StaticFieldsSupport.class);
    r.register(new RequiredInvocationPlugin("getStaticObjectFields") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused) {
            b.addPush(JavaKind.Object, new StaticFieldBaseNode(false));
            return true;
        }
    });
    r.register(new RequiredInvocationPlugin("getStaticPrimitiveFields") {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused) {
            b.addPush(JavaKind.Object, new StaticFieldBaseNode(true));
            return true;
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 38 with RequiredInvocationPlugin

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

the class TruffleGraphBuilderPlugins method registerUnsafeCast.

public static void registerUnsafeCast(Registration r, boolean canDelayIntrinsification, EconomicSet<ResolvedJavaType> primitiveBoxTypes) {
    r.register(new RequiredInvocationPlugin("unsafeCast", Object.class, Class.class, boolean.class, boolean.class, boolean.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode clazz, ValueNode condition, ValueNode nonNull, ValueNode isExactType) {
            if (clazz.isConstant() && nonNull.isConstant() && isExactType.isConstant()) {
                ConstantReflectionProvider constantReflection = b.getConstantReflection();
                ResolvedJavaType javaType = constantReflection.asJavaType(clazz.asConstant());
                if (javaType == null) {
                    b.push(JavaKind.Object, object);
                } else {
                    TypeReference type;
                    if (isExactType.asJavaConstant().asInt() != 0) {
                        assert javaType.isConcrete() || javaType.isArray() : "exact type is not a concrete class: " + javaType;
                        type = TypeReference.createExactTrusted(javaType);
                    } else {
                        type = TypeReference.createTrusted(b.getAssumptions(), javaType);
                    }
                    Stamp piStamp = StampFactory.object(type, nonNull.asJavaConstant().asInt() != 0);
                    ConditionAnchorNode valueAnchorNode = null;
                    if (condition.isConstant() && condition.asJavaConstant().asInt() == 1) {
                    // Nothing to do.
                    } else {
                        boolean skipAnchor = false;
                        LogicNode compareNode = CompareNode.createCompareNode(object.graph(), CanonicalCondition.EQ, condition, ConstantNode.forBoolean(true, object.graph()), constantReflection, NodeView.DEFAULT);
                        if (compareNode instanceof LogicConstantNode) {
                            LogicConstantNode logicConstantNode = (LogicConstantNode) compareNode;
                            if (logicConstantNode.getValue()) {
                                skipAnchor = true;
                            }
                        }
                        if (!skipAnchor) {
                            valueAnchorNode = b.add(new ConditionAnchorNode(compareNode));
                        }
                    }
                    b.addPush(JavaKind.Object, trustedBox(type, primitiveBoxTypes, PiNode.create(object, piStamp, valueAnchorNode)));
                }
                return true;
            } else if (canDelayIntrinsification) {
                return false;
            } else {
                logPerformanceWarningUnsafeCastArgNotConst(targetMethod, clazz, nonNull, isExactType);
                b.push(JavaKind.Object, object);
                return true;
            }
        }
    });
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 39 with RequiredInvocationPlugin

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

the class TruffleGraphBuilderPlugins method registerNodePlugins.

/**
 * @see com.oracle.truffle.api.nodes.Node
 */
public static void registerNodePlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, boolean canDelayIntrinsification, ConstantReflectionProvider constantReflection, KnownTruffleTypes types) {
    final ResolvedJavaType nodeType = getRuntime().resolveType(metaAccess, "com.oracle.truffle.api.nodes.Node");
    Registration r = new Registration(plugins, new ResolvedJavaSymbol(nodeType));
    r.register(new RequiredInvocationPlugin("getRootNodeImpl", Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (canDelayIntrinsification) {
                return false;
            }
            ValueNode thisValue = receiver.get();
            if (!thisValue.isJavaConstant() || thisValue.isNullConstant()) {
                throw b.bailout("getRootNode() receiver is not a compile-time constant or is null.");
            }
            final int parentLimit = MaximumLoopExplosionCount.getValue(b.getOptions());
            JavaConstant parentNode = thisValue.asJavaConstant();
            JavaConstant prevNode;
            int parentsVisited = 0;
            do {
                if (parentsVisited++ > parentLimit) {
                    // Protect against parent cycles and extremely long parent chains.
                    throw b.bailout("getRootNode() did not terminate in " + parentLimit + " iterations.");
                }
                prevNode = parentNode;
                parentNode = constantReflection.readFieldValue(types.fieldNodeParent, prevNode);
            } while (parentNode.isNonNull());
            JavaConstant rootNode = prevNode;
            ConstantNode result = ConstantNode.forConstant(rootNode, metaAccess, b.getGraph());
            // getRootNodeImpl() returns null if parent is not an instance of RootNode.
            if (rootNode.isNonNull() && !types.classRootNode.isAssignableFrom(result.stamp(NodeView.DEFAULT).javaType(metaAccess))) {
                result = ConstantNode.defaultForKind(JavaKind.Object, b.getGraph());
            }
            b.addPush(JavaKind.Object, result);
            return true;
        }
    });
}
Also used : LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) IsCompilationConstantNode(org.graalvm.compiler.truffle.compiler.nodes.IsCompilationConstantNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) ValueNode(org.graalvm.compiler.nodes.ValueNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 40 with RequiredInvocationPlugin

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

the class TruffleGraphBuilderPlugins method registerOptimizedAssumptionPlugins.

public static void registerOptimizedAssumptionPlugins(InvocationPlugins plugins, MetaAccessProvider metaAccess, KnownTruffleTypes types) {
    ResolvedJavaType optimizedAssumptionType = getRuntime().resolveType(metaAccess, "org.graalvm.compiler.truffle.runtime.OptimizedAssumption");
    Registration r = new Registration(plugins, new ResolvedJavaSymbol(optimizedAssumptionType));
    r.register(new RequiredInvocationPlugin("isValid", Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (receiver.isConstant() && b.getAssumptions() != null) {
                JavaConstant assumption = (JavaConstant) receiver.get().asConstant();
                if (b.getConstantReflection().readFieldValue(types.fieldOptimizedAssumptionIsValid, assumption).asBoolean()) {
                    b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
                    b.getAssumptions().record(new TruffleAssumption(assumption));
                } else {
                    b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
                }
                return true;
            } else {
                return false;
            }
        }
    });
    r.register(new RequiredInvocationPlugin("check", Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (receiver.isConstant() && b.getAssumptions() != null) {
                JavaConstant assumption = (JavaConstant) receiver.get().asConstant();
                if (b.getConstantReflection().readFieldValue(types.fieldOptimizedAssumptionIsValid, assumption).asBoolean()) {
                    b.getAssumptions().record(new TruffleAssumption(assumption));
                } else {
                    b.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.None));
                }
                return true;
            } else {
                return false;
            }
        }
    });
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) TruffleAssumption(org.graalvm.compiler.truffle.compiler.nodes.TruffleAssumption) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) JavaConstant(jdk.vm.ci.meta.JavaConstant) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) ResolvedJavaSymbol(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)47 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)47 RequiredInvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin)47 ValueNode (org.graalvm.compiler.nodes.ValueNode)38 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)37 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)34 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)14 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)9 ResolvedJavaSymbol (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.ResolvedJavaSymbol)8 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)6 JavaConstant (jdk.vm.ci.meta.JavaConstant)5 LogicNode (org.graalvm.compiler.nodes.LogicNode)5 InvocationPlugins (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins)5 IsolateThread (org.graalvm.nativeimage.IsolateThread)4 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)3 TruffleCompilerRuntime (org.graalvm.compiler.truffle.common.TruffleCompilerRuntime)3 AllowMaterializeNode (org.graalvm.compiler.truffle.compiler.nodes.frame.AllowMaterializeNode)3 NewFrameNode (org.graalvm.compiler.truffle.compiler.nodes.frame.NewFrameNode)3 VirtualFrameGetNode (org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameGetNode)3 VirtualFrameSetNode (org.graalvm.compiler.truffle.compiler.nodes.frame.VirtualFrameSetNode)3