Search in sources :

Example 6 with RequiredInvocationPlugin

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

the class SubstrateGraphBuilderPlugins method registerSystemPlugins.

private static void registerSystemPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
    Registration r = new Registration(plugins, System.class);
    if (SubstrateOptions.FoldSecurityManagerGetter.getValue()) {
        r.register(new RequiredInvocationPlugin("getSecurityManager") {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
                /* System.getSecurityManager() always returns null. */
                b.addPush(JavaKind.Object, ConstantNode.forConstant(SubstrateObjectConstant.forObject(null), metaAccess, b.getGraph()));
                return true;
            }
        });
    }
    r.register(new RequiredInvocationPlugin("identityHashCode", Object.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.addPush(JavaKind.Int, new SubstrateIdentityHashCodeNode(object, b.bci()));
            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) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) SubstrateIdentityHashCodeNode(com.oracle.svm.core.identityhashcode.SubstrateIdentityHashCodeNode)

Example 7 with RequiredInvocationPlugin

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

the class SubstrateGraphBuilderPlugins method registerClassDesiredAssertionStatusPlugin.

public static void registerClassDesiredAssertionStatusPlugin(InvocationPlugins plugins, SnippetReflectionProvider snippetReflection) {
    Registration r = new Registration(plugins, Class.class);
    r.register(new RequiredInvocationPlugin("desiredAssertionStatus", Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            JavaConstant constantReceiver = receiver.get().asJavaConstant();
            if (constantReceiver != null && constantReceiver.isNonNull()) {
                Object clazzOrHub = snippetReflection.asObject(Object.class, constantReceiver);
                boolean desiredAssertionStatus;
                if (clazzOrHub instanceof Class) {
                    desiredAssertionStatus = RuntimeAssertionsSupport.singleton().desiredAssertionStatus((Class<?>) clazzOrHub);
                } else if (clazzOrHub instanceof DynamicHub) {
                    desiredAssertionStatus = ((DynamicHub) clazzOrHub).desiredAssertionStatus();
                } else {
                    throw VMError.shouldNotReachHere("Unexpected class object: " + clazzOrHub);
                }
                b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(desiredAssertionStatus));
                return true;
            }
            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) DynamicHub(com.oracle.svm.core.hub.DynamicHub) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) JavaConstant(jdk.vm.ci.meta.JavaConstant) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 8 with RequiredInvocationPlugin

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

the class SubstrateGraphBuilderPlugins method registerImageInfoPlugins.

