use of org.graalvm.compiler.nodes.UnwindNode in project graal by oracle.
the class BytecodeExceptionTest method throwBytecodeException.
protected boolean throwBytecodeException(GraphBuilderContext b, Class<? extends Throwable> exception, ValueNode... arguments) {
BytecodeExceptionNode exceptionNode = b.add(new BytecodeExceptionNode(b.getMetaAccess(), exception, arguments));
b.add(new UnwindNode(exceptionNode));
return true;
}
use of org.graalvm.compiler.nodes.UnwindNode in project graal by oracle.
the class InliningUtil method inline.
/**
* Performs an actual inlining, thereby replacing the given invoke with the given
* {@code inlineGraph}.
*
* @param invoke the invoke that will be replaced
* @param inlineGraph the graph that the invoke will be replaced with
* @param receiverNullCheck true if a null check needs to be generated for non-static inlinings,
* false if no such check is required
* @param inlineeMethod the actual method being inlined. Maybe be null for snippets.
* @param reason the reason for inlining, used in tracing
* @param phase the phase that invoked inlining
*/
@SuppressWarnings("try")
public static UnmodifiableEconomicMap<Node, Node> inline(Invoke invoke, StructuredGraph inlineGraph, boolean receiverNullCheck, ResolvedJavaMethod inlineeMethod, String reason, String phase) {
FixedNode invokeNode = invoke.asNode();
StructuredGraph graph = invokeNode.graph();
final NodeInputList<ValueNode> parameters = invoke.callTarget().arguments();
assert inlineGraph.getGuardsStage().ordinal() >= graph.getGuardsStage().ordinal();
assert !invokeNode.graph().isAfterFloatingReadPhase() : "inline isn't handled correctly after floating reads phase";
if (receiverNullCheck && !((MethodCallTargetNode) invoke.callTarget()).isStatic()) {
nonNullReceiver(invoke);
}
ArrayList<Node> nodes = new ArrayList<>(inlineGraph.getNodes().count());
ArrayList<ReturnNode> returnNodes = new ArrayList<>(4);
ArrayList<Invoke> partialIntrinsicExits = new ArrayList<>();
UnwindNode unwindNode = null;
final StartNode entryPointNode = inlineGraph.start();
FixedNode firstCFGNode = entryPointNode.next();
if (firstCFGNode == null) {
throw new IllegalStateException("Inlined graph is in invalid state: " + inlineGraph);
}
for (Node node : inlineGraph.getNodes()) {
if (node == entryPointNode || (node == entryPointNode.stateAfter() && node.usages().count() == 1) || node instanceof ParameterNode) {
// Do nothing.
} else {
nodes.add(node);
if (node instanceof ReturnNode) {
returnNodes.add((ReturnNode) node);
} else if (node instanceof Invoke) {
Invoke invokeInInlineGraph = (Invoke) node;
if (invokeInInlineGraph.bci() == BytecodeFrame.UNKNOWN_BCI) {
ResolvedJavaMethod target1 = inlineeMethod;
ResolvedJavaMethod target2 = invokeInInlineGraph.callTarget().targetMethod();
assert target1.equals(target2) : String.format("invoke in inlined method expected to be partial intrinsic exit (i.e., call to %s), not a call to %s", target1.format("%H.%n(%p)"), target2.format("%H.%n(%p)"));
partialIntrinsicExits.add(invokeInInlineGraph);
}
} else if (node instanceof UnwindNode) {
assert unwindNode == null;
unwindNode = (UnwindNode) node;
}
}
}
final AbstractBeginNode prevBegin = AbstractBeginNode.prevBegin(invokeNode);
DuplicationReplacement localReplacement = new DuplicationReplacement() {
@Override
public Node replacement(Node node) {
if (node instanceof ParameterNode) {
return parameters.get(((ParameterNode) node).index());
} else if (node == entryPointNode) {
return prevBegin;
}
return node;
}
};
assert invokeNode.successors().first() != null : invoke;
assert invokeNode.predecessor() != null;
Mark mark = graph.getMark();
// Instead, attach the inlining log of the child graph to the current inlining log.
EconomicMap<Node, Node> duplicates;
try (InliningLog.UpdateScope scope = graph.getInliningLog().openDefaultUpdateScope()) {
duplicates = graph.addDuplicates(nodes, inlineGraph, inlineGraph.getNodeCount(), localReplacement);
if (scope != null) {
graph.getInliningLog().addDecision(invoke, true, reason, phase, duplicates, inlineGraph.getInliningLog());
}
}
FrameState stateAfter = invoke.stateAfter();
assert stateAfter == null || stateAfter.isAlive();
FrameState stateAtExceptionEdge = null;
if (invoke instanceof InvokeWithExceptionNode) {
InvokeWithExceptionNode invokeWithException = ((InvokeWithExceptionNode) invoke);
if (unwindNode != null) {
ExceptionObjectNode obj = (ExceptionObjectNode) invokeWithException.exceptionEdge();
stateAtExceptionEdge = obj.stateAfter();
}
}
updateSourcePositions(invoke, inlineGraph, duplicates, !Objects.equals(inlineGraph.method(), inlineeMethod), mark);
if (stateAfter != null) {
processFrameStates(invoke, inlineGraph, duplicates, stateAtExceptionEdge, returnNodes.size() > 1);
int callerLockDepth = stateAfter.nestedLockDepth();
if (callerLockDepth != 0) {
for (MonitorIdNode original : inlineGraph.getNodes(MonitorIdNode.TYPE)) {
MonitorIdNode monitor = (MonitorIdNode) duplicates.get(original);
processMonitorId(invoke.stateAfter(), monitor);
}
}
} else {
assert checkContainsOnlyInvalidOrAfterFrameState(duplicates);
}
firstCFGNode = (FixedNode) duplicates.get(firstCFGNode);
for (int i = 0; i < returnNodes.size(); i++) {
returnNodes.set(i, (ReturnNode) duplicates.get(returnNodes.get(i)));
}
for (Invoke exit : partialIntrinsicExits) {
// A partial intrinsic exit must be replaced with a call to
// the intrinsified method.
Invoke dup = (Invoke) duplicates.get(exit.asNode());
if (dup instanceof InvokeNode) {
InvokeNode repl = graph.add(new InvokeNode(invoke.callTarget(), invoke.bci()));
dup.intrinsify(repl.asNode());
} else {
((InvokeWithExceptionNode) dup).replaceWithNewBci(invoke.bci());
}
}
if (unwindNode != null) {
unwindNode = (UnwindNode) duplicates.get(unwindNode);
}
finishInlining(invoke, graph, firstCFGNode, returnNodes, unwindNode, inlineGraph.getAssumptions(), inlineGraph);
GraphUtil.killCFG(invokeNode);
return duplicates;
}
use of org.graalvm.compiler.nodes.UnwindNode in project graal by oracle.
the class ValueMergeUtil method mergeValueProducers.
public static <T> ValueNode mergeValueProducers(AbstractMergeNode merge, List<? extends T> valueProducers, Function<T, FixedWithNextNode> lastInstrFunction, Function<T, ValueNode> valueFunction) {
ValueNode singleResult = null;
PhiNode phiResult = null;
for (T valueProducer : valueProducers) {
ValueNode result = valueFunction.apply(valueProducer);
if (result != null) {
if (phiResult == null && (singleResult == null || singleResult == result)) {
/* Only one result value, so no need yet for a phi node. */
singleResult = result;
} else if (phiResult == null) {
/* Found a second result value, so create phi node. */
phiResult = merge.graph().addWithoutUnique(new ValuePhiNode(result.stamp(NodeView.DEFAULT).unrestricted(), merge));
for (int i = 0; i < merge.forwardEndCount(); i++) {
phiResult.addInput(singleResult);
}
phiResult.addInput(result);
} else {
/* Multiple return values, just add to existing phi node. */
phiResult.addInput(result);
}
}
// create and wire up a new EndNode
EndNode endNode = merge.graph().add(new EndNode());
merge.addForwardEnd(endNode);
if (lastInstrFunction == null) {
assert valueProducer instanceof ReturnNode || valueProducer instanceof UnwindNode;
((ControlSinkNode) valueProducer).replaceAndDelete(endNode);
} else {
FixedWithNextNode lastInstr = lastInstrFunction.apply(valueProducer);
lastInstr.setNext(endNode);
}
}
if (phiResult != null) {
assert phiResult.verify();
phiResult.inferStamp();
return phiResult;
} else {
return singleResult;
}
}
use of org.graalvm.compiler.nodes.UnwindNode in project graal by oracle.
the class ReflectionSubstitutionType method throwInvocationTargetException.
private static void throwInvocationTargetException(HostedGraphKit graphKit) {
ValueNode exception = graphKit.exceptionObject();
ResolvedJavaType exceptionType = graphKit.getMetaAccess().lookupJavaType(InvocationTargetException.class);
ValueNode ite = graphKit.append(new NewInstanceNode(exceptionType, true));
ResolvedJavaMethod cons = null;
for (ResolvedJavaMethod c : exceptionType.getDeclaredConstructors()) {
if (c.getSignature().getParameterCount(false) == 1) {
cons = c;
}
}
graphKit.createJavaCallWithExceptionAndUnwind(InvokeKind.Special, cons, ite, exception);
graphKit.append(new UnwindNode(ite));
}
use of org.graalvm.compiler.nodes.UnwindNode in project graal by oracle.
the class ReflectionSubstitutionType method throwIllegalArgumentException.
private static void throwIllegalArgumentException(HostedGraphKit graphKit, String message) {
ResolvedJavaType exceptionType = graphKit.getMetaAccess().lookupJavaType(IllegalArgumentException.class);
ValueNode ite = graphKit.append(new NewInstanceNode(exceptionType, true));
ResolvedJavaMethod cons = null;
for (ResolvedJavaMethod c : exceptionType.getDeclaredConstructors()) {
if (c.getSignature().getParameterCount(false) == 2) {
cons = c;
}
}
JavaConstant msg = graphKit.getConstantReflection().forString(message);
ValueNode msgNode = graphKit.createConstant(msg, JavaKind.Object);
ValueNode cause = graphKit.createConstant(JavaConstant.NULL_POINTER, JavaKind.Object);
graphKit.createJavaCallWithExceptionAndUnwind(InvokeKind.Special, cons, ite, msgNode, cause);
graphKit.append(new UnwindNode(ite));
}
Aggregations