336 public int getDepth() {
337 return methodScope.inliningDepth;
338 }
339
340 @Override
341 public IntrinsicContext getIntrinsic() {
342 return null;
343 }
344
345 @Override
346 public <T extends ValueNode> T append(T value) {
347 throw unimplemented();
348 }
349
350 @Override
351 public void push(JavaKind kind, ValueNode value) {
352 throw unimplemented();
353 }
354
355 @Override
356 public void handleReplacedInvoke(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, boolean inlineEverything) {
357 throw unimplemented();
358 }
359
360 @Override
361 public void handleReplacedInvoke(CallTargetNode callTarget, JavaKind resultType) {
362 throw unimplemented();
363 }
364
365 @Override
366 public boolean intrinsify(BytecodeProvider bytecodeProvider, ResolvedJavaMethod targetMethod, ResolvedJavaMethod substitute, InvocationPlugin.Receiver receiver, ValueNode[] args) {
367 return false;
368 }
369
370 @Override
371 public void setStateAfter(StateSplit stateSplit) {
372 throw unimplemented();
373 }
374
375 @Override
376 public GraphBuilderContext getParent() {
572 super(architecture, graph, metaAccess, constantReflection, constantFieldProvider, stampProvider, true);
573 this.loopExplosionPlugin = loopExplosionPlugin;
574 this.invocationPlugins = invocationPlugins;
575 this.inlineInvokePlugins = inlineInvokePlugins;
576 this.parameterPlugin = parameterPlugin;
577 this.nodePlugins = nodePlugins;
578 this.specialCallTargetCache = EconomicMap.create(Equivalence.DEFAULT);
579 this.invocationPluginCache = EconomicMap.create(Equivalence.DEFAULT);
580 this.callInlinedMethod = callInlinedMethod;
581 this.sourceLanguagePositionProvider = sourceLanguagePositionProvider;
582 }
583
584 protected static LoopExplosionKind loopExplosionKind(ResolvedJavaMethod method, LoopExplosionPlugin loopExplosionPlugin) {
585 if (loopExplosionPlugin == null) {
586 return LoopExplosionKind.NONE;
587 } else {
588 return loopExplosionPlugin.loopExplosionKind(method);
589 }
590 }
591
592 public void decode(ResolvedJavaMethod method, boolean isSubstitution, boolean trackNodeSourcePosition) {
593 PEMethodScope methodScope = new PEMethodScope(graph, null, null, lookupEncodedGraph(method, null, null, isSubstitution, trackNodeSourcePosition), method, null, 0, loopExplosionPlugin, null);
594 decode(createInitialLoopScope(methodScope, null));
595 cleanupGraph(methodScope);
596
597 debug.dump(DebugContext.VERBOSE_LEVEL, graph, "After graph cleanup");
598 assert graph.verify();
599
600 try {
601 /* Check that the control flow graph can be computed, to catch problems early. */
602 assert CFGVerifier.verify(ControlFlowGraph.compute(graph, true, true, true, true));
603 } catch (Throwable ex) {
604 throw GraalError.shouldNotReachHere("Control flow graph not valid after partial evaluation");
605 }
606 }
607
608 @Override
609 protected void cleanupGraph(MethodScope methodScope) {
610 super.cleanupGraph(methodScope);
611
612 for (FrameState frameState : graph.getNodes(FrameState.TYPE)) {
613 if (frameState.bci == BytecodeFrame.UNWIND_BCI) {
614 /*
615 * handleMissingAfterExceptionFrameState is called during graph decoding from
616 * InliningUtil.processFrameState - but during graph decoding it does not do
617 * anything because the usages of the frameState are not available yet. So we need
618 * to call it again.
720 if (specialCallTarget == null) {
721 specialCallTarget = MethodCallTargetNode.devirtualizeCall(key.invokeKind, key.targetMethod, key.contextType, graph.getAssumptions(),
722 key.receiverStamp);
723 if (specialCallTarget == null) {
724 specialCallTarget = CACHED_NULL_VALUE;
725 }
726 specialCallTargetCache.put(key, specialCallTarget);
727 }
728
729 return specialCallTarget == CACHED_NULL_VALUE ? null : (ResolvedJavaMethod) specialCallTarget;
730 }
731
732 protected boolean tryInvocationPlugin(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
733 if (invocationPlugins == null || invocationPlugins.isEmpty()) {
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) {
|
336 public int getDepth() {
337 return methodScope.inliningDepth;
338 }
339
340 @Override
341 public IntrinsicContext getIntrinsic() {
342 return null;
343 }
344
345 @Override
346 public <T extends ValueNode> T append(T value) {
347 throw unimplemented();
348 }
349
350 @Override
351 public void push(JavaKind kind, ValueNode value) {
352 throw unimplemented();
353 }
354
355 @Override
356 public Invoke handleReplacedInvoke(InvokeKind invokeKind, ResolvedJavaMethod targetMethod, ValueNode[] args, boolean inlineEverything) {
357 throw unimplemented();
358 }
359
360 @Override
361 public void handleReplacedInvoke(CallTargetNode callTarget, JavaKind resultType) {
362 throw unimplemented();
363 }
364
365 @Override
366 public boolean intrinsify(BytecodeProvider bytecodeProvider, ResolvedJavaMethod targetMethod, ResolvedJavaMethod substitute, InvocationPlugin.Receiver receiver, ValueNode[] args) {
367 return false;
368 }
369
370 @Override
371 public void setStateAfter(StateSplit stateSplit) {
372 throw unimplemented();
373 }
374
375 @Override
376 public GraphBuilderContext getParent() {
572 super(architecture, graph, metaAccess, constantReflection, constantFieldProvider, stampProvider, true);
573 this.loopExplosionPlugin = loopExplosionPlugin;
574 this.invocationPlugins = invocationPlugins;
575 this.inlineInvokePlugins = inlineInvokePlugins;
576 this.parameterPlugin = parameterPlugin;
577 this.nodePlugins = nodePlugins;
578 this.specialCallTargetCache = EconomicMap.create(Equivalence.DEFAULT);
579 this.invocationPluginCache = EconomicMap.create(Equivalence.DEFAULT);
580 this.callInlinedMethod = callInlinedMethod;
581 this.sourceLanguagePositionProvider = sourceLanguagePositionProvider;
582 }
583
584 protected static LoopExplosionKind loopExplosionKind(ResolvedJavaMethod method, LoopExplosionPlugin loopExplosionPlugin) {
585 if (loopExplosionPlugin == null) {
586 return LoopExplosionKind.NONE;
587 } else {
588 return loopExplosionPlugin.loopExplosionKind(method);
589 }
590 }
591
592 @SuppressWarnings("try")
593 public void decode(ResolvedJavaMethod method, boolean isSubstitution, boolean trackNodeSourcePosition) {
594 try (DebugContext.Scope scope = debug.scope("PEGraphDecode", graph)) {
595 EncodedGraph encodedGraph = lookupEncodedGraph(method, null, null, isSubstitution, trackNodeSourcePosition);
596 PEMethodScope methodScope = new PEMethodScope(graph, null, null, encodedGraph, method, null, 0, loopExplosionPlugin, null);
597 decode(createInitialLoopScope(methodScope, null));
598 cleanupGraph(methodScope);
599
600 debug.dump(DebugContext.VERBOSE_LEVEL, graph, "After graph cleanup");
601 assert graph.verify();
602 } catch (Throwable t) {
603 throw debug.handle(t);
604 }
605
606 try {
607 /* Check that the control flow graph can be computed, to catch problems early. */
608 assert CFGVerifier.verify(ControlFlowGraph.compute(graph, true, true, true, true));
609 } catch (Throwable ex) {
610 throw GraalError.shouldNotReachHere("Control flow graph not valid after partial evaluation");
611 }
612 }
613
614 @Override
615 protected void cleanupGraph(MethodScope methodScope) {
616 super.cleanupGraph(methodScope);
617
618 for (FrameState frameState : graph.getNodes(FrameState.TYPE)) {
619 if (frameState.bci == BytecodeFrame.UNWIND_BCI) {
620 /*
621 * handleMissingAfterExceptionFrameState is called during graph decoding from
622 * InliningUtil.processFrameState - but during graph decoding it does not do
623 * anything because the usages of the frameState are not available yet. So we need
624 * to call it again.
726 if (specialCallTarget == null) {
727 specialCallTarget = MethodCallTargetNode.devirtualizeCall(key.invokeKind, key.targetMethod, key.contextType, graph.getAssumptions(),
728 key.receiverStamp);
729 if (specialCallTarget == null) {
730 specialCallTarget = CACHED_NULL_VALUE;
731 }
732 specialCallTargetCache.put(key, specialCallTarget);
733 }
734
735 return specialCallTarget == CACHED_NULL_VALUE ? null : (ResolvedJavaMethod) specialCallTarget;
736 }
737
738 protected boolean tryInvocationPlugin(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
739 if (invocationPlugins == null || invocationPlugins.isEmpty()) {
740 return false;
741 }
742
743 Invoke invoke = invokeData.invoke;
744
745 ResolvedJavaMethod targetMethod = callTarget.targetMethod();
746 if (loopScope.methodScope.encodedGraph.isCallToOriginal(targetMethod)) {
747 return false;
748 }
749
750 InvocationPlugin invocationPlugin = getInvocationPlugin(targetMethod);
751 if (invocationPlugin == null) {
752 return false;
753 }
754
755 if (loopScope.methodScope.encodedGraph.isCallToOriginal(targetMethod)) {
756 return false;
757 }
758
759 ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
760 FixedWithNextNode invokePredecessor = (FixedWithNextNode) invoke.asNode().predecessor();
761
762 /*
763 * Remove invoke from graph so that invocation plugin can append nodes to the predecessor.
764 */
765 invoke.asNode().replaceAtPredecessor(null);
766
767 PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, null, targetMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
768
769 JavaType returnType = targetMethod.getSignature().getReturnType(methodScope.method.getDeclaringClass());
770 PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, invokePredecessor, callTarget.invokeKind(), returnType);
771 InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(graphBuilderContext);
772
773 if (invocationPlugin.execute(graphBuilderContext, targetMethod, invocationPluginReceiver.init(targetMethod, arguments), arguments)) {
774
775 if (graphBuilderContext.invokeConsumed) {
|