|
35 | 35 | import java.util.List; |
36 | 36 | import java.util.Objects; |
37 | 37 | import java.util.Set; |
| 38 | +import java.util.stream.StreamSupport; |
38 | 39 |
|
39 | 40 | import org.graalvm.collections.Pair; |
40 | 41 | import org.graalvm.collections.UnmodifiableEconomicMap; |
@@ -778,7 +779,7 @@ private ValueNode[] nodes(List<ValueNode> oNodes) throws AbortTransplantExceptio |
778 | 779 | return tNodes; |
779 | 780 | } |
780 | 781 |
|
781 | | - private ValueNode node(ValueNode oNode) throws AbortTransplantException { |
| 782 | + private ValueNode node(Node oNode) throws AbortTransplantException { |
782 | 783 | if (oNode == null) { |
783 | 784 | return null; |
784 | 785 | } |
@@ -812,16 +813,28 @@ private ValueNode node(ValueNode oNode) throws AbortTransplantException { |
812 | 813 | * have side effects and also do not reference any types or other elements that we |
813 | 814 | * would need to modify. |
814 | 815 | */ |
| 816 | + for (Node input : oNode.inputs()) { |
| 817 | + /* |
| 818 | + * Make sure all input nodes are transplanted first, and registered in the |
| 819 | + * transplanted map. |
| 820 | + */ |
| 821 | + node(input); |
| 822 | + } |
815 | 823 | List<Node> oNodes = Collections.singletonList(oNode); |
816 | 824 | UnmodifiableEconomicMap<Node, Node> tNodes = b.getGraph().addDuplicates(oNodes, oNode.graph(), 1, transplanted); |
817 | | - assert tNodes.size() == 1; |
| 825 | + /* |
| 826 | + * The following assertion looks strange, but NodeMap.size() is not implemented so |
| 827 | + * we need to iterate the map to get the size. |
| 828 | + */ |
| 829 | + assert StreamSupport.stream(tNodes.getKeys().spliterator(), false).count() == 1; |
818 | 830 | tNode = tNodes.get(oNode); |
819 | 831 |
|
820 | 832 | } else { |
821 | 833 | throw bailout(); |
822 | 834 | } |
823 | 835 |
|
824 | 836 | tNode = b.add((ValueNode) tNode); |
| 837 | + assert tNode.verify(); |
825 | 838 | transplanted.put(oNode, tNode); |
826 | 839 | return (ValueNode) tNode; |
827 | 840 | } |
|
0 commit comments