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 */
95 static final Carrier INIT_FULL_CARRIER = new Carrier(2);
96
97 @Test
98 @IR(counts = { IRNode.LOAD, ">0" })
99 @IR(failOn = { IRNode.MEMBAR })
100 static int testNoFold() {
101 // Access should not be folded.
102 // No barriers expected for plain fields.
103 Integer[] is = BLANK_CARRIER.field;
104 if (is != null) {
105 Integer i = is[0];
106 if (i != null) {
107 return i;
108 }
109 }
110 return 0;
111 }
112
113 @Test
114 @IR(counts = { IRNode.LOAD, ">0" })
115 @IR(failOn = { IRNode.MEMBAR })
116 static int testPartialFold() {
117 // Access should not be folded.
118 // No barriers expected for plain fields.
119 Integer[] is = INIT_EMPTY_CARRIER.field;
120 if (is != null) {
121 Integer i = is[0];
122 if (i != null) {
123 return i;
124 }
125 }
126 return 0;
127 }
128
129
130 @Test
131 @IR(failOn = { IRNode.LOAD, IRNode.MEMBAR })
132 static int testFold() {
133 // Access should be completely folded.
134 Integer[] is = INIT_FULL_CARRIER.field;
135 if (is != null) {
136 Integer i = is[0];
137 if (i != null) {
138 return i;
|
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 */
96 static final Carrier INIT_FULL_CARRIER = new Carrier(2);
97
98 @Test
99 @IR(counts = { IRNode.LOAD, ">0" })
100 @IR(failOn = { IRNode.MEMBAR })
101 static int testNoFold() {
102 // Access should not be folded.
103 // No barriers expected for plain fields.
104 Integer[] is = BLANK_CARRIER.field;
105 if (is != null) {
106 Integer i = is[0];
107 if (i != null) {
108 return i;
109 }
110 }
111 return 0;
112 }
113
114 @Test
115 @IR(counts = { IRNode.LOAD, ">0" })
116 @IR(applyIf = {"enable-valhalla", "false"}, failOn = { IRNode.MEMBAR })
117 // We have barriers with valhalla from the atomic expansion of the LoadFlatNode
118 // Indeed, since the array element is not initialized, it is not known to be constant yet,
119 // and so, the LoadFlat cannot be expanded non-atomically. We need barriers to synchronize
120 // the LoadFlat and potential updates to field of the flatten array element.
121 @IR(applyIfAnd = {"UseArrayFlattening", "true", "enable-valhalla", "true"}, counts = { IRNode.MEMBAR, "> 0" })
122 static int testPartialFold() {
123 // Access should not be folded.
124 Integer[] is = INIT_EMPTY_CARRIER.field;
125 if (is != null) {
126 Integer i = is[0];
127 if (i != null) {
128 return i;
129 }
130 }
131 return 0;
132 }
133
134
135 @Test
136 @IR(failOn = { IRNode.LOAD, IRNode.MEMBAR })
137 static int testFold() {
138 // Access should be completely folded.
139 Integer[] is = INIT_FULL_CARRIER.field;
140 if (is != null) {
141 Integer i = is[0];
142 if (i != null) {
143 return i;
|