Search in sources :

Example 1 with AddressNode

use of org.graalvm.compiler.nodes.memory.address.AddressNode 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 2 with AddressNode

use of org.graalvm.compiler.nodes.memory.address.AddressNode 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 3 with AddressNode

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

the class AddressLoweringPhase method run.

@Override
protected void run(StructuredGraph graph) {
    lowering.preProcess(graph);
    for (Node node : graph.getNodes()) {
        AddressNode lowered;
        if (node instanceof OffsetAddressNode) {
            OffsetAddressNode address = (OffsetAddressNode) node;
            lowered = lowering.lower(address.getBase(), address.getOffset());
            lowering.postProcess(lowered);
        } else {
            continue;
        }
        node.replaceAtUsages(lowered);
        GraphUtil.killWithUnusedFloatingInputs(node);
    }
}
Also used : OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)

Example 4 with AddressNode

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

the class CompareAndSetVMThreadLocalNode method lower.

@Override
public void lower(LoweringTool tool) {
    assert threadLocalInfo.offset >= 0;
    ConstantNode offset = ConstantNode.forIntegerKind(FrameAccess.getWordKind(), threadLocalInfo.offset, holder.graph());
    AddressNode address = graph().unique(new OffsetAddressNode(holder, offset));
    LogicCompareAndSwapNode atomic = graph().add(new LogicCompareAndSwapNode(address, threadLocalInfo.locationIdentity, expect, update, barrierType));
    atomic.setStateAfter(stateAfter());
    graph().replaceFixedWithFixed(this, atomic);
}
Also used : LogicCompareAndSwapNode(org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)

Example 5 with AddressNode

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

the class StoreVMThreadLocalNode method lower.

@Override
public void lower(LoweringTool tool) {
    assert threadLocalInfo.offset >= 0;
    ConstantNode offset = ConstantNode.forIntegerKind(FrameAccess.getWordKind(), threadLocalInfo.offset, graph());
    AddressNode address = graph().unique(new OffsetAddressNode(holder, offset));
    AbstractWriteNode write;
    if (SubstrateOptions.MultiThreaded.getValue()) {
        write = new CInterfaceWriteNode(address, threadLocalInfo.locationIdentity, value, barrierType, threadLocalInfo.name);
    } else {
        write = new JavaWriteNode(threadLocalInfo.storageKind, address, threadLocalInfo.locationIdentity, value, barrierType, true);
    }
    write = graph().add(write);
    write.setStateAfter(stateAfter());
    graph().replaceFixedWithFixed(this, write);
    if (!SubstrateOptions.MultiThreaded.getValue()) {
        tool.getLowerer().lower(write, tool);
    }
}
Also used : ConstantNode(org.graalvm.compiler.nodes.ConstantNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AbstractWriteNode(org.graalvm.compiler.nodes.memory.AbstractWriteNode) CInterfaceWriteNode(com.oracle.svm.core.graal.nodes.CInterfaceWriteNode)

Aggregations

AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)43 ValueNode (org.graalvm.compiler.nodes.ValueNode)35 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)25 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)16 JavaKind (jdk.vm.ci.meta.JavaKind)13 ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)12 Stamp (org.graalvm.compiler.core.common.type.Stamp)9 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)9 ComputeObjectAddressNode (org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode)8 GetObjectAddressNode (org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode)8 AMD64AddressNode (org.graalvm.compiler.core.amd64.AMD64AddressNode)7 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)7 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)7 JavaReadNode (org.graalvm.compiler.nodes.extended.JavaReadNode)7 WriteNode (org.graalvm.compiler.nodes.memory.WriteNode)7 Test (org.junit.Test)7 LeftShiftNode (org.graalvm.compiler.nodes.calc.LeftShiftNode)6 JavaWriteNode (org.graalvm.compiler.nodes.extended.JavaWriteNode)6 AtomicReadAndWriteNode (org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode)6 LoweredAtomicReadAndWriteNode (org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode)6