82
83 public static void main(String[] args) {
84 // Must use G1 GC to ensure there is a pre-barrier
85 // before the first field write.
86 TestFramework.runWithFlags("-XX:+UseG1GC");
87 }
88
89 @Run(test = "testScalarReplacementWithGCBarrier")
90 private void runner() {
91 List list = new List();
92 for (int i = 0; i < SIZE; i++) {
93 list.push(i);
94 }
95 testScalarReplacementWithGCBarrier(list);
96 }
97
98 // Allocation of `Iter iter` should be eliminated by scalar replacement, and
99 // the allocation of `Integer sum` can not be eliminated, so there should be
100 // 1 allocation after allocations and locks elimination.
101 //
102 // Before the patch of JDK-8333334, both allocations of `Iter` and `Integer`
103 // could not be eliminated.
104 @Test
105 @IR(phase = { CompilePhase.AFTER_PARSING }, counts = { IRNode.ALLOC, "1" })
106 @IR(phase = { CompilePhase.INCREMENTAL_BOXING_INLINE }, counts = { IRNode.ALLOC, "2" })
107 @IR(phase = { CompilePhase.ITER_GVN_AFTER_ELIMINATION }, counts = { IRNode.ALLOC, "1" })
108 private int testScalarReplacementWithGCBarrier(List list) {
109 Iter iter = list.iter();
110 while (true) {
111 while (iter.next()) {}
112 if (list.head == null) break;
113 list.head = list.head.next;
114 iter.n = list.head;
115 }
116 return iter.sum;
117 }
118 }
|
82
83 public static void main(String[] args) {
84 // Must use G1 GC to ensure there is a pre-barrier
85 // before the first field write.
86 TestFramework.runWithFlags("-XX:+UseG1GC");
87 }
88
89 @Run(test = "testScalarReplacementWithGCBarrier")
90 private void runner() {
91 List list = new List();
92 for (int i = 0; i < SIZE; i++) {
93 list.push(i);
94 }
95 testScalarReplacementWithGCBarrier(list);
96 }
97
98 // Allocation of `Iter iter` should be eliminated by scalar replacement, and
99 // the allocation of `Integer sum` can not be eliminated, so there should be
100 // 1 allocation after allocations and locks elimination.
101 //
102 // With Valhalla, when Integer is a value class, we have only one allocation
103 // at first (Iter), which goes away.
104 //
105 // Before the patch of JDK-8333334, both allocations of `Iter` and `Integer`
106 // could not be eliminated.
107 @Test
108 @IR(applyIf = {"enable-valhalla", "false"}, phase = { CompilePhase.PHASEIDEAL_BEFORE_EA }, counts = { IRNode.ALLOC, "2" })
109 @IR(applyIf = {"enable-valhalla", "false"}, phase = { CompilePhase.ITER_GVN_AFTER_ELIMINATION }, counts = { IRNode.ALLOC, "1"})
110 @IR(applyIf = {"enable-valhalla", "true"}, phase = { CompilePhase.PHASEIDEAL_BEFORE_EA }, counts = { IRNode.ALLOC, "1" })
111 @IR(applyIf = {"enable-valhalla", "true"}, phase = { CompilePhase.ITER_GVN_AFTER_ELIMINATION }, failOn = { IRNode.ALLOC })
112 private int testScalarReplacementWithGCBarrier(List list) {
113 Iter iter = list.iter();
114 while (true) {
115 while (iter.next()) {}
116 if (list.head == null) break;
117 list.head = list.head.next;
118 iter.n = list.head;
119 }
120 return iter.sum;
121 }
122 }
|