private static void registerImageInfoPlugins(MetaAccessProvider metaAccess, InvocationPlugins plugins) {
    Registration proxyRegistration = new Registration(plugins, ImageInfo.class);
    proxyRegistration.register(new RequiredInvocationPlugin("inImageCode") {

        /**
         * See {@link ImageInfo#inImageCode()}.
         */
        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.push(JavaKind.Boolean, ConstantNode.forConstant(JavaConstant.TRUE, metaAccess, b.getGraph()));
            return true;
        }
    });
    proxyRegistration.register(new RequiredInvocationPlugin("inImageBuildtimeCode") {

        /**
         * See {@link ImageInfo#inImageBuildtimeCode()}.
         */
        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.push(JavaKind.Boolean, ConstantNode.forConstant(JavaConstant.FALSE, metaAccess, b.getGraph()));
            return true;
        }
    });
    proxyRegistration.register(new RequiredInvocationPlugin("inImageRuntimeCode") {

        /**
         * See {@link ImageInfo#inImageRuntimeCode()}.
         */
        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.push(JavaKind.Boolean, ConstantNode.forConstant(JavaConstant.TRUE, metaAccess, b.getGraph()));
            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) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 9 with RequiredInvocationPlugin

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

the class PointstoGraphBuilderPlugins method registerObjectPlugins.

public static void registerObjectPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, Object.class);
    r.register(new RequiredInvocationPlugin("clone", Receiver.class) {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            ValueNode object = receiver.get();
            b.addPush(JavaKind.Object, new AnalysisObjectCloneNode(MacroParams.of(b, targetMethod, object)));
            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) ValueNode(org.graalvm.compiler.nodes.ValueNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) AnalysisObjectCloneNode(com.oracle.graal.pointsto.nodes.AnalysisObjectCloneNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 10 with RequiredInvocationPlugin

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

the class CGlobalDataFeature method registerInvocationPlugins.

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

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            ValueNode cGlobalDataNode = receiver.get();
            if (cGlobalDataNode.isConstant()) {
                CGlobalDataImpl<?> data = (CGlobalDataImpl<?>) SubstrateObjectConstant.asObject(cGlobalDataNode.asConstant());
                CGlobalDataInfo info = CGlobalDataFeature.this.map.get(data);
                b.addPush(targetMethod.getSignature().getReturnKind(), new CGlobalDataLoadAddressNode(info));
            } else {
                ConstantNode registry = ConstantNode.forConstant(nonConstantRegistryJavaConstant, b.getMetaAccess(), b.getGraph());
                ValueNode info = (ValueNode) b.handleReplacedInvoke(InvokeKind.Virtual, b.getMetaAccess().lookupJavaMethod(getCGlobalDataInfoMethod), new ValueNode[] { registry, cGlobalDataNode }, false);
                b.pop(info.getStackKind());
                info = b.nullCheckedValue(info);
                ResolvedJavaType infoType = b.getMetaAccess().lookupJavaType(CGlobalDataInfo.class);
                if (infoType instanceof AnalysisType) {
                    ((AnalysisType) infoType).registerAsReachable();
                }
                ValueNode offset = b.add(LoadFieldNode.create(b.getAssumptions(), info, b.getMetaAccess().lookupJavaField(offsetField)));
                CGlobalDataLoadAddressNode baseAddress = b.add(new CGlobalDataLoadAddressNode(cGlobalDataBaseAddress));
                /* Both operands should have the same bits size */
                ValueNode offsetWidened = b.getGraph().addOrUnique(SignExtendNode.create(offset, IntegerStamp.getBits(baseAddress.stamp(NodeView.DEFAULT)), NodeView.DEFAULT));
                ValueNode address = b.add(new AddNode(baseAddress, offsetWidened));
                /* Do not dereference the address if CGlobalDataInfo is not a reference */
                ValueNode isSymbolReference = b.add(LoadFieldNode.create(b.getAssumptions(), info, b.getMetaAccess().lookupJavaField(isSymbolReferenceField)));
                LogicNode condition = IntegerEqualsNode.create(isSymbolReference, ConstantNode.forBoolean(false, b.getGraph()), NodeView.DEFAULT);
                ReadNode readValue = b.add(new ReadNode(b.add(OffsetAddressNode.create(address)), NamedLocationIdentity.ANY_LOCATION, baseAddress.stamp(NodeView.DEFAULT), OnHeapMemoryAccess.BarrierType.NONE));
                AbstractBeginNode trueBegin = b.add(new BeginNode());
                FixedWithNextNode predecessor = (FixedWithNextNode) trueBegin.predecessor();
                predecessor.setNext(null);
                AbstractBeginNode falseBegin = b.add(new BeginNode());
                trueBegin.setNext(null);
                IfNode ifNode = b.add(new IfNode(condition, trueBegin, falseBegin, BranchProbabilityNode.NOT_LIKELY_PROFILE));
                falseBegin.setNext(null);
                predecessor.setNext(ifNode);
                EndNode thenEnd = b.add(new EndNode());
                trueBegin.setNext(thenEnd);
                EndNode elseEnd = b.add(new EndNode());
                falseBegin.setNext(elseEnd);
                AbstractMergeNode merge = b.add(new MergeNode());
                merge.addForwardEnd(thenEnd);
                merge.addForwardEnd(elseEnd);
                ValuePhiNode phiNode = new ValuePhiNode(StampFactory.pointer(), merge, new ValueNode[] { address, readValue });
                phiNode.inferStamp();
                b.push(targetMethod.getSignature().getReturnKind(), b.getGraph().addOrUnique(phiNode));
                b.setStateAfter(merge);
            }
            return true;
        }
    });
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) CGlobalDataImpl(com.oracle.svm.core.c.CGlobalDataImpl) RequiredInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.RequiredInvocationPlugin) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) CGlobalDataInfo(com.oracle.svm.core.graal.code.CGlobalDataInfo) CGlobalDataLoadAddressNode(com.oracle.svm.core.graal.nodes.CGlobalDataLoadAddressNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) EndNode(org.graalvm.compiler.nodes.EndNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) BeginNode(org.graalvm.compiler.nodes.BeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) 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