Search in sources :

Example 6 with WriteNode

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

the class DefaultJavaLoweringProvider method lowerJavaWriteNode.

protected void lowerJavaWriteNode(JavaWriteNode write) {
    StructuredGraph graph = write.graph();
    ValueNode value = implicitStoreConvert(graph, write.getWriteKind(), write.value(), write.isCompressible());
    WriteNode memoryWrite = graph.add(new WriteNode(write.getAddress(), write.getLocationIdentity(), value, write.getBarrierType()));
    memoryWrite.setStateAfter(write.stateAfter());
    graph.replaceFixedWithFixed(write, memoryWrite);
    memoryWrite.setGuard(write.getGuard());
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) AtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode)

Example 7 with WriteNode

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

the class DefaultJavaLoweringProvider method lowerStoreIndexedNode.

protected void lowerStoreIndexedNode(StoreIndexedNode storeIndexed, LoweringTool tool) {
    StructuredGraph graph = storeIndexed.graph();
    ValueNode value = storeIndexed.value();
    ValueNode array = storeIndexed.array();
    array = this.createNullCheckedValue(array, storeIndexed, tool);
    GuardingNode boundsCheck = getBoundsCheck(storeIndexed, array, tool);
    JavaKind elementKind = storeIndexed.elementKind();
    LogicNode condition = null;
    if (elementKind == JavaKind.Object && !StampTool.isPointerAlwaysNull(value)) {
        /* Array store check. */
        TypeReference arrayType = StampTool.typeReferenceOrNull(array);
        if (arrayType != null && arrayType.isExact()) {
            ResolvedJavaType elementType = arrayType.getType().getComponentType();
            if (!elementType.isJavaLangObject()) {
                TypeReference typeReference = TypeReference.createTrusted(storeIndexed.graph().getAssumptions(), elementType);
                LogicNode typeTest = graph.addOrUniqueWithInputs(InstanceOfNode.create(typeReference, value));
                condition = LogicNode.or(graph.unique(IsNullNode.create(value)), typeTest, GraalDirectives.UNLIKELY_PROBABILITY);
            }
        } else {
            /*
                 * The guard on the read hub should be the null check of the array that was
                 * introduced earlier.
                 */
            ValueNode arrayClass = createReadHub(graph, array, tool);
            ValueNode componentHub = createReadArrayComponentHub(graph, arrayClass, storeIndexed);
            LogicNode typeTest = graph.unique(InstanceOfDynamicNode.create(graph.getAssumptions(), tool.getConstantReflection(), componentHub, value, false));
            condition = LogicNode.or(graph.unique(IsNullNode.create(value)), typeTest, GraalDirectives.UNLIKELY_PROBABILITY);
        }
    }
    AddressNode address = createArrayIndexAddress(graph, array, elementKind, storeIndexed.index(), boundsCheck);
    WriteNode memoryWrite = graph.add(new WriteNode(address, NamedLocationIdentity.getArrayLocation(elementKind), implicitStoreConvert(graph, elementKind, value), arrayStoreBarrierType(storeIndexed.elementKind())));
    memoryWrite.setGuard(boundsCheck);
    if (condition != null) {
        tool.createGuard(storeIndexed, condition, DeoptimizationReason.ArrayStoreException, DeoptimizationAction.InvalidateReprofile);
    }
    memoryWrite.setStateAfter(storeIndexed.stateAfter());
    graph.replaceFixedWithFixed(storeIndexed, memoryWrite);
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) AtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 8 with WriteNode

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

the class DefaultJavaLoweringProvider method lowerStoreFieldNode.

protected void lowerStoreFieldNode(StoreFieldNode storeField, LoweringTool tool) {
    StructuredGraph graph = storeField.graph();
    ResolvedJavaField field = storeField.field();
    ValueNode object = storeField.isStatic() ? staticFieldBase(graph, field) : storeField.object();
    object = createNullCheckedValue(object, storeField, tool);
    ValueNode value = implicitStoreConvert(graph, getStorageKind(storeField.field()), storeField.value());
    AddressNode address = createFieldAddress(graph, object, field);
    assert address != null;
    WriteNode memoryWrite = graph.add(new WriteNode(address, fieldLocationIdentity(field), value, fieldStoreBarrierType(storeField.field())));
    memoryWrite.setStateAfter(storeField.stateAfter());
    graph.replaceFixedWithFixed(storeField, memoryWrite);
    if (storeField.isVolatile()) {
        MembarNode preMembar = graph.add(new MembarNode(JMM_PRE_VOLATILE_WRITE));
        graph.addBeforeFixed(memoryWrite, preMembar);
        MembarNode postMembar = graph.add(new MembarNode(JMM_POST_VOLATILE_WRITE));
        graph.addAfterFixed(memoryWrite, postMembar);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) MembarNode(org.graalvm.compiler.nodes.extended.MembarNode) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) AtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 9 with WriteNode

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

