Search in sources :

Example 1 with DynamicNewInstanceNode

use of org.graalvm.compiler.nodes.java.DynamicNewInstanceNode in project graal by oracle.

the class StandardGraphBuilderPlugins method registerUnsafePlugins.

private static void registerUnsafePlugins(InvocationPlugins plugins, BytecodeProvider bytecodeProvider) {
    Registration r;
    if (Java8OrEarlier) {
        r = new Registration(plugins, Unsafe.class);
    } else {
        r = new Registration(plugins, "jdk.internal.misc.Unsafe", bytecodeProvider);
    }
    for (JavaKind kind : JavaKind.values()) {
        if ((kind.isPrimitive() && kind != JavaKind.Void) || kind == JavaKind.Object) {
            Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
            String kindName = kind.name();
            String getName = "get" + kindName;
            String putName = "put" + kindName;
            // Object-based accesses
            r.register3(getName, Receiver.class, Object.class, long.class, new UnsafeGetPlugin(kind, false));
            r.register4(putName, Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, false));
            // Volatile object-based accesses
            r.register3(getName + "Volatile", Receiver.class, Object.class, long.class, new UnsafeGetPlugin(kind, true));
            r.register4(putName + "Volatile", Receiver.class, Object.class, long.class, javaClass, new UnsafePutPlugin(kind, true));
            // Ordered object-based accesses
            if (Java8OrEarlier) {
                if (kind == JavaKind.Int || kind == JavaKind.Long || kind == JavaKind.Object) {
                    r.register4("putOrdered" + kindName, Receiver.class, Object.class, long.class, javaClass, UnsafePutPlugin.putOrdered(kind));
                }
            } else {
                r.register4("put" + kindName + "Release", Receiver.class, Object.class, long.class, javaClass, UnsafePutPlugin.putOrdered(kind));
            }
            if (kind != JavaKind.Boolean && kind != JavaKind.Object) {
                // Raw accesses to memory addresses
                r.register2(getName, Receiver.class, long.class, new UnsafeGetPlugin(kind, false));
                r.register3(putName, Receiver.class, long.class, kind.toJavaClass(), new UnsafePutPlugin(kind, false));
            }
        }
    }
    // Accesses to native memory addresses.
    r.register2("getAddress", Receiver.class, long.class, new UnsafeGetPlugin(JavaKind.Long, false));
    r.register3("putAddress", Receiver.class, long.class, long.class, new UnsafePutPlugin(JavaKind.Long, false));
    for (JavaKind kind : new JavaKind[] { JavaKind.Int, JavaKind.Long, JavaKind.Object }) {
        Class<?> javaClass = kind == JavaKind.Object ? Object.class : kind.toJavaClass();
        String casName;
        if (Java8OrEarlier) {
            casName = "compareAndSwap";
        } else {
            casName = "compareAndSet";
        }
        r.register5(casName + kind.name(), Receiver.class, Object.class, long.class, javaClass, javaClass, new InvocationPlugin() {

            @Override
            public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode object, ValueNode offset, ValueNode expected, ValueNode x) {
                // Emits a null-check for the otherwise unused receiver
                unsafe.get();
                b.addPush(JavaKind.Int, new UnsafeCompareAndSwapNode(object, offset, expected, x, kind, LocationIdentity.any()));
                b.getGraph().markUnsafeAccess();
                return true;
            }
        });
    }
    r.register2("allocateInstance", Receiver.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver unsafe, ValueNode clazz) {
            // Emits a null-check for the otherwise unused receiver
            unsafe.get();
            b.addPush(JavaKind.Object, new DynamicNewInstanceNode(b.nullCheckedValue(clazz, DeoptimizationAction.None), true));
            return true;
        }
    });
    r.register1("loadFence", Receiver.class, new UnsafeFencePlugin(LOAD_LOAD | LOAD_STORE));
    r.register1("storeFence", Receiver.class, new UnsafeFencePlugin(STORE_STORE | LOAD_STORE));
    r.register1("fullFence", Receiver.class, new UnsafeFencePlugin(LOAD_LOAD | STORE_STORE | LOAD_STORE | STORE_LOAD));
}
Also used : UnsafeCompareAndSwapNode(org.graalvm.compiler.nodes.java.UnsafeCompareAndSwapNode) DynamicNewInstanceNode(org.graalvm.compiler.nodes.java.DynamicNewInstanceNode) Unsafe(sun.misc.Unsafe) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) 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) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 2 with DynamicNewInstanceNode

use of org.graalvm.compiler.nodes.java.DynamicNewInstanceNode in project graal by oracle.

