Search in sources :

Example 1 with FloatingReadNode

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

the class ConditionAnchoringTest method test.

public void test(String name, int ids) {
    StructuredGraph graph = parseEager(name, AllowAssumptions.YES);
    NodeIterable<RawLoadNode> unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
    assertThat(unsafeNodes, hasCount(1));
    // lower unsafe load
    PhaseContext context = new PhaseContext(getProviders());
    LoweringPhase lowering = new LoweringPhase(new CanonicalizerPhase(), StandardLoweringStage.HIGH_TIER);
    lowering.apply(graph, context);
    unsafeNodes = graph.getNodes().filter(RawLoadNode.class);
    NodeIterable<ConditionAnchorNode> conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
    NodeIterable<ReadNode> reads = graph.getNodes().filter(ReadNode.class);
    assertThat(unsafeNodes, isEmpty());
    assertThat(conditionAnchors, hasCount(1));
    // 2 * ids id reads, 1 'field' access
    assertThat(reads, hasCount(2 * ids + 1));
    // float reads and canonicalize to give a chance to conditions to GVN
    FloatingReadPhase floatingReadPhase = new FloatingReadPhase();
    floatingReadPhase.apply(graph);
    CanonicalizerPhase canonicalizerPhase = new CanonicalizerPhase();
    canonicalizerPhase.apply(graph, context);
    NodeIterable<FloatingReadNode> floatingReads = graph.getNodes().filter(FloatingReadNode.class);
    // 1 id read, 1 'field' access
    assertThat(floatingReads, hasCount(ids + 1));
    new ConditionalEliminationPhase(false).apply(graph, context);
    floatingReads = graph.getNodes().filter(FloatingReadNode.class).filter(n -> ((FloatingReadNode) n).getLocationIdentity() instanceof ObjectLocationIdentity);
    conditionAnchors = graph.getNodes().filter(ConditionAnchorNode.class);
    assertThat(floatingReads, hasCount(1));
    assertThat(conditionAnchors, isEmpty());
    FloatingReadNode readNode = floatingReads.first();
    assertThat(readNode.getGuard(), instanceOf(BeginNode.class));
    assertThat(readNode.getGuard().asNode().predecessor(), instanceOf(IfNode.class));
}
Also used : RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) GraphBuilderConfiguration(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderConfiguration) Unsafe(sun.misc.Unsafe) IsInstanceOf.instanceOf(org.hamcrest.core.IsInstanceOf.instanceOf) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) TruffleGraphBuilderPlugins(org.graalvm.compiler.truffle.compiler.substitutions.TruffleGraphBuilderPlugins) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) NodeIterableIsEmpty.isEmpty(org.graalvm.compiler.graph.test.matchers.NodeIterableIsEmpty.isEmpty) GraalCompilerTest(org.graalvm.compiler.core.test.GraalCompilerTest) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) Assert.assertThat(org.junit.Assert.assertThat) InlineInfo.createStandardInlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo.createStandardInlineInfo) JavaKind(jdk.vm.ci.meta.JavaKind) ObjectLocationIdentity(org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity) BeginNode(org.graalvm.compiler.nodes.BeginNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) IfNode(org.graalvm.compiler.nodes.IfNode) Test(org.junit.Test) Registration(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration) ValueNode(org.graalvm.compiler.nodes.ValueNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) NodeIterableCount.hasCount(org.graalvm.compiler.graph.test.matchers.NodeIterableCount.hasCount) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) StandardLoweringStage(org.graalvm.compiler.nodes.spi.LoweringTool.StandardLoweringStage) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ConditionAnchorNode(org.graalvm.compiler.nodes.ConditionAnchorNode) LoweringPhase(org.graalvm.compiler.phases.common.LoweringPhase) ObjectLocationIdentity(org.graalvm.compiler.truffle.compiler.nodes.ObjectLocationIdentity) IfNode(org.graalvm.compiler.nodes.IfNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) FloatingReadPhase(org.graalvm.compiler.phases.common.FloatingReadPhase) PhaseContext(org.graalvm.compiler.phases.tiers.PhaseContext) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) BeginNode(org.graalvm.compiler.nodes.BeginNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ConditionalEliminationPhase(org.graalvm.compiler.phases.common.ConditionalEliminationPhase) CanonicalizerPhase(org.graalvm.compiler.phases.common.CanonicalizerPhase) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode)

Example 2 with FloatingReadNode

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

the class LoadJavaMirrorWithKlassPhase method getClassConstantReplacement.

