Search in sources :

Example 41 with FixedWithNextNode

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

the class ReplaceConstantNodesPhase method findFixedWithValidState.

/**
 * Find first dominating {@link FixedWithNextNode} that has a valid state reaching it starting
 * from the given node.
 *
 * @param graph
 * @param stateMapper
 * @param node
 * @return {@link FixedWithNextNode} that we can use as an insertion point
 */
private static FixedWithNextNode findFixedWithValidState(StructuredGraph graph, FrameStateMapperClosure stateMapper, FixedWithNextNode node) {
    ScheduleResult schedule = graph.getLastSchedule();
    NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
    Block block = nodeToBlock.get(node);
    Node n = node;
    do {
        if (isFixedWithValidState(stateMapper, n)) {
            return (FixedWithNextNode) n;
        }
        while (n != block.getBeginNode()) {
            n = n.predecessor();
            if (isFixedWithValidState(stateMapper, n)) {
                return (FixedWithNextNode) n;
            }
        }
        block = block.getDominator();
        if (block != null) {
            n = block.getEndNode();
        }
    } while (block != null);
    return graph.start();
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) LoadMethodCountersNode(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadConstantIndirectlyFixedNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Block(org.graalvm.compiler.nodes.cfg.Block)

Example 42 with FixedWithNextNode

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

the class ReplaceConstantNodesPhase method replaceWithResolution.

/**
 * Replace the uses of a constant with either {@link LoadConstantIndirectlyNode} or
 * {@link ResolveConstantNode}.
 *
 * @param graph
 * @param stateMapper
 * @param node {@link ConstantNode} containing a {@link HotSpotResolvedJavaType} that needs
 *            resolution.
 */
private static void replaceWithResolution(StructuredGraph graph, FrameStateMapperClosure stateMapper, ConstantNode node) {
    HotSpotMetaspaceConstant metaspaceConstant = (HotSpotMetaspaceConstant) node.asConstant();
    HotSpotResolvedJavaType type = (HotSpotResolvedJavaType) metaspaceConstant.asResolvedJavaType();
    ResolvedJavaType topMethodHolder = graph.method().getDeclaringClass();
    ValueNode replacement;
    if (type.isArray() && type.getComponentType().isPrimitive()) {
        // Special case for primitive arrays. The AOT runtime pre-resolves them, so we may
        // omit the resolution call.
        replacement = graph.addOrUnique(new LoadConstantIndirectlyNode(node));
    } else if (type.equals(topMethodHolder) || (type.isAssignableFrom(topMethodHolder) && !type.isInterface())) {
        // If it's a supertype of or the same class that declares the top method, we are
        // guaranteed to have it resolved already. If it's an interface, we just test for
        // equality.
        replacement = graph.addOrUnique(new LoadConstantIndirectlyNode(node));
    } else {
        FixedWithNextNode fixedReplacement;
        if (builtIns.contains(type.mirror())) {
            // Special case of klass constants that come from {@link BoxingSnippets}.
            fixedReplacement = graph.add(new ResolveConstantNode(node, HotSpotConstantLoadAction.INITIALIZE));
        } else {
            fixedReplacement = graph.add(new ResolveConstantNode(node));
        }
        insertReplacement(graph, stateMapper, node, fixedReplacement);
        replacement = fixedReplacement;
    }
    node.replaceAtUsages(replacement, n -> !isReplacementNode(n));
}
Also used : ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) HotSpotResolvedJavaType(jdk.vm.ci.hotspot.HotSpotResolvedJavaType) HotSpotMetaspaceConstant(jdk.vm.ci.hotspot.HotSpotMetaspaceConstant)

Example 43 with FixedWithNextNode

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

the class ReplaceConstantNodesPhase method findInsertionPoint.

/**
 * Find a good place to insert a stateful fixed node that is above the given node. A good
 * insertion point should have a valid FrameState reaching it.
 *
 * @param graph
 * @param stateMapper
 * @param node start search from this node up
 * @return an insertion point
 */
private static FixedWithNextNode findInsertionPoint(StructuredGraph graph, FrameStateMapperClosure stateMapper, FloatingNode node) {
    FixedWithNextNode fixed = findFixedBeforeFloating(graph, node);
    FixedWithNextNode result = findFixedWithValidState(graph, stateMapper, fixed);
    return result;
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode)

Example 44 with FixedWithNextNode

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

the class ReplaceConstantNodesPhase method findFixedBeforeFloating.

