Search in sources :

Example 1 with LoadFieldNode

use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.

the class ObjectCloneNode method getLoweredSnippetGraph.

@Override
@SuppressWarnings("try")
protected StructuredGraph getLoweredSnippetGraph(LoweringTool tool) {
    ResolvedJavaType type = StampTool.typeOrNull(getObject());
    if (type != null) {
        if (type.isArray()) {
            Method method = ObjectCloneSnippets.arrayCloneMethods.get(type.getComponentType().getJavaKind());
            if (method != null) {
                final ResolvedJavaMethod snippetMethod = tool.getMetaAccess().lookupJavaMethod(method);
                final Replacements replacements = tool.getReplacements();
                StructuredGraph snippetGraph = null;
                DebugContext debug = getDebug();
                try (DebugContext.Scope s = debug.scope("ArrayCloneSnippet", snippetMethod)) {
                    snippetGraph = replacements.getSnippet(snippetMethod, null, graph().trackNodeSourcePosition(), this.getNodeSourcePosition());
                } catch (Throwable e) {
                    throw debug.handle(e);
                }
                assert snippetGraph != null : "ObjectCloneSnippets should be installed";
                assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
                return lowerReplacement((StructuredGraph) snippetGraph.copy(getDebug()), tool);
            }
            assert false : "unhandled array type " + type.getComponentType().getJavaKind();
        } else {
            Assumptions assumptions = graph().getAssumptions();
            type = getConcreteType(getObject().stamp(NodeView.DEFAULT));
            if (type != null) {
                StructuredGraph newGraph = new StructuredGraph.Builder(graph().getOptions(), graph().getDebug(), AllowAssumptions.ifNonNull(assumptions)).build();
                ParameterNode param = newGraph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(getObject().stamp(NodeView.DEFAULT))));
                NewInstanceNode newInstance = newGraph.add(new NewInstanceNode(type, true));
                newGraph.addAfterFixed(newGraph.start(), newInstance);
                ReturnNode returnNode = newGraph.add(new ReturnNode(newInstance));
                newGraph.addAfterFixed(newInstance, returnNode);
                for (ResolvedJavaField field : type.getInstanceFields(true)) {
                    LoadFieldNode load = newGraph.add(LoadFieldNode.create(newGraph.getAssumptions(), param, field));
                    newGraph.addBeforeFixed(returnNode, load);
                    newGraph.addBeforeFixed(returnNode, newGraph.add(new StoreFieldNode(newInstance, field, load)));
                }
                assert getConcreteType(stamp(NodeView.DEFAULT)) != null;
                return lowerReplacement(newGraph, tool);
            }
        }
    }
    assert getConcreteType(stamp(NodeView.DEFAULT)) == null;
    return null;
}
Also used : StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Replacements(org.graalvm.compiler.nodes.spi.Replacements) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) Method(java.lang.reflect.Method) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DebugContext(org.graalvm.compiler.debug.DebugContext) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AllowAssumptions(org.graalvm.compiler.nodes.StructuredGraph.AllowAssumptions) Assumptions(jdk.vm.ci.meta.Assumptions) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with LoadFieldNode

use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.

the class BasicObjectCloneNode method virtualize.