private ValueNode getClassConstantReplacement(StructuredGraph graph, PhaseContext context, JavaConstant constant) {
    if (constant instanceof HotSpotObjectConstant) {
        ConstantReflectionProvider constantReflection = context.getConstantReflection();
        ResolvedJavaType type = constantReflection.asJavaType(constant);
        if (type != null) {
            MetaAccessProvider metaAccess = context.getMetaAccess();
            Stamp stamp = StampFactory.objectNonNull(TypeReference.createExactTrusted(metaAccess.lookupJavaType(Class.class)));
            if (type instanceof HotSpotResolvedObjectType) {
                ConstantNode klass = ConstantNode.forConstant(KlassPointerStamp.klassNonNull(), ((HotSpotResolvedObjectType) type).klass(), metaAccess, graph);
                ValueNode getClass = graph.unique(new HubGetClassNode(metaAccess, klass));
                if (((HotSpotObjectConstant) constant).isCompressed()) {
                    return HotSpotCompressionNode.compress(getClass, oopEncoding);
                } else {
                    return getClass;
                }
            } else {
                /*
                     * Primitive classes are more difficult since they don't have a corresponding
                     * Klass* so get them from Class.TYPE for the java box type.
                     */
                HotSpotResolvedPrimitiveType primitive = (HotSpotResolvedPrimitiveType) type;
                ResolvedJavaType boxingClass = metaAccess.lookupJavaType(primitive.getJavaKind().toBoxedJavaClass());
                ConstantNode clazz = ConstantNode.forConstant(context.getConstantReflection().asJavaClass(boxingClass), metaAccess, graph);
                HotSpotResolvedJavaField[] a = (HotSpotResolvedJavaField[]) boxingClass.getStaticFields();
                HotSpotResolvedJavaField typeField = null;
                for (HotSpotResolvedJavaField f : a) {
                    if (f.getName().equals("TYPE")) {
                        typeField = f;
                        break;
                    }
                }
                if (typeField == null) {
                    throw new GraalError("Can't find TYPE field in class");
                }
                if (oopEncoding != null) {
                    stamp = HotSpotNarrowOopStamp.compressed((AbstractObjectStamp) stamp, oopEncoding);
                }
                AddressNode address = graph.unique(new OffsetAddressNode(clazz, ConstantNode.forLong(typeField.offset(), graph)));
                ValueNode read = graph.unique(new FloatingReadNode(address, FINAL_LOCATION, null, stamp));
                if (oopEncoding == null || ((HotSpotObjectConstant) constant).isCompressed()) {
                    return read;
                } else {
                    return HotSpotCompressionNode.uncompress(read, oopEncoding);
                }
            }
        }
    }
    return null;
}
Also used : KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotNarrowOopStamp(org.graalvm.compiler.hotspot.nodes.type.HotSpotNarrowOopStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) HubGetClassNode(org.graalvm.compiler.hotspot.replacements.HubGetClassNode) HotSpotResolvedPrimitiveType(jdk.vm.ci.hotspot.HotSpotResolvedPrimitiveType) AbstractObjectStamp(org.graalvm.compiler.core.common.type.AbstractObjectStamp) HotSpotResolvedJavaField(jdk.vm.ci.hotspot.HotSpotResolvedJavaField) HotSpotObjectConstant(jdk.vm.ci.hotspot.HotSpotObjectConstant) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) GraalError(org.graalvm.compiler.debug.GraalError) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) HotSpotResolvedObjectType(jdk.vm.ci.hotspot.HotSpotResolvedObjectType) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider)

Example 3 with FloatingReadNode

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

the class AddressLoweringByUsePhase method run.

@Override
protected void run(StructuredGraph graph) {
    // first replace address nodes hanging off known usages
    for (Node node : graph.getNodes()) {
        AddressNode address;
        AddressNode lowered;
        if (node instanceof ReadNode) {
            ReadNode readNode = (ReadNode) node;
            Stamp stamp = readNode.stamp(NodeView.DEFAULT);
            address = readNode.getAddress();
            lowered = lowering.lower(readNode, stamp, address);
        } else if (node instanceof JavaReadNode) {
            JavaReadNode javaReadNode = (JavaReadNode) node;
            Stamp stamp = javaReadNode.stamp(NodeView.DEFAULT);
            address = javaReadNode.getAddress();
            lowered = lowering.lower(javaReadNode, stamp, address);
        } else if (node instanceof FloatingReadNode) {
            FloatingReadNode floatingReadNode = (FloatingReadNode) node;
            Stamp stamp = floatingReadNode.stamp(NodeView.DEFAULT);
            address = floatingReadNode.getAddress();
            lowered = lowering.lower(floatingReadNode, stamp, address);
        } else if (node instanceof AbstractWriteNode) {
            AbstractWriteNode abstractWriteNode = (AbstractWriteNode) node;
            Stamp stamp = abstractWriteNode.value().stamp(NodeView.DEFAULT);
            address = abstractWriteNode.getAddress();
            lowered = lowering.lower(abstractWriteNode, stamp, address);
        } else if (node instanceof PrefetchAllocateNode) {
            PrefetchAllocateNode prefetchAllocateNode = (PrefetchAllocateNode) node;
            Stamp stamp = StampFactory.forKind(JavaKind.Object);
            address = (AddressNode) prefetchAllocateNode.inputs().first();
            lowered = lowering.lower(prefetchAllocateNode, stamp, address);
        } else {
            continue;
        }
        // in which case we want to use it not delete it!
        if (lowered != address) {
            // replace original with lowered at this usage only
            // n.b. lowered is added unique so repeat lowerings will elide
            node.replaceFirstInput(address, lowered);
            // if that was the last reference we can kill the old (dead) node
            if (address.hasNoUsages()) {
                GraphUtil.killWithUnusedFloatingInputs(address);
            }
        }
    }
    // now replace any remaining unlowered address nodes
    for (Node node : graph.getNodes()) {
        AddressNode lowered;
        if (node instanceof OffsetAddressNode) {
            AddressNode address = (AddressNode) node;
            lowered = lowering.lower(address);
        } else {
            continue;
        }
        // will always be a new AddresNode
        node.replaceAtUsages(lowered);
        GraphUtil.killWithUnusedFloatingInputs(node);
    }
}
Also used : JavaReadNode(org.graalvm.compiler.nodes.extended.JavaReadNode) Stamp(org.graalvm.compiler.core.common.type.Stamp) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AbstractWriteNode(org.graalvm.compiler.nodes.memory.AbstractWriteNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) PrefetchAllocateNode(org.graalvm.compiler.nodes.PrefetchAllocateNode) Node(org.graalvm.compiler.graph.Node) JavaReadNode(org.graalvm.compiler.nodes.extended.JavaReadNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) JavaReadNode(org.graalvm.compiler.nodes.extended.JavaReadNode) AbstractWriteNode(org.graalvm.compiler.nodes.memory.AbstractWriteNode) PrefetchAllocateNode(org.graalvm.compiler.nodes.PrefetchAllocateNode)

