Search in sources :

Example 21 with VirtualObjectNode

use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.

the class PartialEscapeClosure method processNodeInputs.

/**
 * This replaces all inputs that point to virtual or materialized values with the actual value,
 * materializing if necessary. Also takes care of frame states, adding the necessary
 * {@link VirtualObjectState}.
 */
private void processNodeInputs(ValueNode node, FixedNode insertBefore, BlockT state, GraphEffectList effects) {
    VirtualUtil.trace(node.getOptions(), debug, "processing nodewithstate: %s", node);
    for (Node input : node.inputs()) {
        if (input instanceof ValueNode) {
            ValueNode alias = getAlias((ValueNode) input);
            if (alias instanceof VirtualObjectNode) {
                int id = ((VirtualObjectNode) alias).getObjectId();
                ensureMaterialized(state, id, insertBefore, effects, COUNTER_MATERIALIZATIONS_UNHANDLED);
                effects.replaceFirstInput(node, input, state.getObjectState(id).getMaterializedValue());
                VirtualUtil.trace(node.getOptions(), debug, "replacing input %s at %s", input, node);
            }
        }
    }
    if (node instanceof NodeWithState) {
        processNodeWithState((NodeWithState) node, state, effects);
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) AllocatedObjectNode(org.graalvm.compiler.nodes.virtual.AllocatedObjectNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) NodeWithState(org.graalvm.compiler.nodes.spi.NodeWithState)

Example 22 with VirtualObjectNode

use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.

the class PartialEscapeClosure method collectReferencedVirtualObjects.

private void collectReferencedVirtualObjects(BlockT state, EconomicSet<VirtualObjectNode> virtual) {
    Iterator<VirtualObjectNode> iterator = virtual.iterator();
    while (iterator.hasNext()) {
        VirtualObjectNode object = iterator.next();
        int id = object.getObjectId();
        if (id != -1) {
            ObjectState objState = state.getObjectStateOptional(id);
            if (objState != null && objState.isVirtual()) {
                for (ValueNode entry : objState.getEntries()) {
                    if (entry instanceof VirtualObjectNode) {
                        VirtualObjectNode entryVirtual = (VirtualObjectNode) entry;
                        if (!virtual.contains(entryVirtual)) {
                            virtual.add(entryVirtual);
                        }
                    }
                }
            }
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) VirtualObjectState(org.graalvm.compiler.virtual.nodes.VirtualObjectState) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 23 with VirtualObjectNode

use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.

the class VirtualizerToolImpl method createVirtualObject.

@Override
public void createVirtualObject(VirtualObjectNode virtualObject, ValueNode[] entryState, List<MonitorIdNode> locks, boolean ensureVirtualized) {
    VirtualUtil.trace(options, debug, "{{%s}} ", current);
    if (!virtualObject.isAlive()) {
        effects.addFloatingNode(virtualObject, "newVirtualObject");
    }
    for (int i = 0; i < entryState.length; i++) {
        ValueNode entry = entryState[i];
        entryState[i] = entry instanceof VirtualObjectNode ? entry : closure.getAliasAndResolve(state, entry);
    }
    int id = virtualObject.getObjectId();
    if (id == -1) {
        id = closure.virtualObjects.size();
        closure.virtualObjects.add(virtualObject);
        virtualObject.setObjectId(id);
    }
    state.addObject(id, new ObjectState(entryState, locks, ensureVirtualized));
    closure.addVirtualAlias(virtualObject, virtualObject);
    PartialEscapeClosure.COUNTER_ALLOCATION_REMOVED.increment(debug);
    effects.addVirtualizationDelta(1);
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode)

Example 24 with VirtualObjectNode

use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.

the class LoopFragment method computeNodes.

protected static void computeNodes(NodeBitMap nodes, Graph graph, Iterable<AbstractBeginNode> blocks, Iterable<AbstractBeginNode> earlyExits) {
    for (AbstractBeginNode b : blocks) {
        if (b.isDeleted()) {
            continue;
        }
        for (Node n : b.getBlockNodes()) {
            if (n instanceof Invoke) {
                nodes.mark(((Invoke) n).callTarget());
            }
            if (n instanceof NodeWithState) {
                NodeWithState withState = (NodeWithState) n;
                withState.states().forEach(state -> state.applyToVirtual(node -> nodes.mark(node)));
            }
            if (n instanceof AbstractMergeNode) {
                // if a merge is in the loop, all of its phis are also in the loop
                for (PhiNode phi : ((AbstractMergeNode) n).phis()) {
                    nodes.mark(phi);
                }
            }
            nodes.mark(n);
        }
    }
    for (AbstractBeginNode earlyExit : earlyExits) {
        if (earlyExit.isDeleted()) {
            continue;
        }
        nodes.mark(earlyExit);
        if (earlyExit instanceof LoopExitNode) {
            LoopExitNode loopExit = (LoopExitNode) earlyExit;
            FrameState stateAfter = loopExit.stateAfter();
            if (stateAfter != null) {
                stateAfter.applyToVirtual(node -> nodes.mark(node));
            }
            for (ProxyNode proxy : loopExit.proxies()) {
                nodes.mark(proxy);
            }
        }
    }
    final NodeBitMap nonLoopNodes = graph.createNodeBitMap();
    Deque<WorkListEntry> worklist = new ArrayDeque<>();
    for (AbstractBeginNode b : blocks) {
        if (b.isDeleted()) {
            continue;
        }
        for (Node n : b.getBlockNodes()) {
            if (n instanceof CommitAllocationNode) {
                for (VirtualObjectNode obj : ((CommitAllocationNode) n).getVirtualObjects()) {
                    markFloating(worklist, obj, nodes, nonLoopNodes);
                }
            }
            if (n instanceof MonitorEnterNode) {
                markFloating(worklist, ((MonitorEnterNode) n).getMonitorId(), nodes, nonLoopNodes);
            }
            if (n instanceof AbstractMergeNode) {
                /*
                     * Since we already marked all phi nodes as being in the loop to break cycles,
                     * we also have to iterate over their usages here.
                     */
                for (PhiNode phi : ((AbstractMergeNode) n).phis()) {
                    for (Node usage : phi.usages()) {
                        markFloating(worklist, usage, nodes, nonLoopNodes);
                    }
                }
            }
            for (Node usage : n.usages()) {
                markFloating(worklist, usage, nodes, nonLoopNodes);
            }
        }
    }
}
Also used : GuardNode(org.graalvm.compiler.nodes.GuardNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) GuardProxyNode(org.graalvm.compiler.nodes.GuardProxyNode) Deque(java.util.Deque) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) TriState(jdk.vm.ci.meta.TriState) EconomicMap(org.graalvm.collections.EconomicMap) MergeNode(org.graalvm.compiler.nodes.MergeNode) VirtualState(org.graalvm.compiler.nodes.VirtualState) FixedNode(org.graalvm.compiler.nodes.FixedNode) NodeWithState(org.graalvm.compiler.nodes.spi.NodeWithState) Iterator(java.util.Iterator) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) NodeView(org.graalvm.compiler.nodes.NodeView) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) NodeBitMap(org.graalvm.compiler.graph.NodeBitMap) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) Graph(org.graalvm.compiler.graph.Graph) ValueNode(org.graalvm.compiler.nodes.ValueNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) DuplicationReplacement(org.graalvm.compiler.graph.Graph.DuplicationReplacement) GuardPhiNode(org.graalvm.compiler.nodes.GuardPhiNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) FrameState(org.graalvm.compiler.nodes.FrameState) NodeIterable(org.graalvm.compiler.graph.iterators.NodeIterable) Invoke(org.graalvm.compiler.nodes.Invoke) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) Block(org.graalvm.compiler.nodes.cfg.Block) GraalError(org.graalvm.compiler.debug.GraalError) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) ArrayDeque(java.util.ArrayDeque) Collections(java.util.Collections) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) GuardProxyNode(org.graalvm.compiler.nodes.GuardProxyNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) GuardPhiNode(org.graalvm.compiler.nodes.GuardPhiNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) NodeBitMap(org.graalvm.compiler.graph.NodeBitMap) GuardNode(org.graalvm.compiler.nodes.GuardNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) GuardProxyNode(org.graalvm.compiler.nodes.GuardProxyNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ValueProxyNode(org.graalvm.compiler.nodes.ValueProxyNode) GuardPhiNode(org.graalvm.compiler.nodes.GuardPhiNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) FrameState(org.graalvm.compiler.nodes.FrameState) ArrayDeque(java.util.ArrayDeque) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) Invoke(org.graalvm.compiler.nodes.Invoke) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) NodeWithState(org.graalvm.compiler.nodes.spi.NodeWithState) CommitAllocationNode(org.graalvm.compiler.nodes.virtual.CommitAllocationNode)

