Search in sources :

Example 1 with WithExceptionNode

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

the class BytecodeParser method replacePluginWithException.

@Override
public void replacePluginWithException(GeneratedInvocationPlugin plugin, ResolvedJavaMethod targetMethod, ValueNode[] args, PluginReplacementWithExceptionNode.ReplacementWithExceptionFunction replacementFunction) {
    assert replacementFunction != null;
    JavaType returnType = maybeEagerlyResolve(targetMethod.getSignature().getReturnType(method.getDeclaringClass()), targetMethod.getDeclaringClass());
    StampPair returnStamp = getReplacements().getGraphBuilderPlugins().getOverridingStamp(this, returnType, false);
    if (returnStamp == null) {
        returnStamp = StampFactory.forDeclaredType(getAssumptions(), returnType, false);
    }
    WithExceptionNode node = new PluginReplacementWithExceptionNode(returnStamp.getTrustedStamp(), args, replacementFunction, plugin.getClass().getSimpleName());
    if (returnType.getJavaKind() == JavaKind.Void) {
        add(node);
    } else {
        addPush(returnType.getJavaKind(), node);
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) StressInvokeWithExceptionNode(org.graalvm.compiler.core.common.GraalOptions.StressInvokeWithExceptionNode) PluginReplacementWithExceptionNode(org.graalvm.compiler.nodes.PluginReplacementWithExceptionNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) PluginReplacementWithExceptionNode(org.graalvm.compiler.nodes.PluginReplacementWithExceptionNode) StampPair(org.graalvm.compiler.core.common.type.StampPair)

Example 2 with WithExceptionNode

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

the class BytecodeParser method updateLastInstruction.

private <T extends ValueNode> void updateLastInstruction(T v) {
    if (v instanceof FixedNode) {
        FixedNode fixedNode = (FixedNode) v;
        if (lastInstr != null) {
            lastInstr.setNext(fixedNode);
        }
        if (fixedNode instanceof FixedWithNextNode) {
            FixedWithNextNode fixedWithNextNode = (FixedWithNextNode) fixedNode;
            assert fixedWithNextNode.next() == null : "cannot append instruction to instruction which isn't end";
            lastInstr = fixedWithNextNode;
        } else if (fixedNode instanceof WithExceptionNode) {
            lastInstr = updateWithExceptionNode((WithExceptionNode) fixedNode);
        } else {
            lastInstr = null;
        }
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) StressInvokeWithExceptionNode(org.graalvm.compiler.core.common.GraalOptions.StressInvokeWithExceptionNode) PluginReplacementWithExceptionNode(org.graalvm.compiler.nodes.PluginReplacementWithExceptionNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Example 3 with WithExceptionNode

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

the class PlaceholderLogicNode method verifyWithExceptionNode.

/**
 * Verifies that a {@link WithExceptionNode} has only memory usages via the
 * {@link WithExceptionNode#next()} edge. On the {@link WithExceptionNode#exceptionEdge()} there
 * must be a {@link MemoryKill} (or an {@link UnreachableBeginNode}), otherwise we would not
 * know from which edge a memory usage is coming from.
 */
private static void verifyWithExceptionNode(ValueNode node) {
    if (node instanceof WithExceptionNode && node instanceof MemoryKill) {
        WithExceptionNode withExceptionNode = (WithExceptionNode) node;
        AbstractBeginNode exceptionEdge = withExceptionNode.exceptionEdge();
        if (exceptionEdge instanceof UnreachableBeginNode) {
            // exception edge is unreachable - we are good
            return;
        }
        GraalError.guarantee(exceptionEdge instanceof MemoryKill, "The exception edge of %s is not a memory kill %s", node, exceptionEdge);
        if (exceptionEdge instanceof SingleMemoryKill) {
            SingleMemoryKill exceptionEdgeKill = (SingleMemoryKill) exceptionEdge;
            if (exceptionEdgeKill.getKilledLocationIdentity().isAny()) {
                // exception edge kills any - we are good
                return;
            }
            // if the exception edge does not kill any, it must kill the same location
            GraalError.guarantee(withExceptionNode instanceof SingleMemoryKill, "Not a single memory kill: %s", withExceptionNode);
            SingleMemoryKill withExceptionKill = (SingleMemoryKill) withExceptionNode;
            GraalError.guarantee(withExceptionKill.getKilledLocationIdentity().equals(exceptionEdgeKill.getKilledLocationIdentity()), "Kill locations do not match: %s (%s) vs %s (%s)", withExceptionKill, withExceptionKill.getKilledLocationIdentity(), exceptionEdgeKill, exceptionEdgeKill.getKilledLocationIdentity());
        } else if (exceptionEdge instanceof MultiMemoryKill) {
            // for multi memory kills the locations must match
            MultiMemoryKill exceptionEdgeKill = (MultiMemoryKill) exceptionEdge;
            GraalError.guarantee(withExceptionNode instanceof MultiMemoryKill, "Not a single memory kill: %s", withExceptionNode);
            MultiMemoryKill withExceptionKill = (MultiMemoryKill) withExceptionNode;
            GraalError.guarantee(Arrays.equals(withExceptionKill.getKilledLocationIdentities(), exceptionEdgeKill.getKilledLocationIdentities()), "Kill locations do not match: %s (%s) vs %s (%s)", withExceptionKill, withExceptionKill.getKilledLocationIdentities(), exceptionEdgeKill, exceptionEdgeKill.getKilledLocationIdentities());
        } else {
            GraalError.shouldNotReachHere("Unexpected exception edge: " + exceptionEdge);
        }
    }
}
Also used : SingleMemoryKill(org.graalvm.compiler.nodes.memory.SingleMemoryKill) MultiMemoryKill(org.graalvm.compiler.nodes.memory.MultiMemoryKill) MemoryKill(org.graalvm.compiler.nodes.memory.MemoryKill) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) FallbackInvokeWithExceptionNode(org.graalvm.compiler.replacements.nodes.FallbackInvokeWithExceptionNode) MacroWithExceptionNode(org.graalvm.compiler.replacements.nodes.MacroWithExceptionNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) MultiMemoryKill(org.graalvm.compiler.nodes.memory.MultiMemoryKill) UnreachableBeginNode(org.graalvm.compiler.nodes.UnreachableBeginNode) SingleMemoryKill(org.graalvm.compiler.nodes.memory.SingleMemoryKill) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 4 with WithExceptionNode

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

the class PlaceholderLogicNode method markExceptionsUnreachable.

/**
 * Searches for {@link WithExceptionNode} reachable from the {@link UnwindNode} and marks them
 * as {@linkplain WithExceptionNode#replaceWithNonThrowing() non-throwing}.
 */
private static void markExceptionsUnreachable(ValueNode snippetExceptionValue, EconomicMap<Node, Node> duplicates) {
    assert snippetExceptionValue.graph().isSubstitution() : "search should be done in the snippet graph";
    if (snippetExceptionValue instanceof ValuePhiNode) {
        for (ValueNode phiInput : ((PhiNode) snippetExceptionValue).values().snapshot()) {
            markExceptionsUnreachable(phiInput, duplicates);
        }
    } else {
        // snippetExceptionValue is a (lowered) ExceptionObjectNode
        Node snippetUnwindPred = snippetExceptionValue.predecessor();
        // the exception node might have been lowered to a memory anchor and a begin node
        while (snippetUnwindPred instanceof AbstractBeginNode || snippetUnwindPred instanceof MemoryAnchorNode) {
            snippetUnwindPred = snippetUnwindPred.predecessor();
        }
        GraalError.guarantee(snippetUnwindPred instanceof WithExceptionNode, "Unexpected exception producer: %s", snippetUnwindPred);
        WithExceptionNode snippetWithException = (WithExceptionNode) duplicates.get(snippetUnwindPred);
        snippetWithException.replaceWithNonThrowing();
    }
}
Also used : InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) FallbackInvokeWithExceptionNode(org.graalvm.compiler.replacements.nodes.FallbackInvokeWithExceptionNode) MacroWithExceptionNode(org.graalvm.compiler.replacements.nodes.MacroWithExceptionNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractBoxingNode(org.graalvm.compiler.nodes.extended.AbstractBoxingNode) UnreachableBeginNode(org.graalvm.compiler.nodes.UnreachableBeginNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) FallbackInvokeWithExceptionNode(org.graalvm.compiler.replacements.nodes.FallbackInvokeWithExceptionNode) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) 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) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) GuardedNode(org.graalvm.compiler.nodes.extended.GuardedNode) MemoryMapControlSinkNode(org.graalvm.compiler.nodes.MemoryMapControlSinkNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MacroWithExceptionNode(org.graalvm.compiler.replacements.nodes.MacroWithExceptionNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 5 with WithExceptionNode

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

the class GraphEffectList method deleteNode.

/**
 * Removes the given fixed node from the control flow and deletes it.
 *
 * @param node The fixed node that should be deleted.
 */
public void deleteNode(Node node) {
    add("delete fixed node", new Effect() {

        @Override
        public void apply(StructuredGraph graph, ArrayList<Node> obsoleteNodes) {
            if (node instanceof FixedWithNextNode) {
                GraphUtil.unlinkFixedNode((FixedWithNextNode) node);
            } else if (node instanceof WithExceptionNode && node.isAlive()) {
                WithExceptionNode withExceptionNode = (WithExceptionNode) node;
                AbstractBeginNode next = withExceptionNode.next();
                GraphUtil.unlinkAndKillExceptionEdge(withExceptionNode);
                if (next.hasNoUsages() && next instanceof MemoryKill) {
                    // This is a killing begin which is no longer needed.
                    graph.replaceFixedWithFixed(next, graph.add(new BeginNode()));
                }
                obsoleteNodes.add(withExceptionNode);
            }
            obsoleteNodes.add(node);
        }

        @Override
        public boolean isCfgKill() {
            return node instanceof WithExceptionNode;
        }
    });
}
Also used : MemoryKill(org.graalvm.compiler.nodes.memory.MemoryKill) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) BeginNode(org.graalvm.compiler.nodes.BeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) WeakCounterNode(org.graalvm.compiler.nodes.debug.WeakCounterNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) DynamicCounterNode(org.graalvm.compiler.nodes.debug.DynamicCounterNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Aggregations

WithExceptionNode (org.graalvm.compiler.nodes.WithExceptionNode)15 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)10 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)9 UnwindNode (org.graalvm.compiler.nodes.UnwindNode)9 Node (org.graalvm.compiler.graph.Node)8 FixedNode (org.graalvm.compiler.nodes.FixedNode)8 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)8 ValueNode (org.graalvm.compiler.nodes.ValueNode)8 ExceptionObjectNode (org.graalvm.compiler.nodes.java.ExceptionObjectNode)8 PhiNode (org.graalvm.compiler.nodes.PhiNode)7 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)6 IfNode (org.graalvm.compiler.nodes.IfNode)6 MergeNode (org.graalvm.compiler.nodes.MergeNode)6 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)5 LogicNode (org.graalvm.compiler.nodes.LogicNode)5 UnreachableBeginNode (org.graalvm.compiler.nodes.UnreachableBeginNode)5 FallbackInvokeWithExceptionNode (org.graalvm.compiler.replacements.nodes.FallbackInvokeWithExceptionNode)5 MacroWithExceptionNode (org.graalvm.compiler.replacements.nodes.MacroWithExceptionNode)5 BeginNode (org.graalvm.compiler.nodes.BeginNode)4 DeoptimizingNode (org.graalvm.compiler.nodes.DeoptimizingNode)4