12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package compiler.gcbarriers;
25
26 import compiler.lib.ir_framework.*;
27 import java.lang.invoke.VarHandle;
28 import java.lang.invoke.MethodHandles;
29 import java.util.concurrent.ThreadLocalRandom;
30
31 /**
32 * @test
33 * @summary Test that the ZGC barrier elision optimization does not elide
34 * necessary barriers. The tests use volatile memory accesses and
35 * blackholes to prevent C2 from simply optimizing them away.
36 * @library /test/lib /
37 * @requires vm.gc.ZGenerational
38 * @run driver compiler.gcbarriers.TestZGCBarrierElision test-correctness
39 */
40
41 /**
42 * @test
43 * @summary Test that the ZGC barrier elision optimization elides unnecessary
44 * barriers following simple allocation and domination rules.
45 * @library /test/lib /
46 * @requires vm.gc.ZGenerational & (vm.simpleArch == "x64" | vm.simpleArch == "aarch64")
47 * @run driver compiler.gcbarriers.TestZGCBarrierElision test-effectiveness
48 */
49
50 class Inner {}
51
52 class Outer {
53 volatile Inner field1;
54 volatile Inner field2;
55 Outer() {}
56 }
57
58 class Common {
59
60 static Inner inner = new Inner();
61 static Outer outer = new Outer();
62 static Outer outer2 = new Outer();
178 Common.nonInlinedMethod();
179 o.field1 = i;
180 }
181
182 @Run(test = {"testConditionalStoreThenStore",
183 "testStoreThenCallThenStore"})
184 void runControlFlowTests() {
185 testConditionalStoreThenStore(Common.outer, Common.inner, ThreadLocalRandom.current().nextInt(0, 100));
186 testStoreThenCallThenStore(Common.outer, Common.inner);
187 }
188
189 @Test
190 @IR(counts = { IRNode.Z_GET_AND_SET_P_WITH_BARRIER_FLAG, Common.REMAINING, "1" }, phase = CompilePhase.FINAL_CODE)
191 static void testAllocateThenAtomic(Inner i) {
192 Outer o = new Outer();
193 Common.blackhole(o);
194 Common.field1VarHandle.getAndSet(o, i);
195 }
196
197 @Test
198 @IR(counts = { IRNode.Z_LOAD_P_WITH_BARRIER_FLAG, Common.REMAINING, "1" }, phase = CompilePhase.FINAL_CODE)
199 @IR(counts = { IRNode.Z_GET_AND_SET_P_WITH_BARRIER_FLAG, Common.REMAINING, "1" }, phase = CompilePhase.FINAL_CODE)
200 static void testLoadThenAtomic(Outer o, Inner i) {
201 Common.blackhole(o.field1);
202 Common.field1VarHandle.getAndSet(o, i);
203 }
204
205 @Test
206 @IR(counts = { IRNode.Z_GET_AND_SET_P_WITH_BARRIER_FLAG, Common.REMAINING, "2" }, phase = CompilePhase.FINAL_CODE)
207 static void testAtomicThenAtomicAnotherField(Outer o, Inner i) {
208 Common.field1VarHandle.getAndSet(o, i);
209 Common.field2VarHandle.getAndSet(o, i);
210 }
211
212 @Test
213 @IR(counts = { IRNode.Z_GET_AND_SET_P_WITH_BARRIER_FLAG, Common.REMAINING, "1" }, phase = CompilePhase.FINAL_CODE)
214 static void testAllocateArrayThenAtomicAtKnownIndex(Outer o) {
215 Outer[] a = new Outer[42];
216 Common.blackhole(a);
217 Common.outerArrayVarHandle.getAndSet(a, 2, o);
218 }
|
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 package compiler.gcbarriers;
25
26 import compiler.lib.ir_framework.*;
27 import java.lang.invoke.VarHandle;
28 import java.lang.invoke.MethodHandles;
29 import java.util.concurrent.ThreadLocalRandom;
30
31 /**
32 * @test id=Z
33 * @summary Test that the ZGC barrier elision optimization does not elide
34 * necessary barriers. The tests use volatile memory accesses and
35 * blackholes to prevent C2 from simply optimizing them away.
36 * @library /test/lib /
37 * @requires vm.gc.ZGenerational
38 * @run driver compiler.gcbarriers.TestZGCBarrierElision test-correctness
39 */
40
41 /**
42 * @test id=ZGen
43 * @summary Test that the ZGC barrier elision optimization elides unnecessary
44 * barriers following simple allocation and domination rules.
45 * @library /test/lib /
46 * @requires vm.gc.ZGenerational & (vm.simpleArch == "x64" | vm.simpleArch == "aarch64")
47 * @run driver compiler.gcbarriers.TestZGCBarrierElision test-effectiveness
48 */
49
50 class Inner {}
51
52 class Outer {
53 volatile Inner field1;
54 volatile Inner field2;
55 Outer() {}
56 }
57
58 class Common {
59
60 static Inner inner = new Inner();
61 static Outer outer = new Outer();
62 static Outer outer2 = new Outer();
178 Common.nonInlinedMethod();
179 o.field1 = i;
180 }
181
182 @Run(test = {"testConditionalStoreThenStore",
183 "testStoreThenCallThenStore"})
184 void runControlFlowTests() {
185 testConditionalStoreThenStore(Common.outer, Common.inner, ThreadLocalRandom.current().nextInt(0, 100));
186 testStoreThenCallThenStore(Common.outer, Common.inner);
187 }
188
189 @Test
190 @IR(counts = { IRNode.Z_GET_AND_SET_P_WITH_BARRIER_FLAG, Common.REMAINING, "1" }, phase = CompilePhase.FINAL_CODE)
191 static void testAllocateThenAtomic(Inner i) {
192 Outer o = new Outer();
193 Common.blackhole(o);
194 Common.field1VarHandle.getAndSet(o, i);
195 }
196
197 @Test
198 // TODO 8329234
199 // @IR(counts = { IRNode.Z_LOAD_P_WITH_BARRIER_FLAG, Common.REMAINING, "1" }, phase = CompilePhase.FINAL_CODE)
200 @IR(counts = { IRNode.Z_GET_AND_SET_P_WITH_BARRIER_FLAG, Common.REMAINING, "1" }, phase = CompilePhase.FINAL_CODE)
201 static void testLoadThenAtomic(Outer o, Inner i) {
202 Common.blackhole(o.field1);
203 Common.field1VarHandle.getAndSet(o, i);
204 }
205
206 @Test
207 @IR(counts = { IRNode.Z_GET_AND_SET_P_WITH_BARRIER_FLAG, Common.REMAINING, "2" }, phase = CompilePhase.FINAL_CODE)
208 static void testAtomicThenAtomicAnotherField(Outer o, Inner i) {
209 Common.field1VarHandle.getAndSet(o, i);
210 Common.field2VarHandle.getAndSet(o, i);
211 }
212
213 @Test
214 @IR(counts = { IRNode.Z_GET_AND_SET_P_WITH_BARRIER_FLAG, Common.REMAINING, "1" }, phase = CompilePhase.FINAL_CODE)
215 static void testAllocateArrayThenAtomicAtKnownIndex(Outer o) {
216 Outer[] a = new Outer[42];
217 Common.blackhole(a);
218 Common.outerArrayVarHandle.getAndSet(a, 2, o);
219 }
|