Search in sources :

Example 1 with FixedValueAnchorNode

use of org.graalvm.compiler.nodes.extended.FixedValueAnchorNode in project graal by oracle.

the class DefaultJavaLoweringProvider method finishAllocatedObjects.

public void finishAllocatedObjects(LoweringTool tool, CommitAllocationNode commit, ValueNode[] allocations) {
    StructuredGraph graph = commit.graph();
    for (int objIndex = 0; objIndex < commit.getVirtualObjects().size(); objIndex++) {
        FixedValueAnchorNode anchor = graph.add(new FixedValueAnchorNode(allocations[objIndex]));
        allocations[objIndex] = anchor;
        graph.addBeforeFixed(commit, anchor);
    }
    /*
         * Note that the FrameState that is assigned to these MonitorEnterNodes isn't the correct
         * state. It will be the state from before the allocation occurred instead of a valid state
         * after the locking is performed. In practice this should be fine since these are newly
         * allocated objects. The bytecodes themselves permit allocating an object, doing a
         * monitorenter and then dropping all references to the object which would produce the same
         * state, though that would normally produce an IllegalMonitorStateException. In HotSpot
         * some form of fast path locking should always occur so the FrameState should never
         * actually be used.
         */
    ArrayList<MonitorEnterNode> enters = null;
    for (int objIndex = 0; objIndex < commit.getVirtualObjects().size(); objIndex++) {
        List<MonitorIdNode> locks = commit.getLocks(objIndex);
        if (locks.size() > 1) {
            // Ensure that the lock operations are performed in lock depth order
            ArrayList<MonitorIdNode> newList = new ArrayList<>(locks);
            newList.sort((a, b) -> Integer.compare(a.getLockDepth(), b.getLockDepth()));
            locks = newList;
        }
        int lastDepth = -1;
        for (MonitorIdNode monitorId : locks) {
            assert lastDepth < monitorId.getLockDepth();
            lastDepth = monitorId.getLockDepth();
            MonitorEnterNode enter = graph.add(new MonitorEnterNode(allocations[objIndex], monitorId));
            graph.addBeforeFixed(commit, enter);
            if (enters == null) {
                enters = new ArrayList<>();
            }
            enters.add(enter);
        }
    }
    for (Node usage : commit.usages().snapshot()) {
        if (usage instanceof AllocatedObjectNode) {
            AllocatedObjectNode addObject = (AllocatedObjectNode) usage;
            int index = commit.getVirtualObjects().indexOf(addObject.getVirtualObject());
            addObject.replaceAtUsagesAndDelete(allocations[index]);
        } else {
            assert enters != null;
            commit.replaceAtUsages(InputType.Memory, enters.get(enters.size() - 1));
        }
    }
    if (enters != null) {
        for (MonitorEnterNode enter : enters) {
            enter.lower(tool);
        }
    }
    assert commit.hasNoUsages();
    insertAllocationBarrier(commit, graph);
}
Also used : FixedValueAnchorNode(org.graalvm.compiler.nodes.extended.FixedValueAnchorNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) RawMonitorEnterNode(org.graalvm.compiler.nodes.java.RawMonitorEnterNode) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) RawMonitorEnterNode(org.graalvm.compiler.nodes.java.RawMonitorEnterNode) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) LeftShiftNode(org.graalvm.compiler.nodes.calc.LeftShiftNode) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) UnsafeMemoryStoreNode(org.graalvm.compiler.nodes.extended.UnsafeMemoryStoreNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) IntegerConvertNode(org.graalvm.compiler.nodes.calc.IntegerConvertNode) IntegerEqualsNode(org.graalvm.compiler.nodes.calc.IntegerEqualsNode) AtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IntegerBelowNode(org.graalvm.compiler.nodes.calc.IntegerBelowNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) VerifyHeapNode(org.graalvm.compiler.nodes.debug.VerifyHeapNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) NarrowNode(org.graalvm.compiler.nodes.calc.NarrowNode) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) JavaReadNode(org.graalvm.compiler.nodes.extended.JavaReadNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) BinaryMathIntrinsicNode(org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) PiNode(org.graalvm.compiler.nodes.PiNode) FinalFieldBarrierNode(org.graalvm.compiler.nodes.java.FinalFieldBarrierNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) LogicCompareAndSwapNode(org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode) UnsafeCompareAndSwapNode(org.graalvm.compiler.nodes.java.UnsafeCompareAndSwapNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) InstanceOfDynamicNode(org.graalvm.compiler.nodes.java.InstanceOfDynamicNode) AddNode(org.graalvm.compiler.nodes.calc.AddNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) InstanceOfNode(org.graalvm.compiler.nodes.java.InstanceOfNode) RightShiftNode(org.graalvm.compiler.nodes.calc.RightShiftNode) AccessIndexedNode(org.graalvm.compiler.nodes.java.AccessIndexedNode) ConditionalNode(org.graalvm.compiler.nodes.calc.ConditionalNode) GuardedUnsafeLoadNode(org.graalvm.compiler.nodes.extended.GuardedUnsafeLoadNode) UnsafeMemoryLoadNode(org.graalvm.compiler.nodes.extended.UnsafeMemoryLoadNode) UnpackEndianHalfNode(org.graalvm.compiler.nodes.calc.UnpackEndianHalfNode) UnaryMathIntrinsicNode(org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) SubNode(org.graalvm.compiler.nodes.calc.SubNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) FixedValueAnchorNode(org.graalvm.compiler.nodes.extended.FixedValueAnchorNode) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) MembarNode(org.graalvm.compiler.nodes.extended.MembarNode) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Node(org.graalvm.compiler.graph.Node) UnboxNode(org.graalvm.compiler.nodes.extended.UnboxNode) ArrayList(java.util.ArrayList)

