Skip to content

Commit b2ac725

Browse files
tabjyrwestrel
authored andcommitted
8327380: Add tests for Shenandoah barrier expansion optimization
Reviewed-by: roland, shade
1 parent f23295e commit b2ac725

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/*
2+
* Copyright (c) 2024 Red Hat and/or its affiliates. All rights reserved.
3+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4+
*
5+
* This code is free software; you can redistribute it and/or modify it
6+
* under the terms of the GNU General Public License version 2 only, as
7+
* published by the Free Software Foundation.
8+
*
9+
* This code is distributed in the hope that it will be useful, but WITHOUT
10+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
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.CompilePhase;
27+
import compiler.lib.ir_framework.DontInline;
28+
import compiler.lib.ir_framework.IR;
29+
import compiler.lib.ir_framework.IRNode;
30+
import compiler.lib.ir_framework.Test;
31+
import compiler.lib.ir_framework.TestFramework;
32+
33+
/**
34+
* @test
35+
* @bug 8231569
36+
* @summary Test that Shenandoah barriers are expanded correctly
37+
* @library /test/lib /
38+
* @requires vm.gc.Shenandoah
39+
* @run main compiler.gcbarriers.TestShenandoahBarrierExpansion
40+
*/
41+
public class TestShenandoahBarrierExpansion {
42+
public static void main(String[] args) {
43+
TestFramework test = new TestFramework(TestShenandoahBarrierExpansion.class);
44+
test.addFlags("-XX:+UseShenandoahGC");
45+
test.start();
46+
}
47+
48+
private static Object staticField;
49+
@Test
50+
@IR(failOn = IRNode.IF, phase = CompilePhase.AFTER_PARSING)
51+
@IR(counts = { IRNode.IF, "2" }, phase = CompilePhase.BARRIER_EXPANSION)
52+
public Object testLoadFieldObject() {
53+
return staticField;
54+
}
55+
56+
private static A staticField2 = new A();
57+
@Test
58+
@IR(counts = { IRNode.IF, "1" }, phase = CompilePhase.AFTER_PARSING)
59+
@IR(counts = { IRNode.IF, "3" }, phase = CompilePhase.BARRIER_EXPANSION)
60+
private static int testLoadObjectFieldWithNullCheck() {
61+
return staticField2.intField;
62+
}
63+
64+
private static A staticField3 = new A();
65+
@Test
66+
@IR(counts = { IRNode.IF, "2" }, phase = CompilePhase.AFTER_PARSING)
67+
@IR(counts = { IRNode.IF, "6" }, phase = CompilePhase.BARRIER_EXPANSION)
68+
private static int testLoadTwoObjectFieldsWithNullCheck() {
69+
return staticField2.intField + staticField3.intField;
70+
}
71+
72+
@Test
73+
@IR(failOn = IRNode.IF, phase = CompilePhase.AFTER_PARSING)
74+
@IR(counts = { IRNode.IF, "3" }, phase = CompilePhase.BARRIER_EXPANSION)
75+
private static void testLoadTwoFieldObjectAndEscape() {
76+
final A field2 = staticField2;
77+
final A field3 = staticField3;
78+
notInlined(field2, field3);
79+
}
80+
81+
@DontInline
82+
private static void notInlined(A field2, A field3) {
83+
// noop
84+
}
85+
86+
private static class A {
87+
public int intField;
88+
}
89+
}

0 commit comments

Comments
 (0)