use of org.graalvm.compiler.nodes.DeoptBciSupplier in project graal by oracle.
the class PEGraphDecoder method tryInvocationPlugin.
@SuppressWarnings("try")
protected boolean tryInvocationPlugin(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
try (DebugCloseable a = InvocationPluginTimer.start(debug)) {
if (invocationPlugins == null || invocationPlugins.isEmpty()) {
return false;
}
if (!callTarget.invokeKind().isDirect()) {
/*
* Like method inlining, method intrinsification using InvocationPlugin can only
* handle direct calls. Indirect calls can only be intrinsified by a NodePlugin (and
* currently only during bytecode parsing and not during partial evaluation).
*/
return false;
}
Invoke invoke = invokeData.invoke;
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
if (loopScope.methodScope.encodedGraph.isCallToOriginal(targetMethod)) {
return false;
}
InvocationPlugin invocationPlugin = getInvocationPlugin(targetMethod);
if (invocationPlugin == null) {
return false;
}
if (loopScope.methodScope.encodedGraph.isCallToOriginal(targetMethod)) {
return false;
}
ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
FixedWithNextNode invokePredecessor = (FixedWithNextNode) invoke.asNode().predecessor();
/*
* Remove invoke from graph so that invocation plugin can append nodes to the
* predecessor.
*/
invoke.asNode().replaceAtPredecessor(null);
PEMethodScope inlineScope = createMethodScope(graph, methodScope, loopScope, null, targetMethod, invokeData, methodScope.inliningDepth + 1, arguments);
JavaType returnType = targetMethod.getSignature().getReturnType(methodScope.method.getDeclaringClass());
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, invokePredecessor, callTarget.invokeKind(), returnType, true);
InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(graphBuilderContext);
if (invocationPlugin.execute(graphBuilderContext, targetMethod, invocationPluginReceiver.init(targetMethod, arguments), arguments)) {
if (graphBuilderContext.invokeConsumed) {
/* Nothing to do. */
} else if (graphBuilderContext.lastInstr != null) {
if (graphBuilderContext.lastInstr instanceof DeoptBciSupplier && !BytecodeFrame.isPlaceholderBci(invokeData.invoke.bci()) && BytecodeFrame.isPlaceholderBci(((DeoptBciSupplier) graphBuilderContext.lastInstr).bci())) {
((DeoptBciSupplier) graphBuilderContext.lastInstr).setBci(invokeData.invoke.bci());
}
registerNode(loopScope, invokeData.invokeOrderId, graphBuilderContext.pushedNode, true, true);
invoke.asNode().replaceAtUsages(graphBuilderContext.pushedNode);
BeginNode begin = graphBuilderContext.lastInstr instanceof BeginNode ? (BeginNode) graphBuilderContext.lastInstr : null;
FixedNode afterInvoke = nodeAfterInvoke(methodScope, loopScope, invokeData, begin);
if (afterInvoke != graphBuilderContext.lastInstr) {
graphBuilderContext.lastInstr.setNext(afterInvoke);
}
deleteInvoke(invoke);
} else {
assert graphBuilderContext.pushedNode == null : "Why push a node when the invoke does not return anyway?";
invoke.asNode().replaceAtUsages(null);
deleteInvoke(invoke);
}
return true;
} else {
/* Intrinsification failed, restore original state: invoke is in Graph. */
invokePredecessor.setNext(invoke.asFixedNode());
return false;
}
}
}
use of org.graalvm.compiler.nodes.DeoptBciSupplier in project graal by oracle.
the class PlaceholderLogicNode method assignNecessaryFrameStates.
private void assignNecessaryFrameStates(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates, FixedNode replaceeGraphCFGPredecessor) {
FrameState stateAfter = null;
if (replacee instanceof StateSplit && ((StateSplit) replacee).hasSideEffect()) {
stateAfter = ((StateSplit) replacee).stateAfter();
GraalError.guarantee(stateAfter != null, "Statesplit with side-effect %s needs a framestate", replacee);
} else {
/*
* We dont have a state split as a replacee, thus we take the prev state as the state
* after for the node in the snippet.
*/
stateAfter = GraphUtil.findLastFrameState(replaceeGraphCFGPredecessor);
}
final ExceptionObjectNode exceptionObject;
if (replacee instanceof WithExceptionNode) {
WithExceptionNode withExceptionNode = (WithExceptionNode) replacee;
if (withExceptionNode.exceptionEdge() instanceof ExceptionObjectNode) {
exceptionObject = (ExceptionObjectNode) withExceptionNode.exceptionEdge();
} else {
GraalError.guarantee(withExceptionNode.exceptionEdge() instanceof UnreachableBeginNode, "Unexpected exception edge %s", withExceptionNode.exceptionEdge());
exceptionObject = null;
}
} else {
exceptionObject = null;
}
NodeMap<NodeStateAssignment> assignedStateMappings = frameStateAssignment.getStateMapping();
MapCursor<Node, NodeStateAssignment> stateAssignments = assignedStateMappings.getEntries();
while (stateAssignments.advance()) {
Node nodeRequiringState = stateAssignments.getKey();
if (nodeRequiringState instanceof DeoptBciSupplier) {
if (replacee instanceof DeoptBciSupplier) {
((DeoptBciSupplier) duplicates.get(nodeRequiringState)).setBci(((DeoptBciSupplier) replacee).bci());
}
}
NodeStateAssignment assignment = stateAssignments.getValue();
switch(assignment) {
case AFTER_BCI:
setReplaceeGraphStateAfter(nodeRequiringState, replacee, duplicates, stateAfter);
break;
case AFTER_EXCEPTION_BCI:
if (nodeRequiringState instanceof ExceptionObjectNode) {
ExceptionObjectNode newExceptionObject = (ExceptionObjectNode) duplicates.get(nodeRequiringState);
rewireExceptionFrameState(exceptionObject, newExceptionObject, newExceptionObject);
} else if (nodeRequiringState instanceof MergeNode) {
MergeNode mergeNode = (MergeNode) duplicates.get(nodeRequiringState);
rewireExceptionFrameState(exceptionObject, getExceptionValueFromMerge(mergeNode), mergeNode);
} else {
GraalError.shouldNotReachHere("Unexpected exception state node: " + nodeRequiringState);
}
break;
case BEFORE_BCI:
FrameState stateBeforeSnippet = GraphUtil.findLastFrameState(replaceeGraphCFGPredecessor);
((StateSplit) duplicates.get(nodeRequiringState)).setStateAfter(stateBeforeSnippet.duplicate());
break;
case INVALID:
/*
* We cannot assign a proper frame state for this snippet's node since there are
* effects which cannot be represented by a single state at the node
*/
throw GraalError.shouldNotReachHere("Invalid snippet replacing a node before frame state assignment with node " + nodeRequiringState + " for replacee " + replacee);
default:
throw GraalError.shouldNotReachHere("Unknown StateAssigment:" + assignment);
}
replacee.graph().getDebug().dump(DebugContext.VERY_DETAILED_LEVEL, replacee.graph(), "After duplicating after state for node %s in snippet", duplicates.get(nodeRequiringState));
}
}
Aggregations