@Override
public void virtualize(VirtualizerTool tool) {
    ValueNode originalAlias = tool.getAlias(getObject());
    if (originalAlias instanceof VirtualObjectNode) {
        VirtualObjectNode originalVirtual = (VirtualObjectNode) originalAlias;
        if (originalVirtual.type().isCloneableWithAllocation()) {
            ValueNode[] newEntryState = new ValueNode[originalVirtual.entryCount()];
            for (int i = 0; i < newEntryState.length; i++) {
                newEntryState[i] = tool.getEntry(originalVirtual, i);
            }
            VirtualObjectNode newVirtual = originalVirtual.duplicate();
            tool.createVirtualObject(newVirtual, newEntryState, Collections.<MonitorIdNode>emptyList(), false);
            tool.replaceWithVirtual(newVirtual);
        }
    } else {
        ResolvedJavaType type = getConcreteType(originalAlias.stamp(NodeView.DEFAULT));
        if (type != null && !type.isArray()) {
            VirtualInstanceNode newVirtual = createVirtualInstanceNode(type, true);
            ResolvedJavaField[] fields = newVirtual.getFields();
            ValueNode[] state = new ValueNode[fields.length];
            final LoadFieldNode[] loads = new LoadFieldNode[fields.length];
            for (int i = 0; i < fields.length; i++) {
                state[i] = loads[i] = genLoadFieldNode(graph().getAssumptions(), originalAlias, fields[i]);
                tool.addNode(loads[i]);
            }
            tool.createVirtualObject(newVirtual, state, Collections.<MonitorIdNode>emptyList(), false);
            tool.replaceWithVirtual(newVirtual);
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField)

Example 3 with LoadFieldNode

use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.

the class SimplifyingGraphDecoder method canonicalizeFixedNode.

/**
 * Canonicalizes the provided node, which was originally a {@link FixedNode} but can already be
 * canonicalized (and therefore be a non-fixed node).
 *
 * @param methodScope The current method.
 * @param node The node to be canonicalized.
 */
protected Node canonicalizeFixedNode(MethodScope methodScope, Node node) {
    if (node instanceof LoadFieldNode) {
        LoadFieldNode loadFieldNode = (LoadFieldNode) node;
        return loadFieldNode.canonical(canonicalizerTool);
    } else if (node instanceof FixedGuardNode) {
        FixedGuardNode guard = (FixedGuardNode) node;
        if (guard.getCondition() instanceof LogicConstantNode) {
            LogicConstantNode condition = (LogicConstantNode) guard.getCondition();
            if (condition.getValue() == guard.isNegated()) {
                DeoptimizeNode deopt = new DeoptimizeNode(guard.getAction(), guard.getReason(), guard.getSpeculation());
                if (guard.stateBefore() != null) {
                    deopt.setStateBefore(guard.stateBefore());
                }
                return deopt;
            } else {
                return null;
            }
        }
        return node;
    } else if (node instanceof IfNode) {
        IfNode ifNode = (IfNode) node;
        if (ifNode.condition() instanceof LogicNegationNode) {
            ifNode.eliminateNegation();
        }
        if (ifNode.condition() instanceof LogicConstantNode) {
            boolean condition = ((LogicConstantNode) ifNode.condition()).getValue();
            AbstractBeginNode survivingSuccessor = ifNode.getSuccessor(condition);
            AbstractBeginNode deadSuccessor = ifNode.getSuccessor(!condition);
            graph.removeSplit(ifNode, survivingSuccessor);
            assert deadSuccessor.next() == null : "must not be parsed yet";
            deadSuccessor.safeDelete();
        }
        return node;
    } else if (node instanceof LoadIndexedNode) {
        LoadIndexedNode loadIndexedNode = (LoadIndexedNode) node;
        return loadIndexedNode.canonical(canonicalizerTool);
    } else if (node instanceof ArrayLengthNode) {
        ArrayLengthNode arrayLengthNode = (ArrayLengthNode) node;
        return arrayLengthNode.canonical(canonicalizerTool);
    } else if (node instanceof IntegerSwitchNode && ((IntegerSwitchNode) node).value().isConstant()) {
        IntegerSwitchNode switchNode = (IntegerSwitchNode) node;
        int value = switchNode.value().asJavaConstant().asInt();
        AbstractBeginNode survivingSuccessor = switchNode.successorAtKey(value);
        List<Node> allSuccessors = switchNode.successors().snapshot();
        graph.removeSplit(switchNode, survivingSuccessor);
        for (Node successor : allSuccessors) {
            if (successor != survivingSuccessor) {
                assert ((AbstractBeginNode) successor).next() == null : "must not be parsed yet";
                successor.safeDelete();
            }
        }
        return node;
    } else if (node instanceof Canonicalizable) {
        return ((Canonicalizable) node).canonical(canonicalizerTool);
    } else {
        return node;
    }
}
Also used : IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) Node(org.graalvm.compiler.graph.Node) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) Canonicalizable(org.graalvm.compiler.graph.spi.Canonicalizable) List(java.util.List) ArrayLengthNode(org.graalvm.compiler.nodes.java.ArrayLengthNode) IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode)

