402 throw unimplemented();
403 }
404
405 @Override
406 public String toString() {
407 Formatter fmt = new Formatter();
408 PEMethodScope scope = this.methodScope;
409 fmt.format("%s", new ResolvedJavaMethodBytecode(scope.method).asStackTraceElement(invoke.bci()));
410 NodeSourcePosition callers = scope.getCallerBytecodePosition();
411 if (callers != null) {
412 fmt.format("%n%s", callers);
413 }
414 return fmt.toString();
415 }
416 }
417
418 protected class PEAppendGraphBuilderContext extends PENonAppendGraphBuilderContext {
419 protected FixedWithNextNode lastInstr;
420 protected ValueNode pushedNode;
421 protected boolean invokeConsumed;
422
423 public PEAppendGraphBuilderContext(PEMethodScope inlineScope, FixedWithNextNode lastInstr) {
424 super(inlineScope, inlineScope.invokeData != null ? inlineScope.invokeData.invoke : null);
425 this.lastInstr = lastInstr;
426 }
427
428 @Override
429 public void push(JavaKind kind, ValueNode value) {
430 if (pushedNode != null) {
431 throw unimplemented("Only one push is supported");
432 }
433 pushedNode = value;
434 }
435
436 @Override
437 public void setStateAfter(StateSplit stateSplit) {
438 Node stateAfter = decodeFloatingNode(methodScope.caller, methodScope.callerLoopScope, methodScope.invokeData.stateAfterOrderId);
439 getGraph().add(stateAfter);
440 FrameState fs = (FrameState) handleFloatingNodeAfterAdd(methodScope.caller, methodScope.callerLoopScope, stateAfter);
441 stateSplit.setStateAfter(fs);
442 }
443
444 @SuppressWarnings("try")
445 @Override
466 return null;
467 }
468
469 private <T extends ValueNode> void updateLastInstruction(T v) {
470 if (v instanceof FixedNode) {
471 FixedNode fixedNode = (FixedNode) v;
472 if (lastInstr != null) {
473 lastInstr.setNext(fixedNode);
474 }
475 if (fixedNode instanceof FixedWithNextNode) {
476 FixedWithNextNode fixedWithNextNode = (FixedWithNextNode) fixedNode;
477 assert fixedWithNextNode.next() == null : "cannot append instruction to instruction which isn't end";
478 lastInstr = fixedWithNextNode;
479 } else {
480 lastInstr = null;
481 }
482 }
483 }
484
485 @Override
486 public void handleReplacedInvoke(CallTargetNode callTarget, JavaKind resultType) {
487 if (invokeConsumed) {
488 throw unimplemented("handleReplacedInvoke can be called only once");
489 }
490 invokeConsumed = true;
491
492 appendInvoke(methodScope.caller, methodScope.callerLoopScope, methodScope.invokeData, callTarget);
493 updateLastInstruction(invoke.asNode());
494 }
495 }
496
497 @NodeInfo(cycles = CYCLES_IGNORED, size = SIZE_IGNORED)
498 static class ExceptionPlaceholderNode extends ValueNode {
499 public static final NodeClass<ExceptionPlaceholderNode> TYPE = NodeClass.create(ExceptionPlaceholderNode.class);
500
501 protected ExceptionPlaceholderNode() {
502 super(TYPE, StampFactory.object());
503 }
504 }
505
710 return false;
711 }
712
713 Invoke invoke = invokeData.invoke;
714
715 ResolvedJavaMethod targetMethod = callTarget.targetMethod();
716 InvocationPlugin invocationPlugin = getInvocationPlugin(targetMethod);
717 if (invocationPlugin == null) {
718 return false;
719 }
720
721 ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
722 FixedWithNextNode invokePredecessor = (FixedWithNextNode) invoke.asNode().predecessor();
723
724 /*
725 * Remove invoke from graph so that invocation plugin can append nodes to the predecessor.
726 */
727 invoke.asNode().replaceAtPredecessor(null);
728
729 PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, null, targetMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
730 PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, invokePredecessor);
731 InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(graphBuilderContext);
732
733 if (invocationPlugin.execute(graphBuilderContext, targetMethod, invocationPluginReceiver.init(targetMethod, arguments), arguments)) {
734
735 if (graphBuilderContext.invokeConsumed) {
736 /* Nothing to do. */
737 } else if (graphBuilderContext.lastInstr != null) {
738 registerNode(loopScope, invokeData.invokeOrderId, graphBuilderContext.pushedNode, true, true);
739 invoke.asNode().replaceAtUsages(graphBuilderContext.pushedNode);
740 graphBuilderContext.lastInstr.setNext(nodeAfterInvoke(methodScope, loopScope, invokeData, AbstractBeginNode.prevBegin(graphBuilderContext.lastInstr)));
741 deleteInvoke(invoke);
742 } else {
743 assert graphBuilderContext.pushedNode == null : "Why push a node when the invoke does not return anyway?";
744 invoke.asNode().replaceAtUsages(null);
745 deleteInvoke(invoke);
746 }
747 return true;
748
749 } else {
750 /* Intrinsification failed, restore original state: invoke is in Graph. */
|
402 throw unimplemented();
403 }
404
405 @Override
406 public String toString() {
407 Formatter fmt = new Formatter();
408 PEMethodScope scope = this.methodScope;
409 fmt.format("%s", new ResolvedJavaMethodBytecode(scope.method).asStackTraceElement(invoke.bci()));
410 NodeSourcePosition callers = scope.getCallerBytecodePosition();
411 if (callers != null) {
412 fmt.format("%n%s", callers);
413 }
414 return fmt.toString();
415 }
416 }
417
418 protected class PEAppendGraphBuilderContext extends PENonAppendGraphBuilderContext {
419 protected FixedWithNextNode lastInstr;
420 protected ValueNode pushedNode;
421 protected boolean invokeConsumed;
422 protected final InvokeKind invokeKind;
423 protected final JavaType invokeReturnType;
424
425 public PEAppendGraphBuilderContext(PEMethodScope inlineScope, FixedWithNextNode lastInstr) {
426 this(inlineScope, lastInstr, null, null);
427 }
428
429 public PEAppendGraphBuilderContext(PEMethodScope inlineScope, FixedWithNextNode lastInstr, InvokeKind invokeKind, JavaType invokeReturnType) {
430 super(inlineScope, inlineScope.invokeData != null ? inlineScope.invokeData.invoke : null);
431 this.lastInstr = lastInstr;
432 this.invokeKind = invokeKind;
433 this.invokeReturnType = invokeReturnType;
434 }
435
436 @Override
437 public void push(JavaKind kind, ValueNode value) {
438 if (pushedNode != null) {
439 throw unimplemented("Only one push is supported");
440 }
441 pushedNode = value;
442 }
443
444 @Override
445 public void setStateAfter(StateSplit stateSplit) {
446 Node stateAfter = decodeFloatingNode(methodScope.caller, methodScope.callerLoopScope, methodScope.invokeData.stateAfterOrderId);
447 getGraph().add(stateAfter);
448 FrameState fs = (FrameState) handleFloatingNodeAfterAdd(methodScope.caller, methodScope.callerLoopScope, stateAfter);
449 stateSplit.setStateAfter(fs);
450 }
451
452 @SuppressWarnings("try")
453 @Override
474 return null;
475 }
476
477 private <T extends ValueNode> void updateLastInstruction(T v) {
478 if (v instanceof FixedNode) {
479 FixedNode fixedNode = (FixedNode) v;
480 if (lastInstr != null) {
481 lastInstr.setNext(fixedNode);
482 }
483 if (fixedNode instanceof FixedWithNextNode) {
484 FixedWithNextNode fixedWithNextNode = (FixedWithNextNode) fixedNode;
485 assert fixedWithNextNode.next() == null : "cannot append instruction to instruction which isn't end";
486 lastInstr = fixedWithNextNode;
487 } else {
488 lastInstr = null;
489 }
490 }
491 }
492
493 @Override
494 public InvokeKind getInvokeKind() {
495 if (invokeKind != null) {
496 return invokeKind;
497 }
498 return super.getInvokeKind();
499 }
500
501 @Override
502 public JavaType getInvokeReturnType() {
503 if (invokeReturnType != null) {
504 return invokeReturnType;
505 }
506 return super.getInvokeReturnType();
507 }
508
509 @Override
510 public void handleReplacedInvoke(CallTargetNode callTarget, JavaKind resultType) {
511 if (invokeConsumed) {
512 throw unimplemented("handleReplacedInvoke can be called only once");
513 }
514 invokeConsumed = true;
515
516 appendInvoke(methodScope.caller, methodScope.callerLoopScope, methodScope.invokeData, callTarget);
517 updateLastInstruction(invoke.asNode());
518 }
519 }
520
521 @NodeInfo(cycles = CYCLES_IGNORED, size = SIZE_IGNORED)
522 static class ExceptionPlaceholderNode extends ValueNode {
523 public static final NodeClass<ExceptionPlaceholderNode> TYPE = NodeClass.create(ExceptionPlaceholderNode.class);
524
525 protected ExceptionPlaceholderNode() {
526 super(TYPE, StampFactory.object());
527 }
528 }
529
734 return false;
735 }
736
737 Invoke invoke = invokeData.invoke;
738
739 ResolvedJavaMethod targetMethod = callTarget.targetMethod();
740 InvocationPlugin invocationPlugin = getInvocationPlugin(targetMethod);
741 if (invocationPlugin == null) {
742 return false;
743 }
744
745 ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
746 FixedWithNextNode invokePredecessor = (FixedWithNextNode) invoke.asNode().predecessor();
747
748 /*
749 * Remove invoke from graph so that invocation plugin can append nodes to the predecessor.
750 */
751 invoke.asNode().replaceAtPredecessor(null);
752
753 PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, null, targetMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
754
755 JavaType returnType = targetMethod.getSignature().getReturnType(methodScope.method.getDeclaringClass());
756 PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, invokePredecessor, callTarget.invokeKind(), returnType);
757 InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(graphBuilderContext);
758
759 if (invocationPlugin.execute(graphBuilderContext, targetMethod, invocationPluginReceiver.init(targetMethod, arguments), arguments)) {
760
761 if (graphBuilderContext.invokeConsumed) {
762 /* Nothing to do. */
763 } else if (graphBuilderContext.lastInstr != null) {
764 registerNode(loopScope, invokeData.invokeOrderId, graphBuilderContext.pushedNode, true, true);
765 invoke.asNode().replaceAtUsages(graphBuilderContext.pushedNode);
766 graphBuilderContext.lastInstr.setNext(nodeAfterInvoke(methodScope, loopScope, invokeData, AbstractBeginNode.prevBegin(graphBuilderContext.lastInstr)));
767 deleteInvoke(invoke);
768 } else {
769 assert graphBuilderContext.pushedNode == null : "Why push a node when the invoke does not return anyway?";
770 invoke.asNode().replaceAtUsages(null);
771 deleteInvoke(invoke);
772 }
773 return true;
774
775 } else {
776 /* Intrinsification failed, restore original state: invoke is in Graph. */
|