the class WriteBarrierAdditionTest method testHelper.

@SuppressWarnings("try")
private void testHelper(final String snippetName, final int expectedBarriers) throws Exception, SecurityException {
    ResolvedJavaMethod snippet = getResolvedJavaMethod(snippetName);
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope("WriteBarrierAdditionTest", snippet)) {
        StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO, debug);
        HighTierContext highContext = getDefaultHighTierContext();
        MidTierContext midContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
        new InliningPhase(new InlineEverythingPolicy(), new CanonicalizerPhase()).apply(graph, highContext);
        new CanonicalizerPhase().apply(graph, highContext);
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, highContext);
        new GuardLoweringPhase().apply(graph, midContext);
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, midContext);
        new WriteBarrierAdditionPhase(config).apply(graph);
        debug.dump(DebugContext.BASIC_LEVEL, graph, "After Write Barrier Addition");
        int barriers = 0;
        if (config.useG1GC) {
            barriers = graph.getNodes().filter(G1ReferentFieldReadBarrier.class).count() + graph.getNodes().filter(G1PreWriteBarrier.class).count() + graph.getNodes().filter(G1PostWriteBarrier.class).count();
        } else {
            barriers = graph.getNodes().filter(SerialWriteBarrier.class).count();
        }
        if (expectedBarriers != barriers) {
            Assert.assertEquals(getScheduledGraphString(graph), expectedBarriers, barriers);
        }
        for (WriteNode write : graph.getNodes().filter(WriteNode.class)) {
            if (config.useG1GC) {
                if (write.getBarrierType() != BarrierType.NONE) {
                    Assert.assertEquals(1, write.successors().count());
                    Assert.assertTrue(write.next() instanceof G1PostWriteBarrier);
                    Assert.assertTrue(write.predecessor() instanceof G1PreWriteBarrier);
                }
            } else {
                if (write.getBarrierType() != BarrierType.NONE) {
                    Assert.assertEquals(1, write.successors().count());
                    Assert.assertTrue(write.next() instanceof SerialWriteBarrier);
                }
            }
        }
        for (ReadNode read : graph.getNodes().filter(ReadNode.class)) {
            if (read.getBarrierType() != BarrierType.NONE) {
                Assert.assertTrue(read.getAddress() instanceof OffsetAddressNode);
                JavaConstant constDisp = ((OffsetAddressNode) read.getAddress()).getOffset().asJavaConstant();
                Assert.assertNotNull(constDisp);
                Assert.assertEquals(referentOffset, constDisp.asLong());
                Assert.assertTrue(config.useG1GC);
                Assert.assertEquals(BarrierType.PRECISE, read.getBarrierType());
                Assert.assertTrue(read.next() instanceof G1ReferentFieldReadBarrier);
            }
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : InlineEverythingPolicy(org.graalvm.compiler.phases.common.inlining.policy.InlineEverythingPolicy) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) WriteBarrierAdditionPhase(org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase) G1PreWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier) JavaConstant(jdk.vm.ci.meta.JavaConstant) DebugContext(org.graalvm.compiler.debug.DebugContext) SerialWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier) G1ReferentFieldReadBarrier(org.graalvm.compiler.hotspot.nodes.G1ReferentFieldReadBarrier) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) G1PostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 10 with WriteNode

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

the class WriteBarrierVerificationTest method testPredicate.

