1 /*
2 * Copyright Amazon.com Inc. 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 */
54 tf.start();
55 }
56
57 static final Integer INTEGER = 42;
58
59 static class Carrier {
60 @Stable
61 final Integer field;
62
63 @ForceInline
64 public Carrier(boolean init) {
65 field = init ? INTEGER : null;
66 }
67 }
68
69 static final Carrier BLANK_CARRIER = new Carrier(false);
70 static final Carrier INIT_CARRIER = new Carrier(true);
71
72 @Test
73 @IR(counts = { IRNode.LOAD, ">0" })
74 @IR(failOn = { IRNode.MEMBAR })
75 static int testNoFold() {
76 // Access should not be folded.
77 // No barriers expected for plain fields.
78 Integer i = BLANK_CARRIER.field;
79 return i != null ? i : 0;
80 }
81
82 @Test
83 @IR(failOn = { IRNode.LOAD, IRNode.MEMBAR })
84 static int testFold() {
85 // Access should be completely folded.
86 Integer i = INIT_CARRIER.field;
87 return i != null ? i : 0;
88 }
89
90 @Test
91 @IR(counts = { IRNode.MEMBAR_STORESTORE, "1" })
92 static Carrier testConstructorInit() {
93 // Only the header+final barrier.
94 return new Carrier(true);
|
1 /*
2 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved.
3 * Copyright (c) 2026, Oracle and/or its affiliates. All rights reserved.
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 *
6 * This code is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 only, as
8 * published by the Free Software Foundation.
9 *
10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * version 2 for more details (a copy is included in the LICENSE file that
14 * accompanied this code).
15 *
16 * You should have received a copy of the GNU General Public License version
17 * 2 along with this work; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 * or visit www.oracle.com if you need additional information or have any
22 * questions.
23 */
55 tf.start();
56 }
57
58 static final Integer INTEGER = 42;
59
60 static class Carrier {
61 @Stable
62 final Integer field;
63
64 @ForceInline
65 public Carrier(boolean init) {
66 field = init ? INTEGER : null;
67 }
68 }
69
70 static final Carrier BLANK_CARRIER = new Carrier(false);
71 static final Carrier INIT_CARRIER = new Carrier(true);
72
73 @Test
74 @IR(counts = { IRNode.LOAD, ">0" })
75 @IR(applyIf = {"enable-valhalla", "false"}, failOn = { IRNode.MEMBAR })
76 // We have barriers with valhalla from the atomic expansion of the LoadFlatNode
77 // Indeed, since the field is not initialized, it is not known to be constant yet,
78 // and so, the LoadFlat cannot be expanded non-atomically. We need barriers to synchronize
79 // the LoadFlat and potential updates to sub-field of the flatten field.
80 @IR(applyIfAnd = {"UseFieldFlattening", "true", "enable-valhalla", "true"}, counts = { IRNode.MEMBAR, ">0" })
81 static int testNoFold() {
82 // Access should not be folded.
83 // No barriers expected for plain fields.
84 Integer i = BLANK_CARRIER.field;
85 return i != null ? i : 0;
86 }
87
88 @Test
89 @IR(failOn = { IRNode.LOAD, IRNode.MEMBAR })
90 static int testFold() {
91 // Access should be completely folded.
92 Integer i = INIT_CARRIER.field;
93 return i != null ? i : 0;
94 }
95
96 @Test
97 @IR(counts = { IRNode.MEMBAR_STORESTORE, "1" })
98 static Carrier testConstructorInit() {
99 // Only the header+final barrier.
100 return new Carrier(true);
|