Search in sources :

Example 1 with StartNode

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

the class OnStackReplacementPhase method run.

@Override
@SuppressWarnings("try")
protected void run(StructuredGraph graph) {
    DebugContext debug = graph.getDebug();
    if (graph.getEntryBCI() == JVMCICompiler.INVOCATION_ENTRY_BCI) {
        // used.
        assert graph.getNodes(EntryMarkerNode.TYPE).isEmpty();
        return;
    }
    debug.dump(DebugContext.DETAILED_LEVEL, graph, "OnStackReplacement initial at bci %d", graph.getEntryBCI());
    EntryMarkerNode osr;
    int maxIterations = -1;
    int iterations = 0;
    final EntryMarkerNode originalOSRNode = getEntryMarker(graph);
    final LoopBeginNode originalOSRLoop = osrLoop(originalOSRNode);
    final boolean currentOSRWithLocks = osrWithLocks(originalOSRNode);
    if (originalOSRLoop == null) {
        /*
             * OSR with Locks: We do not have an OSR loop for the original OSR bci. Therefore we
             * cannot decide where to deopt and which framestate will be used. In the worst case the
             * framestate of the OSR entry would be used.
             */
        throw new PermanentBailoutException("OSR compilation without OSR entry loop.");
    }
    if (!supportOSRWithLocks(graph.getOptions()) && currentOSRWithLocks) {
        throw new PermanentBailoutException("OSR with locks disabled.");
    }
    do {
        osr = getEntryMarker(graph);
        LoopsData loops = new LoopsData(graph);
        // Find the loop that contains the EntryMarker
        Loop<Block> l = loops.getCFG().getNodeToBlock().get(osr).getLoop();
        if (l == null) {
            break;
        }
        iterations++;
        if (maxIterations == -1) {
            maxIterations = l.getDepth();
        } else if (iterations > maxIterations) {
            throw GraalError.shouldNotReachHere();
        }
        // Peel the outermost loop first
        while (l.getParent() != null) {
            l = l.getParent();
        }
        LoopTransformations.peel(loops.loop(l));
        osr.replaceAtUsages(InputType.Guard, AbstractBeginNode.prevBegin((FixedNode) osr.predecessor()));
        for (Node usage : osr.usages().snapshot()) {
            EntryProxyNode proxy = (EntryProxyNode) usage;
            proxy.replaceAndDelete(proxy.value());
        }
        GraphUtil.removeFixedWithUnusedInputs(osr);
        debug.dump(DebugContext.DETAILED_LEVEL, graph, "OnStackReplacement loop peeling result");
    } while (true);
    StartNode start = graph.start();
    FrameState osrState = osr.stateAfter();
    OSRStartNode osrStart;
    try (DebugCloseable context = osr.withNodeSourcePosition()) {
        osr.setStateAfter(null);
        osrStart = graph.add(new OSRStartNode());
        FixedNode next = osr.next();
        osr.setNext(null);
        osrStart.setNext(next);
        graph.setStart(osrStart);
        osrStart.setStateAfter(osrState);
        debug.dump(DebugContext.DETAILED_LEVEL, graph, "OnStackReplacement after setting OSR start");
        final int localsSize = osrState.localsSize();
        final int locksSize = osrState.locksSize();
        for (int i = 0; i < localsSize + locksSize; i++) {
            ValueNode value = null;
            if (i >= localsSize) {
                value = osrState.lockAt(i - localsSize);
            } else {
                value = osrState.localAt(i);
            }
            if (value instanceof EntryProxyNode) {
                EntryProxyNode proxy = (EntryProxyNode) value;
                /*
                     * We need to drop the stamp since the types we see during OSR may be too
                     * precise (if a branch was not parsed for example). In cases when this is
                     * possible, we insert a guard and narrow the OSRLocal stamp at its usages.
                     */
                Stamp narrowedStamp = proxy.value().stamp(NodeView.DEFAULT);
                Stamp unrestrictedStamp = proxy.stamp(NodeView.DEFAULT).unrestricted();
                ValueNode osrLocal;
                if (i >= localsSize) {
                    osrLocal = graph.addOrUnique(new OSRLockNode(i - localsSize, unrestrictedStamp));
                } else {
                    osrLocal = graph.addOrUnique(new OSRLocalNode(i, unrestrictedStamp));
                }
                // Speculate on the OSRLocal stamps that could be more precise.
                OSRLocalSpeculationReason reason = new OSRLocalSpeculationReason(osrState.bci, narrowedStamp, i);
                if (graph.getSpeculationLog().maySpeculate(reason) && osrLocal instanceof OSRLocalNode && value.getStackKind().equals(JavaKind.Object) && !narrowedStamp.isUnrestricted()) {
                    // Add guard.
                    LogicNode check = graph.addOrUniqueWithInputs(InstanceOfNode.createHelper((ObjectStamp) narrowedStamp, osrLocal, null, null));
                    JavaConstant constant = graph.getSpeculationLog().speculate(reason);
                    FixedGuardNode guard = graph.add(new FixedGuardNode(check, DeoptimizationReason.OptimizedTypeCheckViolated, DeoptimizationAction.InvalidateRecompile, constant, false));
                    graph.addAfterFixed(osrStart, guard);
                    // Replace with a more specific type at usages.
                    // We know that we are at the root,
                    // so we need to replace the proxy in the state.
                    proxy.replaceAtMatchingUsages(osrLocal, n -> n == osrState);
                    osrLocal = graph.addOrUnique(new PiNode(osrLocal, narrowedStamp, guard));
                }
                proxy.replaceAndDelete(osrLocal);
            } else {
                assert value == null || value instanceof OSRLocalNode;
            }
        }
        osr.replaceAtUsages(InputType.Guard, osrStart);
    }
    debug.dump(DebugContext.DETAILED_LEVEL, graph, "OnStackReplacement after replacing entry proxies");
    GraphUtil.killCFG(start);
    debug.dump(DebugContext.DETAILED_LEVEL, graph, "OnStackReplacement result");
    new DeadCodeEliminationPhase(Required).apply(graph);
    if (currentOSRWithLocks) {
        OsrWithLocksCount.increment(debug);
        try (DebugCloseable context = osrStart.withNodeSourcePosition()) {
            for (int i = osrState.monitorIdCount() - 1; i >= 0; --i) {
                MonitorIdNode id = osrState.monitorIdAt(i);
                ValueNode lockedObject = osrState.lockAt(i);
                OSRMonitorEnterNode osrMonitorEnter = graph.add(new OSRMonitorEnterNode(lockedObject, id));
                for (Node usage : id.usages()) {
                    if (usage instanceof AccessMonitorNode) {
                        AccessMonitorNode access = (AccessMonitorNode) usage;
                        access.setObject(lockedObject);
                    }
                }
                FixedNode oldNext = osrStart.next();
                oldNext.replaceAtPredecessor(null);
                osrMonitorEnter.setNext(oldNext);
                osrStart.setNext(osrMonitorEnter);
            }
        }
        debug.dump(DebugContext.DETAILED_LEVEL, graph, "After inserting OSR monitor enters");
        /*
             * Ensure balanced monitorenter - monitorexit
             *
             * Ensure that there is no monitor exit without a monitor enter in the graph. If there
             * is one this can only be done by bytecode as we have the monitor enter before the OSR
             * loop but the exit in a path of the loop that must be under a condition, else it will
             * throw an IllegalStateException anyway in the 2.iteration
             */
        for (MonitorExitNode exit : graph.getNodes(MonitorExitNode.TYPE)) {
            MonitorIdNode id = exit.getMonitorId();
            if (id.usages().filter(MonitorEnterNode.class).count() != 1) {
                throw new PermanentBailoutException("Unbalanced monitor enter-exit in OSR compilation with locks. Object is locked before the loop but released inside the loop.");
            }
        }
    }
    debug.dump(DebugContext.DETAILED_LEVEL, graph, "OnStackReplacement result");
    new DeadCodeEliminationPhase(Required).apply(graph);
    /*
         * There must not be any parameter nodes left after OSR compilation.
         */
    assert graph.getNodes(ParameterNode.TYPE).count() == 0 : "OSR Compilation contains references to parameters.";
}
Also used : EntryMarkerNode(org.graalvm.compiler.nodes.EntryMarkerNode) AccessMonitorNode(org.graalvm.compiler.nodes.java.AccessMonitorNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) OSRLockNode(org.graalvm.compiler.nodes.extended.OSRLockNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) OSRLocalNode(org.graalvm.compiler.nodes.extended.OSRLocalNode) EntryMarkerNode(org.graalvm.compiler.nodes.EntryMarkerNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) EntryProxyNode(org.graalvm.compiler.nodes.EntryProxyNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) PiNode(org.graalvm.compiler.nodes.PiNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) OSRMonitorEnterNode(org.graalvm.compiler.nodes.extended.OSRMonitorEnterNode) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) StartNode(org.graalvm.compiler.nodes.StartNode) InstanceOfNode(org.graalvm.compiler.nodes.java.InstanceOfNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) AccessMonitorNode(org.graalvm.compiler.nodes.java.AccessMonitorNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) OSRStartNode(org.graalvm.compiler.nodes.extended.OSRStartNode) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) Node(org.graalvm.compiler.graph.Node) JavaConstant(jdk.vm.ci.meta.JavaConstant) FixedNode(org.graalvm.compiler.nodes.FixedNode) PiNode(org.graalvm.compiler.nodes.PiNode) FrameState(org.graalvm.compiler.nodes.FrameState) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) DeadCodeEliminationPhase(org.graalvm.compiler.phases.common.DeadCodeEliminationPhase) PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) StartNode(org.graalvm.compiler.nodes.StartNode) OSRStartNode(org.graalvm.compiler.nodes.extended.OSRStartNode) LoopsData(org.graalvm.compiler.loop.LoopsData) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) OSRLocalNode(org.graalvm.compiler.nodes.extended.OSRLocalNode) DebugContext(org.graalvm.compiler.debug.DebugContext) EntryProxyNode(org.graalvm.compiler.nodes.EntryProxyNode) OSRLockNode(org.graalvm.compiler.nodes.extended.OSRLockNode) OSRMonitorEnterNode(org.graalvm.compiler.nodes.extended.OSRMonitorEnterNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) OSRStartNode(org.graalvm.compiler.nodes.extended.OSRStartNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Block(org.graalvm.compiler.nodes.cfg.Block) LogicNode(org.graalvm.compiler.nodes.LogicNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 2 with StartNode

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

the class DefaultHotSpotLoweringProvider method lowerOSRStartNode.

private void lowerOSRStartNode(OSRStartNode osrStart) {
    StructuredGraph graph = osrStart.graph();
    if (graph.getGuardsStage() == StructuredGraph.GuardsStage.FIXED_DEOPTS) {
        StartNode newStart = graph.add(new StartNode());
        ParameterNode buffer = graph.addWithoutUnique(new ParameterNode(0, StampPair.createSingle(StampFactory.forKind(runtime.getTarget().wordJavaKind))));
        ForeignCallNode migrationEnd = graph.add(new ForeignCallNode(foreignCalls, OSR_MIGRATION_END, buffer));
        migrationEnd.setStateAfter(osrStart.stateAfter());
        newStart.setNext(migrationEnd);
        FixedNode next = osrStart.next();
        osrStart.setNext(null);
        migrationEnd.setNext(next);
        graph.setStart(newStart);
        final int wordSize = target.wordSize;
        // @formatter:off
        // taken from c2 locals_addr = osr_buf + (max_locals-1)*wordSize)
        // @formatter:on
        int localsOffset = (graph.method().getMaxLocals() - 1) * wordSize;
        for (OSRLocalNode osrLocal : graph.getNodes(OSRLocalNode.TYPE)) {
            int size = osrLocal.getStackKind().getSlotCount();
            int offset = localsOffset - (osrLocal.index() + size - 1) * wordSize;
            AddressNode address = createOffsetAddress(graph, buffer, offset);
            ReadNode load = graph.add(new ReadNode(address, any(), osrLocal.stamp(NodeView.DEFAULT), BarrierType.NONE));
            osrLocal.replaceAndDelete(load);
            graph.addBeforeFixed(migrationEnd, load);
        }
        // @formatter:off
        // taken from c2 monitors_addr = osr_buf + (max_locals+mcnt*2-1)*wordSize);
        // @formatter:on
        final int lockCount = osrStart.stateAfter().locksSize();
        final int locksOffset = (graph.method().getMaxLocals() + lockCount * 2 - 1) * wordSize;
        // buffer
        for (OSRMonitorEnterNode osrMonitorEnter : graph.getNodes(OSRMonitorEnterNode.TYPE)) {
            MonitorIdNode monitorID = osrMonitorEnter.getMonitorId();
            OSRLockNode lock = (OSRLockNode) osrMonitorEnter.object();
            final int index = lock.index();
            final int offsetDisplacedHeader = locksOffset - ((index * 2) + 1) * wordSize;
            final int offsetLockObject = locksOffset - index * 2 * wordSize;
            // load the displaced mark from the osr buffer
            AddressNode addressDisplacedHeader = createOffsetAddress(graph, buffer, offsetDisplacedHeader);
            ReadNode loadDisplacedHeader = graph.add(new ReadNode(addressDisplacedHeader, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
            graph.addBeforeFixed(migrationEnd, loadDisplacedHeader);
            // we need to initialize the stack slot for the lock
            BeginLockScopeNode beginLockScope = graph.add(new BeginLockScopeNode(lock.getStackKind(), monitorID.getLockDepth()));
            graph.addBeforeFixed(migrationEnd, beginLockScope);
            // write the displaced mark to the correct stack slot
            AddressNode addressDisplacedMark = createOffsetAddress(graph, beginLockScope, runtime.getVMConfig().basicLockDisplacedHeaderOffset);
            WriteNode writeStackSlot = graph.add(new WriteNode(addressDisplacedMark, DISPLACED_MARK_WORD_LOCATION, loadDisplacedHeader, BarrierType.NONE));
            graph.addBeforeFixed(migrationEnd, writeStackSlot);
            // load the lock object from the osr buffer
            AddressNode addressLockObject = createOffsetAddress(graph, buffer, offsetLockObject);
            ReadNode loadObject = graph.add(new ReadNode(addressLockObject, any(), lock.stamp(NodeView.DEFAULT), BarrierType.NONE));
            lock.replaceAndDelete(loadObject);
            graph.addBeforeFixed(migrationEnd, loadObject);
        }
        osrStart.replaceAtUsagesAndDelete(newStart);
    }
}
Also used : MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) OSRStartNode(org.graalvm.compiler.nodes.extended.OSRStartNode) StartNode(org.graalvm.compiler.nodes.StartNode) OSRLocalNode(org.graalvm.compiler.nodes.extended.OSRLocalNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) OSRLockNode(org.graalvm.compiler.nodes.extended.OSRLockNode) OSRMonitorEnterNode(org.graalvm.compiler.nodes.extended.OSRMonitorEnterNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) BeginLockScopeNode(org.graalvm.compiler.hotspot.nodes.BeginLockScopeNode) 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) WriteNode(org.graalvm.compiler.nodes.memory.WriteNode)

Example 3 with StartNode

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

the class SnippetTemplate method instantiate.

/**
 * Replaces a given fixed node with this specialized snippet.
 *
 * @param metaAccess
 * @param replacee the node that will be replaced
 * @param replacer object that replaces the usages of {@code replacee}
 * @param args the arguments to be bound to the flattened positional parameters of the snippet
 * @param killReplacee is true, the replacee node is deleted
 * @return the map of duplicated nodes (original -&gt; duplicate)
 */
@SuppressWarnings("try")
public UnmodifiableEconomicMap<Node, Node> instantiate(MetaAccessProvider metaAccess, FixedNode replacee, UsageReplacer replacer, Arguments args, boolean killReplacee) {
    DebugContext debug = replacee.getDebug();
    assert assertSnippetKills(replacee);
    try (DebugCloseable a = args.info.instantiationTimer.start(debug)) {
        args.info.instantiationCounter.increment(debug);
        // Inline the snippet nodes, replacing parameters with the given args in the process
        StartNode entryPointNode = snippet.start();
        FixedNode firstCFGNode = entryPointNode.next();
        StructuredGraph replaceeGraph = replacee.graph();
        EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args);
        replacements.put(entryPointNode, AbstractBeginNode.prevBegin(replacee));
        UnmodifiableEconomicMap<Node, Node> duplicates = inlineSnippet(replacee, debug, replaceeGraph, replacements);
        // Re-wire the control flow graph around the replacee
        FixedNode firstCFGNodeDuplicate = (FixedNode) duplicates.get(firstCFGNode);
        replacee.replaceAtPredecessor(firstCFGNodeDuplicate);
        rewireFrameStates(replacee, duplicates);
        if (replacee instanceof DeoptimizingNode) {
            DeoptimizingNode replaceeDeopt = (DeoptimizingNode) replacee;
            FrameState stateBefore = null;
            FrameState stateDuring = null;
            FrameState stateAfter = null;
            if (replaceeDeopt.canDeoptimize()) {
                if (replaceeDeopt instanceof DeoptimizingNode.DeoptBefore) {
                    stateBefore = ((DeoptimizingNode.DeoptBefore) replaceeDeopt).stateBefore();
                }
                if (replaceeDeopt instanceof DeoptimizingNode.DeoptDuring) {
                    stateDuring = ((DeoptimizingNode.DeoptDuring) replaceeDeopt).stateDuring();
                }
                if (replaceeDeopt instanceof DeoptimizingNode.DeoptAfter) {
                    stateAfter = ((DeoptimizingNode.DeoptAfter) replaceeDeopt).stateAfter();
                }
            }
            for (DeoptimizingNode deoptNode : deoptNodes) {
                DeoptimizingNode deoptDup = (DeoptimizingNode) duplicates.get(deoptNode.asNode());
                if (deoptDup.canDeoptimize()) {
                    if (deoptDup instanceof DeoptimizingNode.DeoptBefore) {
                        ((DeoptimizingNode.DeoptBefore) deoptDup).setStateBefore(stateBefore);
                    }
                    if (deoptDup instanceof DeoptimizingNode.DeoptDuring) {
                        DeoptimizingNode.DeoptDuring deoptDupDuring = (DeoptimizingNode.DeoptDuring) deoptDup;
                        if (stateDuring != null) {
                            deoptDupDuring.setStateDuring(stateDuring);
                        } else if (stateAfter != null) {
                            deoptDupDuring.computeStateDuring(stateAfter);
                        } else if (stateBefore != null) {
                            assert !deoptDupDuring.hasSideEffect() : "can't use stateBefore as stateDuring for state split " + deoptDupDuring;
                            deoptDupDuring.setStateDuring(stateBefore);
                        }
                    }
                    if (deoptDup instanceof DeoptimizingNode.DeoptAfter) {
                        DeoptimizingNode.DeoptAfter deoptDupAfter = (DeoptimizingNode.DeoptAfter) deoptDup;
                        if (stateAfter != null) {
                            deoptDupAfter.setStateAfter(stateAfter);
                        } else {
                            assert !deoptDupAfter.hasSideEffect() : "can't use stateBefore as stateAfter for state split " + deoptDupAfter;
                            deoptDupAfter.setStateAfter(stateBefore);
                        }
                    }
                }
            }
        }
        updateStamps(replacee, duplicates);
        rewireMemoryGraph(replacee, duplicates);
        // Replace all usages of the replacee with the value returned by the snippet
        ValueNode returnValue = null;
        if (returnNode != null && !(replacee instanceof ControlSinkNode)) {
            ReturnNode returnDuplicate = (ReturnNode) duplicates.get(returnNode);
            returnValue = returnDuplicate.result();
            if (returnValue == null && replacee.usages().isNotEmpty() && replacee instanceof MemoryCheckpoint) {
                replacer.replace(replacee, null);
            } else {
                assert returnValue != null || replacee.hasNoUsages();
                replacer.replace(replacee, returnValue);
            }
            if (returnDuplicate.isAlive()) {
                FixedNode next = null;
                if (replacee instanceof FixedWithNextNode) {
                    FixedWithNextNode fwn = (FixedWithNextNode) replacee;
                    next = fwn.next();
                    fwn.setNext(null);
                }
                returnDuplicate.replaceAndDelete(next);
            }
        }
        if (killReplacee) {
            // Remove the replacee from its graph
            GraphUtil.killCFG(replacee);
        }
        debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this);
        return duplicates;
    }
}
Also used : StartNode(org.graalvm.compiler.nodes.StartNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) MemoryNode(org.graalvm.compiler.nodes.memory.MemoryNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) DebugContext(org.graalvm.compiler.debug.DebugContext) FixedNode(org.graalvm.compiler.nodes.FixedNode) FrameState(org.graalvm.compiler.nodes.FrameState) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MemoryCheckpoint(org.graalvm.compiler.nodes.memory.MemoryCheckpoint) ValueNode(org.graalvm.compiler.nodes.ValueNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 4 with StartNode

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

the class SnippetTemplate method instantiate.

/**
 * Replaces a given floating node with this specialized snippet.
 *
 * This snippet must be pure data-flow
 *
 * @param metaAccess
 * @param replacee the node that will be replaced
 * @param replacer object that replaces the usages of {@code replacee}
 * @param args the arguments to be bound to the flattened positional parameters of the snippet
 */
@SuppressWarnings("try")
public void instantiate(MetaAccessProvider metaAccess, FloatingNode replacee, UsageReplacer replacer, Arguments args) {
    DebugContext debug = replacee.getDebug();
    assert assertSnippetKills(replacee);
    try (DebugCloseable a = args.info.instantiationTimer.start(debug)) {
        args.info.instantiationCounter.increment(debug);
        // Inline the snippet nodes, replacing parameters with the given args in the process
        StartNode entryPointNode = snippet.start();
        assert entryPointNode.next() == (memoryAnchor == null ? returnNode : memoryAnchor) : entryPointNode.next();
        StructuredGraph replaceeGraph = replacee.graph();
        EconomicMap<Node, Node> replacements = bind(replaceeGraph, metaAccess, args);
        MemoryAnchorNode anchorDuplicate = null;
        if (memoryAnchor != null) {
            anchorDuplicate = replaceeGraph.add(new MemoryAnchorNode());
            replacements.put(memoryAnchor, anchorDuplicate);
        }
        List<Node> floatingNodes = new ArrayList<>(nodes.size() - 2);
        for (Node n : nodes) {
            if (n != entryPointNode && n != returnNode) {
                floatingNodes.add(n);
            }
        }
        UnmodifiableEconomicMap<Node, Node> duplicates = inlineSnippet(replacee, debug, replaceeGraph, replacements);
        rewireFrameStates(replacee, duplicates);
        updateStamps(replacee, duplicates);
        rewireMemoryGraph(replacee, duplicates);
        assert anchorDuplicate == null || anchorDuplicate.isDeleted();
        // Replace all usages of the replacee with the value returned by the snippet
        ValueNode returnValue = (ValueNode) duplicates.get(returnNode.result());
        replacer.replace(replacee, returnValue);
        debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After lowering %s with %s", replacee, this);
    }
}
Also used : StartNode(org.graalvm.compiler.nodes.StartNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) MemoryNode(org.graalvm.compiler.nodes.memory.MemoryNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ArrayList(java.util.ArrayList) ValueNode(org.graalvm.compiler.nodes.ValueNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) DebugContext(org.graalvm.compiler.debug.DebugContext) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 5 with StartNode

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

the class CompileQueue method insertDeoptTests.

/**
 * Inserts a call to {@link DeoptTester#deoptTest} right after FixedWithNextNode StateSplits.
 *
 * @param method method that is being augmented with deopt test calls
 * @param graph The graph of a deoptimizable method or the corresponding deopt target method.
 */
private static void insertDeoptTests(HostedMethod method, StructuredGraph graph) {
    for (Node node : graph.getNodes()) {
        if (node instanceof FixedWithNextNode && node instanceof StateSplit && !(node instanceof InvokeNode) && !(node instanceof ForeignCallNode) && !(node instanceof DeoptTestNode) && !(method.isSynchronized() && node instanceof StartNode)) {
            FixedWithNextNode fixedWithNext = (FixedWithNextNode) node;
            FixedNode next = fixedWithNext.next();
            DeoptTestNode testNode = graph.add(new DeoptTestNode());
            fixedWithNext.setNext(null);
            testNode.setNext(next);
            fixedWithNext.setNext(testNode);
        }
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) StartNode(org.graalvm.compiler.nodes.StartNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) StackValueNode(com.oracle.svm.core.graal.stackvalue.StackValueNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) DeoptTestNode(com.oracle.svm.core.graal.nodes.DeoptTestNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) DeoptEntryNode(com.oracle.svm.core.graal.nodes.DeoptEntryNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) StartNode(org.graalvm.compiler.nodes.StartNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) DeoptTestNode(com.oracle.svm.core.graal.nodes.DeoptTestNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Aggregations

StartNode (org.graalvm.compiler.nodes.StartNode)13 FixedNode (org.graalvm.compiler.nodes.FixedNode)10 Node (org.graalvm.compiler.graph.Node)8 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)8 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)7 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)7 ValueNode (org.graalvm.compiler.nodes.ValueNode)7 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)6 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)6 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)6 DebugContext (org.graalvm.compiler.debug.DebugContext)5 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)5 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)5 MergeNode (org.graalvm.compiler.nodes.MergeNode)5 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)5 FrameState (org.graalvm.compiler.nodes.FrameState)4 PhiNode (org.graalvm.compiler.nodes.PhiNode)4 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)3 DeoptimizingNode (org.graalvm.compiler.nodes.DeoptimizingNode)3 ArrayList (java.util.ArrayList)2