the class DefaultHotSpotLoweringProvider method lower.

@Override
public void lower(Node n, LoweringTool tool) {
    StructuredGraph graph = (StructuredGraph) n.graph();
    if (n instanceof Invoke) {
        lowerInvoke((Invoke) n, tool, graph);
    } else if (n instanceof LoadMethodNode) {
        lowerLoadMethodNode((LoadMethodNode) n);
    } else if (n instanceof GetClassNode) {
        lowerGetClassNode((GetClassNode) n, tool, graph);
    } else if (n instanceof StoreHubNode) {
        lowerStoreHubNode((StoreHubNode) n, graph);
    } else if (n instanceof OSRStartNode) {
        lowerOSRStartNode((OSRStartNode) n);
    } else if (n instanceof BytecodeExceptionNode) {
        lowerBytecodeExceptionNode((BytecodeExceptionNode) n);
    } else if (n instanceof InstanceOfNode) {
        InstanceOfNode instanceOfNode = (InstanceOfNode) n;
        if (graph.getGuardsStage().areDeoptsFixed()) {
            instanceofSnippets.lower(instanceOfNode, tool);
        } else {
            if (instanceOfNode.allowsNull()) {
                ValueNode object = instanceOfNode.getValue();
                LogicNode newTypeCheck = graph.addOrUniqueWithInputs(InstanceOfNode.create(instanceOfNode.type(), object, instanceOfNode.profile(), instanceOfNode.getAnchor()));
                LogicNode newNode = LogicNode.or(graph.unique(IsNullNode.create(object)), newTypeCheck, GraalDirectives.UNLIKELY_PROBABILITY);
                instanceOfNode.replaceAndDelete(newNode);
            }
        }
    } else if (n instanceof InstanceOfDynamicNode) {
        InstanceOfDynamicNode instanceOfDynamicNode = (InstanceOfDynamicNode) n;
        if (graph.getGuardsStage().areDeoptsFixed()) {
            instanceofSnippets.lower(instanceOfDynamicNode, tool);
        } else {
            ValueNode mirror = instanceOfDynamicNode.getMirrorOrHub();
            if (mirror.stamp(NodeView.DEFAULT).getStackKind() == JavaKind.Object) {
                ClassGetHubNode classGetHub = graph.unique(new ClassGetHubNode(mirror));
                instanceOfDynamicNode.setMirror(classGetHub);
            }
            if (instanceOfDynamicNode.allowsNull()) {
                ValueNode object = instanceOfDynamicNode.getObject();
                LogicNode newTypeCheck = graph.addOrUniqueWithInputs(InstanceOfDynamicNode.create(graph.getAssumptions(), tool.getConstantReflection(), instanceOfDynamicNode.getMirrorOrHub(), object, false));
                LogicNode newNode = LogicNode.or(graph.unique(IsNullNode.create(object)), newTypeCheck, GraalDirectives.UNLIKELY_PROBABILITY);
                instanceOfDynamicNode.replaceAndDelete(newNode);
            }
        }
    } else if (n instanceof ClassIsAssignableFromNode) {
        if (graph.getGuardsStage().areDeoptsFixed()) {
            instanceofSnippets.lower((ClassIsAssignableFromNode) n, tool);
        }
    } else if (n instanceof NewInstanceNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            newObjectSnippets.lower((NewInstanceNode) n, registers, tool);
        }
    } else if (n instanceof DynamicNewInstanceNode) {
        DynamicNewInstanceNode newInstanceNode = (DynamicNewInstanceNode) n;
        if (newInstanceNode.getClassClass() == null) {
            JavaConstant classClassMirror = constantReflection.forObject(Class.class);
            ConstantNode classClass = ConstantNode.forConstant(classClassMirror, tool.getMetaAccess(), graph);
            newInstanceNode.setClassClass(classClass);
        }
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            newObjectSnippets.lower(newInstanceNode, registers, tool);
        }
    } else if (n instanceof NewArrayNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            newObjectSnippets.lower((NewArrayNode) n, registers, tool);
        }
    } else if (n instanceof DynamicNewArrayNode) {
        DynamicNewArrayNode dynamicNewArrayNode = (DynamicNewArrayNode) n;
        if (dynamicNewArrayNode.getVoidClass() == null) {
            JavaConstant voidClassMirror = constantReflection.forObject(void.class);
            ConstantNode voidClass = ConstantNode.forConstant(voidClassMirror, tool.getMetaAccess(), graph);
            dynamicNewArrayNode.setVoidClass(voidClass);
        }
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            newObjectSnippets.lower(dynamicNewArrayNode, registers, tool);
        }
    } else if (n instanceof VerifyHeapNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            newObjectSnippets.lower((VerifyHeapNode) n, registers, tool);
        }
    } else if (n instanceof RawMonitorEnterNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            monitorSnippets.lower((RawMonitorEnterNode) n, registers, tool);
        }
    } else if (n instanceof MonitorExitNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            monitorSnippets.lower((MonitorExitNode) n, registers, tool);
        }
    } else if (n instanceof ArrayCopyNode) {
        arraycopySnippets.lower((ArrayCopyNode) n, tool);
    } else if (n instanceof ArrayCopyWithSlowPathNode) {
        arraycopySnippets.lower((ArrayCopyWithSlowPathNode) n, tool);
    } else if (n instanceof G1PreWriteBarrier) {
        writeBarrierSnippets.lower((G1PreWriteBarrier) n, registers, tool);
    } else if (n instanceof G1PostWriteBarrier) {
        writeBarrierSnippets.lower((G1PostWriteBarrier) n, registers, tool);
    } else if (n instanceof G1ReferentFieldReadBarrier) {
        writeBarrierSnippets.lower((G1ReferentFieldReadBarrier) n, registers, tool);
    } else if (n instanceof SerialWriteBarrier) {
        writeBarrierSnippets.lower((SerialWriteBarrier) n, tool);
    } else if (n instanceof SerialArrayRangeWriteBarrier) {
        writeBarrierSnippets.lower((SerialArrayRangeWriteBarrier) n, tool);
    } else if (n instanceof G1ArrayRangePreWriteBarrier) {
        writeBarrierSnippets.lower((G1ArrayRangePreWriteBarrier) n, registers, tool);
    } else if (n instanceof G1ArrayRangePostWriteBarrier) {
        writeBarrierSnippets.lower((G1ArrayRangePostWriteBarrier) n, registers, tool);
    } else if (n instanceof NewMultiArrayNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            newObjectSnippets.lower((NewMultiArrayNode) n, tool);
        }
    } else if (n instanceof LoadExceptionObjectNode) {
        exceptionObjectSnippets.lower((LoadExceptionObjectNode) n, registers, tool);
    } else if (n instanceof AssertionNode) {
        assertionSnippets.lower((AssertionNode) n, tool);
    } else if (n instanceof StringToBytesNode) {
        if (graph.getGuardsStage().areDeoptsFixed()) {
            stringToBytesSnippets.lower((StringToBytesNode) n, tool);
        }
    } else if (n instanceof IntegerDivRemNode) {
    // Nothing to do for division nodes. The HotSpot signal handler catches divisions by
    // zero and the MIN_VALUE / -1 cases.
    } else if (n instanceof AbstractDeoptimizeNode || n instanceof UnwindNode || n instanceof RemNode || n instanceof SafepointNode) {
    /* No lowering, we generate LIR directly for these nodes. */
    } else if (n instanceof ClassGetHubNode) {
        lowerClassGetHubNode((ClassGetHubNode) n, tool);
    } else if (n instanceof HubGetClassNode) {
        lowerHubGetClassNode((HubGetClassNode) n, tool);
    } else if (n instanceof KlassLayoutHelperNode) {
        lowerKlassLayoutHelperNode((KlassLayoutHelperNode) n, tool);
    } else if (n instanceof ComputeObjectAddressNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            lowerComputeObjectAddressNode((ComputeObjectAddressNode) n);
        }
    } else if (n instanceof IdentityHashCodeNode) {
        hashCodeSnippets.lower((IdentityHashCodeNode) n, tool);
    } else if (n instanceof ResolveDynamicConstantNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            resolveConstantSnippets.lower((ResolveDynamicConstantNode) n, tool);
        }
    } else if (n instanceof ResolveConstantNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            resolveConstantSnippets.lower((ResolveConstantNode) n, tool);
        }
    } else if (n instanceof ResolveMethodAndLoadCountersNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            resolveConstantSnippets.lower((ResolveMethodAndLoadCountersNode) n, tool);
        }
    } else if (n instanceof InitializeKlassNode) {
        if (graph.getGuardsStage().areFrameStatesAtDeopts()) {
            resolveConstantSnippets.lower((InitializeKlassNode) n, tool);
        }
    } else if (n instanceof ProfileNode) {
        profileSnippets.lower((ProfileNode) n, tool);
    } else {
        super.lower(n, tool);
    }
}
Also used : ClassIsAssignableFromNode(org.graalvm.compiler.nodes.java.ClassIsAssignableFromNode) SafepointNode(org.graalvm.compiler.nodes.SafepointNode) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode) BytecodeExceptionNode(org.graalvm.compiler.nodes.extended.BytecodeExceptionNode) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) KlassLayoutHelperNode(org.graalvm.compiler.hotspot.replacements.KlassLayoutHelperNode) ComputeObjectAddressNode(org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) IntegerDivRemNode(org.graalvm.compiler.nodes.calc.IntegerDivRemNode) RemNode(org.graalvm.compiler.nodes.calc.RemNode) DynamicNewArrayNode(org.graalvm.compiler.nodes.java.DynamicNewArrayNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode) GetClassNode(org.graalvm.compiler.nodes.extended.GetClassNode) SerialWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier) LoadMethodNode(org.graalvm.compiler.nodes.extended.LoadMethodNode) AbstractDeoptimizeNode(org.graalvm.compiler.nodes.AbstractDeoptimizeNode) InstanceOfDynamicNode(org.graalvm.compiler.nodes.java.InstanceOfDynamicNode) OSRStartNode(org.graalvm.compiler.nodes.extended.OSRStartNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) G1PostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier) InstanceOfNode(org.graalvm.compiler.nodes.java.InstanceOfNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) DynamicNewInstanceNode(org.graalvm.compiler.nodes.java.DynamicNewInstanceNode) StoreHubNode(org.graalvm.compiler.nodes.extended.StoreHubNode) G1ArrayRangePreWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1ArrayRangePreWriteBarrier) JavaConstant(jdk.vm.ci.meta.JavaConstant) Invoke(org.graalvm.compiler.nodes.Invoke) AssertionNode(org.graalvm.compiler.replacements.nodes.AssertionNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ProfileNode(org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode) StringToBytesNode(org.graalvm.compiler.nodes.debug.StringToBytesNode) ClassGetHubNode(org.graalvm.compiler.hotspot.replacements.ClassGetHubNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) SerialArrayRangeWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialArrayRangeWriteBarrier) IntegerDivRemNode(org.graalvm.compiler.nodes.calc.IntegerDivRemNode) ArrayCopyNode(org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopyNode) G1ArrayRangePostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1ArrayRangePostWriteBarrier) DynamicNewInstanceNode(org.graalvm.compiler.nodes.java.DynamicNewInstanceNode) G1PreWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier) RawMonitorEnterNode(org.graalvm.compiler.nodes.java.RawMonitorEnterNode) G1ReferentFieldReadBarrier(org.graalvm.compiler.hotspot.nodes.G1ReferentFieldReadBarrier) VerifyHeapNode(org.graalvm.compiler.nodes.debug.VerifyHeapNode) LoadExceptionObjectNode(org.graalvm.compiler.nodes.java.LoadExceptionObjectNode) ArrayCopyWithSlowPathNode(org.graalvm.compiler.hotspot.replacements.arraycopy.ArrayCopyWithSlowPathNode) IdentityHashCodeNode(org.graalvm.compiler.hotspot.replacements.IdentityHashCodeNode) NewMultiArrayNode(org.graalvm.compiler.nodes.java.NewMultiArrayNode) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) DynamicNewArrayNode(org.graalvm.compiler.nodes.java.DynamicNewArrayNode)

