Search in sources :

Example 26 with OffsetAddressNode

use of org.graalvm.compiler.nodes.memory.address.OffsetAddressNode in project graal by oracle.

the class PEGraphDecoderTest method registerPlugins.

private static void registerPlugins(InvocationPlugins plugins) {
    Registration r = new Registration(plugins, PEGraphDecoderTest.class);
    r.register2("readInt", Object.class, long.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unused, ValueNode obj, ValueNode offset) {
            AddressNode address = b.add(new OffsetAddressNode(obj, offset));
            ReadNode read = b.addPush(JavaKind.Int, new ReadNode(address, LocationIdentity.any(), StampFactory.forKind(JavaKind.Int), BarrierType.NONE));
            read.setGuard(AbstractBeginNode.prevBegin(read));
            return true;
        }
    });
}
Also used : OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 27 with OffsetAddressNode

use of org.graalvm.compiler.nodes.memory.address.OffsetAddressNode in project graal by oracle.

the class PointerTest method assertWrite.

private void assertWrite(StructuredGraph graph, boolean indexConvert, LocationIdentity locationIdentity) {
    WordCastNode cast = (WordCastNode) graph.start().next();
    JavaWriteNode write = (JavaWriteNode) cast.next();
    Assert.assertEquals(graph.getParameter(2), write.value());
    Assert.assertEquals(BytecodeFrame.AFTER_BCI, write.stateAfter().bci);
    OffsetAddressNode address = (OffsetAddressNode) write.getAddress();
    Assert.assertEquals(cast, address.getBase());
    Assert.assertEquals(graph.getParameter(0), cast.getInput());
    Assert.assertEquals(target.wordJavaKind, cast.stamp(NodeView.DEFAULT).getStackKind());
    Assert.assertEquals(locationIdentity, write.getLocationIdentity());
    if (indexConvert) {
        SignExtendNode convert = (SignExtendNode) address.getOffset();
        Assert.assertEquals(convert.getInputBits(), 32);
        Assert.assertEquals(convert.getResultBits(), 64);
        Assert.assertEquals(graph.getParameter(1), convert.getValue());
    } else {
        Assert.assertEquals(graph.getParameter(1), address.getOffset());
    }
    ReturnNode ret = (ReturnNode) write.next();
    Assert.assertEquals(null, ret.result());
}
Also used : ReturnNode(org.graalvm.compiler.nodes.ReturnNode) WordCastNode(org.graalvm.compiler.word.WordCastNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode)

Example 28 with OffsetAddressNode

use of org.graalvm.compiler.nodes.memory.address.OffsetAddressNode in project graal by oracle.

the class AMD64GraphBuilderPlugins method registerUnsafePlugins.

private static void registerUnsafePlugins(InvocationPlugins plugins, BytecodeProvider replacementsBytecodeProvider) {
    Registration r;
    if (Java8OrEarlier) {
        r = new Registration(plugins, Unsafe.class);
    } else {
        r = new Registration(plugins, "jdk.internal.misc.Unsafe", replacementsBytecodeProvider);
    }
    for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long, JavaKind.Object }) {
        Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
        r.register4("getAndSet" + kind.name(), Receiver.class, Object.class, long.class, javaClass, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode value) {
                // Emits a null-check for the otherwise unused receiver
                unsafe.get();
                b.addPush(kind, new AtomicReadAndWriteNode(object, offset, value, kind, LocationIdentity.any()));
                b.getGraph().markUnsafeAccess();
                return true;
            }
        });
        if (kind != JavaKind.Object) {
            r.register4("getAndAdd" + kind.name(), Receiver.class, Object.class, long.class, javaClass, new InvocationPlugin() {

                @Override
                public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode delta) {
                    // Emits a null-check for the otherwise unused receiver
                    unsafe.get();
                    AddressNode address = b.add(new OffsetAddressNode(object, offset));
                    b.addPush(kind, new AtomicReadAndAddNode(address, delta, LocationIdentity.any()));
                    b.getGraph().markUnsafeAccess();
                    return true;
                }
            });
        }
    }
    for (JavaKind kind : new JavaKind[] { JavaKind.Char, JavaKind.Short, JavaKind.Int, JavaKind.Long }) {
        Class<?> javaClass = kind.toJavaClass();
        r.registerOptional3("get" + kind.name() + "Unaligned", Receiver.class, Object.class, long.class, new UnsafeGetPlugin(kind, false));
        r.registerOptional4("put" + kind.name() + "Unaligned", Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, false));
    }
}
Also used : Unsafe(sun.misc.Unsafe) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) UnsafePutPlugin(org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.UnsafePutPlugin) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) AtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind) AtomicReadAndAddNode(org.graalvm.compiler.nodes.java.AtomicReadAndAddNode) UnsafeGetPlugin(org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.UnsafeGetPlugin)

Aggregations

OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)28 ValueNode (org.graalvm.compiler.nodes.ValueNode)18 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)15 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 SignExtendNode (org.graalvm.compiler.nodes.calc.SignExtendNode)7 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)5 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)5 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)5 JavaKind (jdk.vm.ci.meta.JavaKind)4 Stamp (org.graalvm.compiler.core.common.type.Stamp)4 AddNode (org.graalvm.compiler.nodes.calc.AddNode)4 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)3 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)3 Node (org.graalvm.compiler.graph.Node)3 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)3 LeftShiftNode (org.graalvm.compiler.nodes.calc.LeftShiftNode)3 JavaReadNode (org.graalvm.compiler.nodes.extended.JavaReadNode)3 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)3 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)3 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)3