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 */
61 Integer field;
62
63 @ForceInline
64 public Carrier(boolean init) {
65 if (init) {
66 field = INTEGER;
67 }
68 }
69
70 @ForceInline
71 public void init() {
72 field = INTEGER;
73 }
74 }
75
76 static final Carrier BLANK_CARRIER = new Carrier(false);
77 static final Carrier INIT_CARRIER = new Carrier(true);
78
79 @Test
80 @IR(counts = { IRNode.LOAD, ">0" })
81 @IR(failOn = { IRNode.MEMBAR })
82 static int testNoFold() {
83 // Access should not be folded.
84 // No barriers expected for plain fields.
85 Integer i = BLANK_CARRIER.field;
86 return i != null ? i : 0;
87 }
88
89 @Test
90 @IR(failOn = { IRNode.LOAD, IRNode.MEMBAR })
91 static int testFold() {
92 // Access should be completely folded.
93 Integer i = INIT_CARRIER.field;
94 return i != null ? i : 0;
95 }
96
97 @Test
98 @IR(counts = { IRNode.MEMBAR_STORESTORE, "1" })
99 static Carrier testConstructorBlankInit() {
100 // Only the header barrier.
101 return new Carrier(false);
102 }
103
104 @Test
105 @IR(counts = { IRNode.MEMBAR_STORESTORE, "1" })
106 static Carrier testConstructorFullInit() {
107 // Only the header barrier.
108 return new Carrier(true);
109 }
110
111 @Test
112 @IR(failOn = { IRNode.MEMBAR })
113 static void testMethodInit() {
114 // Reference inits do not have membars.
115 INIT_CARRIER.init();
116 }
117
118 }
|
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 */
62 Integer field;
63
64 @ForceInline
65 public Carrier(boolean init) {
66 if (init) {
67 field = INTEGER;
68 }
69 }
70
71 @ForceInline
72 public void init() {
73 field = INTEGER;
74 }
75 }
76
77 static final Carrier BLANK_CARRIER = new Carrier(false);
78 static final Carrier INIT_CARRIER = new Carrier(true);
79
80 @Test
81 @IR(counts = { IRNode.LOAD, ">0" })
82 @IR(applyIf = {"enable-valhalla", "false"}, failOn = { IRNode.MEMBAR })
83 // We have barriers with valhalla from the atomic expansion of the LoadFlatNode
84 // Indeed, since the field is not initialized, it is not known to be constant yet,
85 // and so, the LoadFlat cannot be expanded non-atomically. We need barriers to synchronize
86 // the LoadFlat and potential updates to sub-field of the flatten field.
87 @IR(applyIfAnd = {"UseFieldFlattening", "true", "enable-valhalla", "true"}, counts = { IRNode.MEMBAR, ">0" })
88 static int testNoFold() {
89 // Access should not be folded.
90 Integer i = BLANK_CARRIER.field;
91 return i != null ? i : 0;
92 }
93
94 @Test
95 @IR(failOn = { IRNode.LOAD, IRNode.MEMBAR })
96 static int testFold() {
97 // Access should be completely folded.
98 Integer i = INIT_CARRIER.field;
99 return i != null ? i : 0;
100 }
101
102 @Test
103 @IR(counts = { IRNode.MEMBAR_STORESTORE, "1" })
104 static Carrier testConstructorBlankInit() {
105 // Only the header barrier.
106 return new Carrier(false);
107 }
108
109 @Test
110 @IR(counts = { IRNode.MEMBAR_STORESTORE, "1" })
111 static Carrier testConstructorFullInit() {
112 // Only the header barrier.
113 return new Carrier(true);
114 }
115
116 @Test
117 @IR(applyIf = {"enable-valhalla", "false"}, failOn = { IRNode.MEMBAR })
118 // We have barriers from the atomic expansion of the StoreFlatNode. Store is not eliminated with
119 // or without Valhalla, but Valhalla's StoreFlat require barriers.
120 @IR(applyIfAnd = {"UseFieldFlattening", "true", "enable-valhalla", "true"}, counts = { IRNode.MEMBAR, ">0" })
121 static void testMethodInit() {
122 INIT_CARRIER.init();
123 }
124
125 }
|