Aggregations

ValueNode (org.graalvm.compiler.nodes.ValueNode)2 DynamicNewInstanceNode (org.graalvm.compiler.nodes.java.DynamicNewInstanceNode)2 JavaConstant (jdk.vm.ci.meta.JavaConstant)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ComputeObjectAddressNode (org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode)1 G1ArrayRangePostWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1ArrayRangePostWriteBarrier)1 G1ArrayRangePreWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1ArrayRangePreWriteBarrier)1 G1PostWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier)1 G1PreWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier)1 G1ReferentFieldReadBarrier (org.graalvm.compiler.hotspot.nodes.G1ReferentFieldReadBarrier)1 SerialArrayRangeWriteBarrier (org.graalvm.compiler.hotspot.nodes.SerialArrayRangeWriteBarrier)1 SerialWriteBarrier (org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier)1 InitializeKlassNode (org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode)1 ResolveConstantNode (org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode)1 ResolveDynamicConstantNode (org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode)1 ResolveMethodAndLoadCountersNode (org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode)1 ProfileNode (org.graalvm.compiler.hotspot.nodes.profiling.ProfileNode)1 ClassGetHubNode (org.graalvm.compiler.hotspot.replacements.ClassGetHubNode)1 HubGetClassNode (org.graalvm.compiler.hotspot.replacements.HubGetClassNode)1