Example 4 with FloatingReadNode

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

the class DefaultHotSpotLoweringProvider method createReadHub.

@Override
protected ValueNode createReadHub(StructuredGraph graph, ValueNode object, LoweringTool tool) {
    if (tool.getLoweringStage() != LoweringTool.StandardLoweringStage.LOW_TIER) {
        return graph.unique(new LoadHubNode(tool.getStampProvider(), object));
    }
    assert !object.isConstant() || object.isNullConstant();
    KlassPointerStamp hubStamp = KlassPointerStamp.klassNonNull();
    if (runtime.getVMConfig().useCompressedClassPointers) {
        hubStamp = hubStamp.compressed(runtime.getVMConfig().getKlassEncoding());
    }
    AddressNode address = createOffsetAddress(graph, object, runtime.getVMConfig().hubOffset);
    LocationIdentity hubLocation = runtime.getVMConfig().useCompressedClassPointers ? COMPRESSED_HUB_LOCATION : HUB_LOCATION;
    FloatingReadNode memoryRead = graph.unique(new FloatingReadNode(address, hubLocation, null, hubStamp, null, BarrierType.NONE));
    if (runtime.getVMConfig().useCompressedClassPointers) {
        return HotSpotCompressionNode.uncompress(memoryRead, runtime.getVMConfig().getKlassEncoding());
    } else {
        return memoryRead;
    }
}
Also used : LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) GetObjectAddressNode(org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode) ComputeObjectAddressNode(org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LocationIdentity(org.graalvm.word.LocationIdentity)

Example 5 with FloatingReadNode

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

the class MemoryScheduleTest method assertReadBeforeAllWritesInStartBlock.

private static void assertReadBeforeAllWritesInStartBlock(ScheduleResult schedule) {
    boolean writeNodeFound = false;
    boolean readNodeFound = false;
    for (Node node : schedule.nodesFor(schedule.getCFG().getStartBlock())) {
        if (node instanceof FloatingReadNode) {
            assertTrue(!writeNodeFound);
            readNodeFound = true;
        } else if (node instanceof WriteNode) {
            writeNodeFound = true;
        }
    }
    assertTrue(readNodeFound);
}
Also used : WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) StartNode(org.graalvm.compiler.nodes.StartNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) Node(org.graalvm.compiler.graph.Node) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode)

Aggregations

FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)16 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)9 Node (org.graalvm.compiler.graph.Node)6 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)6 ComputeObjectAddressNode (org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode)4 GetObjectAddressNode (org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode)4 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)4 WriteNode (org.graalvm.compiler.nodes.memory.WriteNode)4 CanonicalizerPhase (org.graalvm.compiler.phases.common.CanonicalizerPhase)3 FloatingReadPhase (org.graalvm.compiler.phases.common.FloatingReadPhase)3 LoweringPhase (org.graalvm.compiler.phases.common.LoweringPhase)3 PhaseContext (org.graalvm.compiler.phases.tiers.PhaseContext)3 Stamp (org.graalvm.compiler.core.common.type.Stamp)2 DebugContext (org.graalvm.compiler.debug.DebugContext)2 DebugDumpScope (org.graalvm.compiler.debug.DebugDumpScope)2 KlassPointerStamp (org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp)2 StartNode (org.graalvm.compiler.nodes.StartNode)2 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)2 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)2