Example 25 with VirtualObjectNode

use of org.graalvm.compiler.nodes.virtual.VirtualObjectNode in project graal by oracle.

the class DefaultJavaLoweringProvider method lowerCommitAllocationNode.

@SuppressWarnings("try")
protected void lowerCommitAllocationNode(CommitAllocationNode commit, LoweringTool tool) {
    StructuredGraph graph = commit.graph();
    if (graph.getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
        List<AbstractNewObjectNode> recursiveLowerings = new ArrayList<>();
        ValueNode[] allocations = new ValueNode[commit.getVirtualObjects().size()];
        BitSet omittedValues = new BitSet();
        int valuePos = 0;
        for (int objIndex = 0; objIndex < commit.getVirtualObjects().size(); objIndex++) {
            VirtualObjectNode virtual = commit.getVirtualObjects().get(objIndex);
            int entryCount = virtual.entryCount();
            AbstractNewObjectNode newObject;
            try (DebugCloseable nsp = virtual.withNodeSourcePosition()) {
                if (virtual instanceof VirtualInstanceNode) {
                    newObject = graph.add(createNewInstanceFromVirtual(virtual));
                } else {
                    newObject = graph.add(createNewArrayFromVirtual(virtual, ConstantNode.forInt(entryCount, graph)));
                }
            }
            recursiveLowerings.add(newObject);
            graph.addBeforeFixed(commit, newObject);
            allocations[objIndex] = newObject;
            for (int i = 0; i < entryCount; i++) {
                ValueNode value = commit.getValues().get(valuePos);
                if (value instanceof VirtualObjectNode) {
                    value = allocations[commit.getVirtualObjects().indexOf(value)];
                }
                if (value == null) {
                    omittedValues.set(valuePos);
                } else if (!(value.isConstant() && value.asConstant().isDefaultForKind())) {
                    // Constant.illegal is always the defaultForKind, so it is skipped
                    JavaKind valueKind = value.getStackKind();
                    JavaKind entryKind = virtual.entryKind(i);
                    // Truffle requires some leniency in terms of what can be put where:
                    assert valueKind.getStackKind() == entryKind.getStackKind() || (valueKind == JavaKind.Long || valueKind == JavaKind.Double || (valueKind == JavaKind.Int && virtual instanceof VirtualArrayNode));
                    AddressNode address = null;
                    BarrierType barrierType = null;
                    if (virtual instanceof VirtualInstanceNode) {
                        ResolvedJavaField field = ((VirtualInstanceNode) virtual).field(i);
                        long offset = fieldOffset(field);
                        if (offset >= 0) {
                            address = createOffsetAddress(graph, newObject, offset);
                            barrierType = fieldInitializationBarrier(entryKind);
                        }
                    } else {
                        address = createOffsetAddress(graph, newObject, arrayBaseOffset(entryKind) + i * arrayScalingFactor(entryKind));
                        barrierType = arrayInitializationBarrier(entryKind);
                    }
                    if (address != null) {
                        WriteNode write = new WriteNode(address, LocationIdentity.init(), implicitStoreConvert(graph, entryKind, value), barrierType);
                        graph.addAfterFixed(newObject, graph.add(write));
                    }
                }
                valuePos++;
            }
        }
        valuePos = 0;
        for (int objIndex = 0; objIndex < commit.getVirtualObjects().size(); objIndex++) {
            VirtualObjectNode virtual = commit.getVirtualObjects().get(objIndex);
            int entryCount = virtual.entryCount();
            ValueNode newObject = allocations[objIndex];
            for (int i = 0; i < entryCount; i++) {
                if (omittedValues.get(valuePos)) {
                    ValueNode value = commit.getValues().get(valuePos);
                    assert value instanceof VirtualObjectNode;
                    ValueNode allocValue = allocations[commit.getVirtualObjects().indexOf(value)];
                    if (!(allocValue.isConstant() && allocValue.asConstant().isDefaultForKind())) {
                        assert virtual.entryKind(i) == JavaKind.Object && allocValue.getStackKind() == JavaKind.Object;
                        AddressNode address;
                        BarrierType barrierType;
                        if (virtual instanceof VirtualInstanceNode) {
                            VirtualInstanceNode virtualInstance = (VirtualInstanceNode) virtual;
                            address = createFieldAddress(graph, newObject, virtualInstance.field(i));
                            barrierType = BarrierType.IMPRECISE;
                        } else {
                            address = createArrayAddress(graph, newObject, virtual.entryKind(i), ConstantNode.forInt(i, graph));
                            barrierType = BarrierType.PRECISE;
                        }
                        if (address != null) {
                            WriteNode write = new WriteNode(address, LocationIdentity.init(), implicitStoreConvert(graph, JavaKind.Object, allocValue), barrierType);
                            graph.addBeforeFixed(commit, graph.add(write));
                        }
                    }
                }
                valuePos++;
            }
        }
        finishAllocatedObjects(tool, commit, allocations);
        graph.removeFixed(commit);
        for (AbstractNewObjectNode recursiveLowering : recursiveLowerings) {
            recursiveLowering.lower(tool);
        }
    }
}
Also used : VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) ArrayList(java.util.ArrayList) BitSet(java.util.BitSet) BarrierType(org.graalvm.compiler.nodes.memory.HeapAccess.BarrierType) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) VirtualInstanceNode(org.graalvm.compiler.nodes.virtual.VirtualInstanceNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) AtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.AtomicReadAndWriteNode) JavaWriteNode(org.graalvm.compiler.nodes.extended.JavaWriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

VirtualObjectNode (org.graalvm.compiler.nodes.virtual.VirtualObjectNode)42 ValueNode (org.graalvm.compiler.nodes.ValueNode)38 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)8 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)7 Node (org.graalvm.compiler.graph.Node)7 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)7 VirtualObjectState (org.graalvm.compiler.virtual.nodes.VirtualObjectState)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)5 PhiNode (org.graalvm.compiler.nodes.PhiNode)5 Block (org.graalvm.compiler.nodes.cfg.Block)5 ArrayList (java.util.ArrayList)4 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)4 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)4 ValueProxyNode (org.graalvm.compiler.nodes.ValueProxyNode)4 VirtualArrayNode (org.graalvm.compiler.nodes.virtual.VirtualArrayNode)4 VirtualInstanceNode (org.graalvm.compiler.nodes.virtual.VirtualInstanceNode)4 JavaKind (jdk.vm.ci.meta.JavaKind)3 FrameState (org.graalvm.compiler.nodes.FrameState)3 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)3 BitSet (java.util.BitSet)2