Example 4 with LoadFieldNode

use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.

the class MethodTypeFlowBuilder method registerUsedElements.

public static void registerUsedElements(BigBang bb, StructuredGraph graph, MethodTypeFlow methodFlow) {
    for (Node n : graph.getNodes()) {
        if (n instanceof InstanceOfNode) {
            InstanceOfNode node = (InstanceOfNode) n;
            AnalysisType type = (AnalysisType) node.type().getType();
            type.registerAsInTypeCheck();
        } else if (n instanceof NewInstanceNode) {
            NewInstanceNode node = (NewInstanceNode) n;
            AnalysisType type = (AnalysisType) node.instanceClass();
            type.registerAsAllocated(node);
        } else if (n instanceof NewArrayNode) {
            NewArrayNode node = (NewArrayNode) n;
            AnalysisType type = ((AnalysisType) node.elementType()).getArrayClass();
            type.registerAsAllocated(node);
        } else if (n instanceof NewMultiArrayNode) {
            NewMultiArrayNode node = (NewMultiArrayNode) n;
            AnalysisType type = ((AnalysisType) node.type());
            for (int i = 0; i < node.dimensionCount(); i++) {
                type.registerAsAllocated(node);
                type = type.getComponentType();
            }
        } else if (n instanceof BoxNode) {
            BoxNode node = (BoxNode) n;
            AnalysisType type = (AnalysisType) StampTool.typeOrNull(node);
            type.registerAsAllocated(node);
        } else if (n instanceof LoadFieldNode) {
            LoadFieldNode node = (LoadFieldNode) n;
            AnalysisField field = (AnalysisField) node.field();
            field.registerAsRead(methodFlow);
        } else if (n instanceof StoreFieldNode) {
            StoreFieldNode node = (StoreFieldNode) n;
            AnalysisField field = (AnalysisField) node.field();
            field.registerAsWritten(methodFlow);
        } else if (n instanceof StoreIndexedNode) {
            StoreIndexedNode node = (StoreIndexedNode) n;
            AnalysisType arrayType = (AnalysisType) StampTool.typeOrNull(node.array());
            if (arrayType != null) {
                assert arrayType.isArray();
                arrayType.getComponentType().registerAsInTypeCheck();
            }
        } else if (n instanceof BytecodeExceptionNode) {
            BytecodeExceptionNode node = (BytecodeExceptionNode) n;
            AnalysisType type = bb.getMetaAccess().lookupJavaType(node.getExceptionClass());
            type.registerAsInHeap();
        } else if (n instanceof ConstantNode) {
            ConstantNode cn = (ConstantNode) n;
            if (cn.hasUsages() && cn.asJavaConstant().getJavaKind() == JavaKind.Object && cn.asJavaConstant().isNonNull()) {
                assert StampTool.isExactType(cn);
                AnalysisType type = (AnalysisType) StampTool.typeOrNull(cn);
                type.registerAsInHeap();
            }
        } else if (n instanceof ForeignCallNode) {
            ForeignCallNode node = (ForeignCallNode) n;
            registerForeignCall(bb, node.getDescriptor());
        } else if (n instanceof UnaryMathIntrinsicNode) {
            UnaryMathIntrinsicNode node = (UnaryMathIntrinsicNode) n;
            registerForeignCall(bb, node.getOperation().foreignCallDescriptor);
        } else if (n instanceof BinaryMathIntrinsicNode) {
            BinaryMathIntrinsicNode node = (BinaryMathIntrinsicNode) n;
            registerForeignCall(bb, node.getOperation().foreignCallDescriptor);
        }
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) DynamicNewInstanceNode(org.graalvm.compiler.nodes.java.DynamicNewInstanceNode) DynamicNewArrayNode(org.graalvm.compiler.nodes.java.DynamicNewArrayNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) UnaryMathIntrinsicNode(org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode) RawLoadNode(org.graalvm.compiler.nodes.extended.RawLoadNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) WordCastNode(org.graalvm.compiler.word.WordCastNode) DynamicNewArrayNode(org.graalvm.compiler.nodes.java.DynamicNewArrayNode) ObjectEqualsNode(org.graalvm.compiler.nodes.calc.ObjectEqualsNode) BasicObjectCloneNode(org.graalvm.compiler.replacements.nodes.BasicObjectCloneNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) AtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode) ConvertUnknownValueNode(com.oracle.graal.pointsto.nodes.ConvertUnknownValueNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AnalysisUnsafePartitionLoadNode(com.oracle.graal.pointsto.nodes.AnalysisUnsafePartitionLoadNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) AnalysisArraysCopyOfNode(com.oracle.graal.pointsto.nodes.AnalysisArraysCopyOfNode) DynamicNewInstanceNode(org.graalvm.compiler.nodes.java.DynamicNewInstanceNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) NewMultiArrayNode(org.graalvm.compiler.nodes.java.NewMultiArrayNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) BinaryMathIntrinsicNode(org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode) IfNode(org.graalvm.compiler.nodes.IfNode) RawStoreNode(org.graalvm.compiler.nodes.extended.RawStoreNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) UnsafeCompareAndSwapNode(org.graalvm.compiler.nodes.java.UnsafeCompareAndSwapNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InstanceOfNode(org.graalvm.compiler.nodes.java.InstanceOfNode) BasicArrayCopyNode(org.graalvm.compiler.replacements.nodes.BasicArrayCopyNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) UnaryMathIntrinsicNode(org.graalvm.compiler.replacements.nodes.UnaryMathIntrinsicNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) GetClassNode(org.graalvm.compiler.nodes.extended.GetClassNode) BytecodeExceptionNode(org.graalvm.compiler.nodes.extended.BytecodeExceptionNode) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) AnalysisUnsafePartitionStoreNode(com.oracle.graal.pointsto.nodes.AnalysisUnsafePartitionStoreNode) BytecodeExceptionNode(org.graalvm.compiler.nodes.extended.BytecodeExceptionNode) BoxNode(org.graalvm.compiler.nodes.extended.BoxNode) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) BinaryMathIntrinsicNode(org.graalvm.compiler.replacements.nodes.BinaryMathIntrinsicNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) NewMultiArrayNode(org.graalvm.compiler.nodes.java.NewMultiArrayNode) InstanceOfNode(org.graalvm.compiler.nodes.java.InstanceOfNode)