@SuppressWarnings("try")
private void testPredicate(final String snippet, final GraphPredicate expectedBarriers, final int... removedBarrierIndices) {
    DebugContext debug = getDebugContext();
    try (DebugCloseable d = debug.disableIntercept();
        DebugContext.Scope s = debug.scope("WriteBarrierVerificationTest", new DebugDumpScope(snippet))) {
        final StructuredGraph graph = parseEager(snippet, AllowAssumptions.YES, debug);
        HighTierContext highTierContext = getDefaultHighTierContext();
        new InliningPhase(new CanonicalizerPhase()).apply(graph, highTierContext);
        MidTierContext midTierContext = new MidTierContext(getProviders(), getTargetProvider(), OptimisticOptimizations.ALL, graph.getProfilingInfo());
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.HIGH_TIER).apply(graph, highTierContext);
        new GuardLoweringPhase().apply(graph, midTierContext);
        new LoopSafepointInsertionPhase().apply(graph);
        new LoweringPhase(new CanonicalizerPhase(), LoweringTool.StandardLoweringStage.MID_TIER).apply(graph, highTierContext);
        new WriteBarrierAdditionPhase(config).apply(graph);
        int barriers = 0;
        // First, the total number of expected barriers is checked.
        if (config.useG1GC) {
            barriers = graph.getNodes().filter(G1PreWriteBarrier.class).count() + graph.getNodes().filter(G1PostWriteBarrier.class).count() + graph.getNodes().filter(G1ArrayRangePreWriteBarrier.class).count() + graph.getNodes().filter(G1ArrayRangePostWriteBarrier.class).count();
            Assert.assertTrue(expectedBarriers.apply(graph) * 2 == barriers);
        } else {
            barriers = graph.getNodes().filter(SerialWriteBarrier.class).count() + graph.getNodes().filter(SerialArrayRangeWriteBarrier.class).count();
            Assert.assertTrue(expectedBarriers.apply(graph) == barriers);
        }
        ResolvedJavaField barrierIndexField = getMetaAccess().lookupJavaField(WriteBarrierVerificationTest.class.getDeclaredField("barrierIndex"));
        LocationIdentity barrierIdentity = new FieldLocationIdentity(barrierIndexField);
        // Iterate over all write nodes and remove barriers according to input indices.
        NodeIteratorClosure<Boolean> closure = new NodeIteratorClosure<Boolean>() {

            @Override
            protected Boolean processNode(FixedNode node, Boolean currentState) {
                if (node instanceof WriteNode) {
                    WriteNode write = (WriteNode) node;
                    LocationIdentity obj = write.getLocationIdentity();
                    if (obj.equals(barrierIdentity)) {
                        /*
                             * A "barrierIndex" variable was found and is checked against the input
                             * barrier array.
                             */
                        if (eliminateBarrier(write.value().asJavaConstant().asInt(), removedBarrierIndices)) {
                            return true;
                        }
                    }
                } else if (node instanceof SerialWriteBarrier || node instanceof G1PostWriteBarrier) {
                    // Remove flagged write barriers.
                    if (currentState) {
                        graph.removeFixed(((FixedWithNextNode) node));
                        return false;
                    }
                }
                return currentState;
            }

            private boolean eliminateBarrier(int index, int[] map) {
                for (int i = 0; i < map.length; i++) {
                    if (map[i] == index) {
                        return true;
                    }
                }
                return false;
            }

            @Override
            protected EconomicMap<LoopExitNode, Boolean> processLoop(LoopBeginNode loop, Boolean initialState) {
                return ReentrantNodeIterator.processLoop(this, loop, initialState).exitStates;
            }

            @Override
            protected Boolean merge(AbstractMergeNode merge, List<Boolean> states) {
                return false;
            }

            @Override
            protected Boolean afterSplit(AbstractBeginNode node, Boolean oldState) {
                return false;
            }
        };
        try (Scope disabled = debug.disable()) {
            ReentrantNodeIterator.apply(closure, graph.start(), false);
            new WriteBarrierVerificationPhase(config).apply(graph);
        } catch (AssertionError error) {
            /*
                 * Catch assertion, test for expected one and re-throw in order to validate unit
                 * test.
                 */
            Assert.assertTrue(error.getMessage().contains("Write barrier must be present"));
            throw error;
        }
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : WriteBarrierVerificationPhase(org.graalvm.compiler.hotspot.phases.WriteBarrierVerificationPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) WriteBarrierAdditionPhase(org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) MidTierContext(org.graalvm.compiler.phases.tiers.MidTierContext) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) Scope(org.graalvm.compiler.debug.DebugContext.Scope) LocationIdentity(org.graalvm.word.LocationIdentity) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) List(java.util.List) NodeIteratorClosure(org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure) SerialArrayRangeWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialArrayRangeWriteBarrier) LoopSafepointInsertionPhase(org.graalvm.compiler.phases.common.LoopSafepointInsertionPhase) G1ArrayRangePostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1ArrayRangePostWriteBarrier) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) G1PreWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier) DebugContext(org.graalvm.compiler.debug.DebugContext) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) SerialWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier) FieldLocationIdentity(org.graalvm.compiler.nodes.FieldLocationIdentity) Scope(org.graalvm.compiler.debug.DebugContext.Scope) DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) HighTierContext(org.graalvm.compiler.phases.tiers.HighTierContext) G1PostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier) InliningPhase(org.graalvm.compiler.phases.common.inlining.InliningPhase) GuardLoweringPhase(org.graalvm.compiler.phases.common.GuardLoweringPhase) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode)

Aggregations

WriteNode (org.graalvm.compiler.nodes.memory.WriteNode)17 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)11 ValueNode (org.graalvm.compiler.nodes.ValueNode)10 LoweredAtomicReadAndWriteNode (org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode)8 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)8 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)7 JavaWriteNode (org.graalvm.compiler.nodes.extended.JavaWriteNode)6 AtomicReadAndWriteNode (org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode)6 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)5 JavaKind (jdk.vm.ci.meta.JavaKind)4 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)4 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)3 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)3 Node (org.graalvm.compiler.graph.Node)3 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 ComputeObjectAddressNode (org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode)2 G1PostWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier)2 G1PreWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier)2 GetObjectAddressNode (org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode)2