Search in sources :

Example 16 with ReadNode

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

the class DefaultHotSpotLoweringProvider method lowerLoadMethodNode.

private void lowerLoadMethodNode(LoadMethodNode loadMethodNode) {
    StructuredGraph graph = loadMethodNode.graph();
    HotSpotResolvedJavaMethod method = (HotSpotResolvedJavaMethod) loadMethodNode.getMethod();
    ReadNode metaspaceMethod = createReadVirtualMethod(graph, loadMethodNode.getHub(), method, loadMethodNode.getReceiverType());
    graph.replaceFixed(loadMethodNode, metaspaceMethod);
}
Also used : HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode)

Example 17 with ReadNode

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

the class DefaultHotSpotLoweringProvider method lowerInvoke.

private void lowerInvoke(Invoke invoke, LoweringTool tool, StructuredGraph graph) {
    if (invoke.callTarget() instanceof MethodCallTargetNode) {
        MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget();
        NodeInputList<ValueNode> parameters = callTarget.arguments();
        ValueNode receiver = parameters.size() <= 0 ? null : parameters.get(0);
        if (!callTarget.isStatic() && receiver.stamp(NodeView.DEFAULT) instanceof ObjectStamp && !StampTool.isPointerNonNull(receiver)) {
            ValueNode nonNullReceiver = createNullCheckedValue(receiver, invoke.asNode(), tool);
            parameters.set(0, nonNullReceiver);
            receiver = nonNullReceiver;
        }
        JavaType[] signature = callTarget.targetMethod().getSignature().toParameterTypes(callTarget.isStatic() ? null : callTarget.targetMethod().getDeclaringClass());
        LoweredCallTargetNode loweredCallTarget = null;
        OptionValues options = graph.getOptions();
        if (InlineVTableStubs.getValue(options) && callTarget.invokeKind().isIndirect() && (AlwaysInlineVTableStubs.getValue(options) || invoke.isPolymorphic())) {
            HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
            ResolvedJavaType receiverType = invoke.getReceiverType();
            if (hsMethod.isInVirtualMethodTable(receiverType)) {
                JavaKind wordKind = runtime.getTarget().wordJavaKind;
                ValueNode hub = createReadHub(graph, receiver, tool);
                ReadNode metaspaceMethod = createReadVirtualMethod(graph, hub, hsMethod, receiverType);
                // We use LocationNode.ANY_LOCATION for the reads that access the
                // compiled code entry as HotSpot does not guarantee they are final
                // values.
                int methodCompiledEntryOffset = runtime.getVMConfig().methodCompiledEntryOffset;
                AddressNode address = createOffsetAddress(graph, metaspaceMethod, methodCompiledEntryOffset);
                ReadNode compiledEntry = graph.add(new ReadNode(address, any(), StampFactory.forKind(wordKind), BarrierType.NONE));
                loweredCallTarget = graph.add(new HotSpotIndirectCallTargetNode(metaspaceMethod, compiledEntry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, callTarget.targetMethod(), HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
                graph.addBeforeFixed(invoke.asNode(), metaspaceMethod);
                graph.addAfterFixed(metaspaceMethod, compiledEntry);
            }
        }
        if (loweredCallTarget == null) {
            loweredCallTarget = graph.add(new HotSpotDirectCallTargetNode(parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, callTarget.targetMethod(), HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
        }
        callTarget.replaceAndDelete(loweredCallTarget);
    }
}
Also used : HotSpotDirectCallTargetNode(org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) OptionValues(org.graalvm.compiler.options.OptionValues) HotSpotIndirectCallTargetNode(org.graalvm.compiler.hotspot.nodes.HotSpotIndirectCallTargetNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) GetObjectAddressNode(org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode) ComputeObjectAddressNode(org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 18 with ReadNode

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

the class WriteBarrierAdditionPhase method run.

@SuppressWarnings("try")
@Override
protected void run(StructuredGraph graph) {
    for (Node n : graph.getNodes()) {
        try (DebugCloseable scope = n.graph().withNodeSourcePosition(n)) {
            if (n instanceof ReadNode) {
                addReadNodeBarriers((ReadNode) n, graph);
            } else if (n instanceof WriteNode) {
                addWriteNodeBarriers((WriteNode) n, graph);
            } else if (n instanceof LoweredAtomicReadAndWriteNode) {
                LoweredAtomicReadAndWriteNode loweredAtomicReadAndWriteNode = (LoweredAtomicReadAndWriteNode) n;
                addAtomicReadWriteNodeBarriers(loweredAtomicReadAndWriteNode, graph);
            } else if (n instanceof AbstractCompareAndSwapNode) {
                addCASBarriers((AbstractCompareAndSwapNode) n, graph);
            } else if (n instanceof ArrayRangeWrite) {
                ArrayRangeWrite node = (ArrayRangeWrite) n;
                if (node.writesObjectArray()) {
                    addArrayRangeBarriers(node, graph);
                }
            }
        }
    }
}
Also used : ArrayRangeWrite(org.graalvm.compiler.nodes.extended.ArrayRangeWrite) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) AbstractCompareAndSwapNode(org.graalvm.compiler.nodes.java.AbstractCompareAndSwapNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) Node(org.graalvm.compiler.graph.Node) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) AbstractCompareAndSwapNode(org.graalvm.compiler.nodes.java.AbstractCompareAndSwapNode)

Example 19 with ReadNode

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

the class HotSpotWordOperationPlugin method processHotSpotWordOperation.

protected void processHotSpotWordOperation(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args, HotSpotOperation operation) {
    JavaKind returnKind = method.getSignature().getReturnKind();
    switch(operation.opcode()) {
        case POINTER_EQ:
        case POINTER_NE:
            assert args.length == 2;
            HotspotOpcode opcode = operation.opcode();
            ValueNode left = args[0];
            ValueNode right = args[1];
            assert left.stamp(NodeView.DEFAULT) instanceof MetaspacePointerStamp : left + " " + left.stamp(NodeView.DEFAULT);
            assert right.stamp(NodeView.DEFAULT) instanceof MetaspacePointerStamp : right + " " + right.stamp(NodeView.DEFAULT);
            assert opcode == POINTER_EQ || opcode == POINTER_NE;
            PointerEqualsNode comparison = b.add(new PointerEqualsNode(left, right));
            ValueNode eqValue = b.add(forBoolean(opcode == POINTER_EQ));
            ValueNode neValue = b.add(forBoolean(opcode == POINTER_NE));
            b.addPush(returnKind, ConditionalNode.create(comparison, eqValue, neValue, NodeView.DEFAULT));
            break;
        case IS_NULL:
            assert args.length == 1;
            ValueNode pointer = args[0];
            assert pointer.stamp(NodeView.DEFAULT) instanceof MetaspacePointerStamp;
            LogicNode isNull = b.addWithInputs(IsNullNode.create(pointer));
            b.addPush(returnKind, ConditionalNode.create(isNull, b.add(forBoolean(true)), b.add(forBoolean(false)), NodeView.DEFAULT));
            break;
        case FROM_POINTER:
            assert args.length == 1;
            b.addPush(returnKind, new PointerCastNode(StampFactory.forKind(wordKind), args[0]));
            break;
        case TO_KLASS_POINTER:
            assert args.length == 1;
            b.addPush(returnKind, new PointerCastNode(KlassPointerStamp.klass(), args[0]));
            break;
        case TO_METHOD_POINTER:
            assert args.length == 1;
            b.addPush(returnKind, new PointerCastNode(MethodPointerStamp.method(), args[0]));
            break;
        case READ_KLASS_POINTER:
            assert args.length == 2 || args.length == 3;
            Stamp readStamp = KlassPointerStamp.klass();
            AddressNode address = makeAddress(b, args[0], args[1]);
            LocationIdentity location;
            if (args.length == 2) {
                location = any();
            } else {
                assert args[2].isConstant();
                location = snippetReflection.asObject(LocationIdentity.class, args[2].asJavaConstant());
            }
            ReadNode read = b.add(new ReadNode(address, location, readStamp, BarrierType.NONE));
            b.push(returnKind, read);
            break;
        default:
            throw GraalError.shouldNotReachHere("unknown operation: " + operation.opcode());
    }
}
Also used : HotspotOpcode(org.graalvm.compiler.hotspot.word.HotSpotOperation.HotspotOpcode) MethodPointerStamp(org.graalvm.compiler.hotspot.nodes.type.MethodPointerStamp) MetaspacePointerStamp(org.graalvm.compiler.hotspot.nodes.type.MetaspacePointerStamp) KlassPointerStamp(org.graalvm.compiler.hotspot.nodes.type.KlassPointerStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) MetaspacePointerStamp(org.graalvm.compiler.hotspot.nodes.type.MetaspacePointerStamp) PointerEqualsNode(org.graalvm.compiler.nodes.calc.PointerEqualsNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LocationIdentity(org.graalvm.word.LocationIdentity) LogicNode(org.graalvm.compiler.nodes.LogicNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) PointerCastNode(org.graalvm.compiler.hotspot.word.PointerCastNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 20 with ReadNode

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

the class PushNodesThroughPiTest method test1.

@Ignore
@Test
@SuppressWarnings("try")
public void test1() {
    final String snippet = "test1Snippet";
    DebugContext debug = getDebugContext();
    try (DebugContext.Scope s = debug.scope("PushThroughPi", new DebugDumpScope(snippet))) {
        StructuredGraph graph = compileTestSnippet(snippet);
        for (ReadNode rn : graph.getNodes().filter(ReadNode.class)) {
            OffsetAddressNode address = (OffsetAddressNode) rn.getAddress();
            long disp = address.getOffset().asJavaConstant().asLong();
            ResolvedJavaType receiverType = StampTool.typeOrNull(address.getBase());
            ResolvedJavaField field = receiverType.findInstanceFieldWithOffset(disp, rn.getStackKind());
            assert field != null : "Node " + rn + " tries to access a field which doesn't exists for this type";
            if (field.getName().equals("x")) {
                Assert.assertTrue(address.getBase() instanceof ParameterNode);
            } else {
                Assert.assertTrue(address.getBase().toString(), address.getBase() instanceof PiNode);
            }
        }
        Assert.assertTrue(graph.getNodes().filter(IsNullNode.class).count() == 1);
    } catch (Throwable e) {
        throw debug.handle(e);
    }
}
Also used : DebugDumpScope(org.graalvm.compiler.debug.DebugDumpScope) DebugContext(org.graalvm.compiler.debug.DebugContext) PiNode(org.graalvm.compiler.nodes.PiNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

ReadNode (org.graalvm.compiler.nodes.memory.ReadNode)22 ValueNode (org.graalvm.compiler.nodes.ValueNode)14 AddressNode (org.graalvm.compiler.nodes.memory.address.AddressNode)13 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)11 OffsetAddressNode (org.graalvm.compiler.nodes.memory.address.OffsetAddressNode)10 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)9 Stamp (org.graalvm.compiler.core.common.type.Stamp)9 JavaReadNode (org.graalvm.compiler.nodes.extended.JavaReadNode)8 JavaKind (jdk.vm.ci.meta.JavaKind)7 FloatingReadNode (org.graalvm.compiler.nodes.memory.FloatingReadNode)6 IntegerStamp (org.graalvm.compiler.core.common.type.IntegerStamp)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 GuardingNode (org.graalvm.compiler.nodes.extended.GuardingNode)4 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)3 Node (org.graalvm.compiler.graph.Node)3 ComputeObjectAddressNode (org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode)3 GetObjectAddressNode (org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode)3 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)3 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)3 WriteNode (org.graalvm.compiler.nodes.memory.WriteNode)3