Search in sources :

Example 1 with AtomicReadAndWriteNode

use of org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode 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

JavaKind (jdk.vm.ci.meta.JavaKind)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)1 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)1 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)1 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)1 AtomicReadAndAddNode (org.graalvm.compiler.nodes.java.AtomicReadAndAddNode)1 AtomicReadAndWriteNode (org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode)1 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)1 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)1 UnsafeGetPlugin (org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.UnsafeGetPlugin)1 UnsafePutPlugin (org.graalvm.compiler.replacements.StandardGraphBuilderPlugins.UnsafePutPlugin)1 Unsafe (sun.misc.Unsafe)1