Search in sources :

Example 1 with G1PreWriteBarrier

use of org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier in project graal by oracle.

the class WriteBarrierAdditionPhase method addG1PreWriteBarrier.

protected static void addG1PreWriteBarrier(FixedAccessNode node, AddressNode address, ValueNode value, boolean doLoad, boolean nullCheck, StructuredGraph graph) {
    G1PreWriteBarrier preBarrier = graph.add(new G1PreWriteBarrier(address, value, doLoad, nullCheck));
    preBarrier.setStateBefore(node.stateBefore());
    node.setNullCheck(false);
    node.setStateBefore(null);
    graph.addBeforeFixed(node, preBarrier);
}
Also used : G1PreWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier)

Example 2 with G1PreWriteBarrier

use of org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier 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 3 with G1PreWriteBarrier

use of org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier 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

G1PreWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PreWriteBarrier)3 JavaConstant (jdk.vm.ci.meta.JavaConstant)2 G1PostWriteBarrier (org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier)2 G1ReferentFieldReadBarrier (org.graalvm.compiler.hotspot.nodes.G1ReferentFieldReadBarrier)2 SerialWriteBarrier (org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 DebugContext (org.graalvm.compiler.debug.DebugContext)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 SerialArrayRangeWriteBarrier (org.graalvm.compiler.hotspot.nodes.SerialArrayRangeWriteBarrier)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 WriteBarrierAdditionPhase (org.graalvm.compiler.hotspot.phases.WriteBarrierAdditionPhase)1 ClassGetHubNode (org.graalvm.compiler.hotspot.replacements.ClassGetHubNode)1 HubGetClassNode (org.graalvm.compiler.hotspot.replacements.HubGetClassNode)1