Example 5 with LoadFieldNode

use of org.graalvm.compiler.nodes.java.LoadFieldNode in project graal by oracle.

the class UnsafeEATest method testMergedDouble.

@Test
public void testMergedDouble() {
    testEscapeAnalysis("testMergedDoubleSnippet", null, false);
    Assert.assertEquals(1, returnNodes.size());
    Assert.assertTrue(returnNodes.get(0).result() instanceof ValuePhiNode);
    PhiNode phi = (PhiNode) returnNodes.get(0).result();
    Assert.assertTrue(phi.valueAt(0) instanceof LoadFieldNode);
    Assert.assertTrue(phi.valueAt(1) instanceof LoadFieldNode);
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) Test(org.junit.Test)

Aggregations

LoadFieldNode (org.graalvm.compiler.nodes.java.LoadFieldNode)19 ValueNode (org.graalvm.compiler.nodes.ValueNode)9 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 StoreFieldNode (org.graalvm.compiler.nodes.java.StoreFieldNode)7 Node (org.graalvm.compiler.graph.Node)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)4 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)3 ResolvedJavaField (jdk.vm.ci.meta.ResolvedJavaField)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 FieldLocationIdentity (org.graalvm.compiler.nodes.FieldLocationIdentity)3 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)3 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)3 PhiNode (org.graalvm.compiler.nodes.PhiNode)3 RawLoadNode (org.graalvm.compiler.nodes.extended.RawLoadNode)3 RawStoreNode (org.graalvm.compiler.nodes.extended.RawStoreNode)3 LoadIndexedNode (org.graalvm.compiler.nodes.java.LoadIndexedNode)3 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)3 NewInstanceNode (org.graalvm.compiler.nodes.java.NewInstanceNode)3 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)2