Example 2 with FixedValueAnchorNode

use of org.graalvm.compiler.nodes.extended.FixedValueAnchorNode in project graal by oracle.

the class SubstrateGraphBuilderPlugins method registerKnownIntrinsicsPlugins.

private static void registerKnownIntrinsicsPlugins(InvocationPlugins plugins, boolean analysis) {
    Registration r = new Registration(plugins, KnownIntrinsics.class);
    r.register0("heapBase", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, ReadRegisterFixedNode.forHeapBase());
            return true;
        }
    });
    r.register1("readArrayLength", Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode array) {
            b.addPush(JavaKind.Int, new ArrayLengthNode(array));
            return true;
        }
    });
    r.register1("readHub", Object.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            ValueNode nonNullObject = b.nullCheckedValue(object);
            b.addPush(JavaKind.Object, new LoadHubNode(b.getStampProvider(), nonNullObject));
            return true;
        }
    });
    r.register3("formatObject", Pointer.class, Class.class, boolean.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode memory, ValueNode hub, ValueNode rememberedSet) {
            b.addPush(JavaKind.Object, new FormatObjectNode(memory, hub, rememberedSet));
            return true;
        }
    });
    r.register5("formatArray", Pointer.class, Class.class, int.class, boolean.class, boolean.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode memory, ValueNode hub, ValueNode length, ValueNode rememberedSet, ValueNode unaligned) {
            b.addPush(JavaKind.Object, new FormatArrayNode(memory, hub, length, rememberedSet, unaligned));
            return true;
        }
    });
    r.register2("unsafeCast", Object.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode toTypeNode) {
            /*
                 * We need to make sure that the updated type information does not flow up, because
                 * it can depend on any condition before (and we do not know which condition, so we
                 * cannot anchor at a particular block).
                 */
            ResolvedJavaType toType = typeValue(b.getConstantReflection(), b, targetMethod, toTypeNode, "toType");
            TypeReference toTypeRef = TypeReference.createTrustedWithoutAssumptions(toType);
            b.addPush(JavaKind.Object, new FixedValueAnchorNode(object, StampFactory.object(toTypeRef)));
            return true;
        }
    });
    r.register1("nonNullPointer", Pointer.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object) {
            b.addPush(JavaKind.Object, new PiNode(object, nonZeroWord()));
            return true;
        }
    });
    r.register0("readStackPointer", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadStackPointerNode());
            return true;
        }
    });
    r.register1("writeStackPointer", Pointer.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode value) {
            b.add(new WriteStackPointerNode(value));
            return true;
        }
    });
    r.register0("readInstructionPointer", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadInstructionPointerNode());
            return true;
        }
    });
    r.register0("readCallerStackPointer", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadCallerStackPointerNode());
            return true;
        }
    });
    r.register0("readReturnAddress", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.addPush(JavaKind.Object, new ReadReturnAddressNode());
            return true;
        }
    });
    r.register3("farReturn", Object.class, Pointer.class, CodePointer.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode result, ValueNode sp, ValueNode ip) {
            b.add(new FarReturnNode(result, sp, ip));
            return true;
        }
    });
    r.register0("testDeoptimize", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            b.add(new TestDeoptimizeNode());
            return true;
        }
    });
    r.register0("isDeoptimizationTarget", new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver) {
            if (b.getGraph().method() instanceof SharedMethod) {
                SharedMethod method = (SharedMethod) b.getGraph().method();
                if (method.isDeoptTarget()) {
                    b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
                } else {
                    b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(false));
                }
            } else {
                // In analysis the value is always true.
                b.addPush(JavaKind.Boolean, ConstantNode.forBoolean(true));
            }
            return true;
        }
    });
    r.register2("convertUnknownValue", Object.class, Class.class, new InvocationPlugin() {

        @Override
        public boolean apply(GraphBuilderContext b, ResolvedJavaMethod targetMethod, Receiver receiver, ValueNode object, ValueNode typeNode) {
            ResolvedJavaType type = typeValue(b.getConstantReflection(), b, targetMethod, typeNode, "type");
            TypeReference typeRef = TypeReference.createTrustedWithoutAssumptions(type);
            Stamp stamp = StampFactory.object(typeRef);
            if (analysis) {
                b.addPush(JavaKind.Object, new ConvertUnknownValueNode(object, stamp));
            } else {
                b.addPush(JavaKind.Object, PiNode.create(object, stamp));
            }
            return true;
        }
    });
}
Also used : FixedValueAnchorNode(org.graalvm.compiler.nodes.extended.FixedValueAnchorNode) TestDeoptimizeNode(com.oracle.svm.core.graal.nodes.TestDeoptimizeNode) DynamicPiNode(org.graalvm.compiler.nodes.DynamicPiNode) PiNode(org.graalvm.compiler.nodes.PiNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) FarReturnNode(com.oracle.svm.core.graal.nodes.FarReturnNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ReadStackPointerNode(com.oracle.svm.core.graal.nodes.ReadStackPointerNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) ReadCallerStackPointerNode(com.oracle.svm.core.graal.nodes.ReadCallerStackPointerNode) WriteStackPointerNode(com.oracle.svm.core.graal.nodes.WriteStackPointerNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) IntegerStamp(org.graalvm.compiler.core.common.type.IntegerStamp) Receiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver) ReadInstructionPointerNode(com.oracle.svm.core.graal.nodes.ReadInstructionPointerNode) ReadReturnAddressNode(com.oracle.svm.core.graal.nodes.ReadReturnAddressNode) FormatObjectNode(com.oracle.svm.core.graal.nodes.FormatObjectNode) FormatArrayNode(com.oracle.svm.core.graal.nodes.FormatArrayNode) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) SharedMethod(com.oracle.svm.core.meta.SharedMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

PiNode (org.graalvm.compiler.nodes.PiNode)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 FixedValueAnchorNode (org.graalvm.compiler.nodes.extended.FixedValueAnchorNode)2 LoadHubNode (org.graalvm.compiler.nodes.extended.LoadHubNode)2 ArrayLengthNode (org.graalvm.compiler.nodes.java.ArrayLengthNode)2 ConvertUnknownValueNode (com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode)1 FarReturnNode (com.oracle.svm.core.graal.nodes.FarReturnNode)1 FormatArrayNode (com.oracle.svm.core.graal.nodes.FormatArrayNode)1 FormatObjectNode (com.oracle.svm.core.graal.nodes.FormatObjectNode)1 ReadCallerStackPointerNode (com.oracle.svm.core.graal.nodes.ReadCallerStackPointerNode)1 ReadInstructionPointerNode (com.oracle.svm.core.graal.nodes.ReadInstructionPointerNode)1 ReadReturnAddressNode (com.oracle.svm.core.graal.nodes.ReadReturnAddressNode)1 ReadStackPointerNode (com.oracle.svm.core.graal.nodes.ReadStackPointerNode)1 TestDeoptimizeNode (com.oracle.svm.core.graal.nodes.TestDeoptimizeNode)1 WriteStackPointerNode (com.oracle.svm.core.graal.nodes.WriteStackPointerNode)1 StackValueNode (com.oracle.svm.core.graal.stackvalue.StackValueNode)1 SharedMethod (com.oracle.svm.core.meta.SharedMethod)1 ArrayList (java.util.ArrayList)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1