/**
 * Find the first {@link FixedWithNextNode} that is currently scheduled before the given
 * floating node.
 *
 * @param graph
 * @param node start search from this node up
 * @return the first {@link FixedWithNextNode}
 */
private static FixedWithNextNode findFixedBeforeFloating(StructuredGraph graph, FloatingNode node) {
    ScheduleResult schedule = graph.getLastSchedule();
    NodeMap<Block> nodeToBlock = schedule.getNodeToBlockMap();
    Block block = nodeToBlock.get(node);
    BlockMap<List<Node>> blockToNodes = schedule.getBlockToNodesMap();
    FixedWithNextNode result = null;
    for (Node n : blockToNodes.get(block)) {
        if (n.equals(node)) {
            break;
        }
        if (n instanceof FixedWithNextNode) {
            result = (FixedWithNextNode) n;
        }
    }
    assert result != null;
    return result;
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ScheduleResult(org.graalvm.compiler.nodes.StructuredGraph.ScheduleResult) LoadMethodCountersNode(org.graalvm.compiler.hotspot.nodes.aot.LoadMethodCountersNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadConstantIndirectlyFixedNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyFixedNode) LoadConstantIndirectlyNode(org.graalvm.compiler.hotspot.nodes.aot.LoadConstantIndirectlyNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ResolveDynamicConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveDynamicConstantNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolveConstantNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveConstantNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InitializeKlassNode(org.graalvm.compiler.hotspot.nodes.aot.InitializeKlassNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) ResolveMethodAndLoadCountersNode(org.graalvm.compiler.hotspot.nodes.aot.ResolveMethodAndLoadCountersNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Block(org.graalvm.compiler.nodes.cfg.Block) List(java.util.List)

Example 45 with FixedWithNextNode

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

the class WriteBarrierVerificationPhase method validateWrite.

private void validateWrite(Node write) {
    /*
         * The currently validated write is checked in order to discover if it has an appropriate
         * attached write barrier.
         */
    if (hasAttachedBarrier((FixedWithNextNode) write)) {
        return;
    }
    NodeFlood frontier = write.graph().createNodeFlood();
    expandFrontier(frontier, write);
    Iterator<Node> iterator = frontier.iterator();
    while (iterator.hasNext()) {
        Node currentNode = iterator.next();
        if (isSafepoint(currentNode)) {
            throw new AssertionError("Write barrier must be present " + write.toString(Verbosity.All) + " / " + write.inputs());
        }
        if (useG1GC()) {
            if (!(currentNode instanceof G1PostWriteBarrier) || (!validateBarrier((FixedAccessNode) write, (ObjectWriteBarrier) currentNode))) {
                expandFrontier(frontier, currentNode);
            }
        } else {
            if (!(currentNode instanceof SerialWriteBarrier) || (!validateBarrier((FixedAccessNode) write, (ObjectWriteBarrier) currentNode)) || ((currentNode instanceof SerialWriteBarrier) && !validateBarrier((FixedAccessNode) write, (ObjectWriteBarrier) currentNode))) {
                expandFrontier(frontier, currentNode);
            }
        }
    }
}
Also used : FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) ObjectWriteBarrier(org.graalvm.compiler.hotspot.nodes.ObjectWriteBarrier) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode) LoweredAtomicReadAndWriteNode(org.graalvm.compiler.nodes.java.LoweredAtomicReadAndWriteNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) OffsetAddressNode(org.graalvm.compiler.nodes.memory.address.OffsetAddressNode) FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) LogicCompareAndSwapNode(org.graalvm.compiler.nodes.java.LogicCompareAndSwapNode) G1PostWriteBarrier(org.graalvm.compiler.hotspot.nodes.G1PostWriteBarrier) SerialWriteBarrier(org.graalvm.compiler.hotspot.nodes.SerialWriteBarrier) NodeFlood(org.graalvm.compiler.graph.NodeFlood)

Aggregations

FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)57 FixedNode (org.graalvm.compiler.nodes.FixedNode)33 ValueNode (org.graalvm.compiler.nodes.ValueNode)29 Node (org.graalvm.compiler.graph.Node)26 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)22 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)21 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)20 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)13 EndNode (org.graalvm.compiler.nodes.EndNode)12 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)12 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)10 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)9 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)9 Invoke (org.graalvm.compiler.nodes.Invoke)9 LogicNode (org.graalvm.compiler.nodes.LogicNode)9 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)9 PhiNode (org.graalvm.compiler.nodes.PhiNode)9 IfNode (org.graalvm.compiler.nodes.IfNode)8 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)7 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7