author | alanb |
Tue, 03 May 2016 09:09:20 +0100 | |
changeset 37773 | e5b3e9732c3c |
parent 36616 | 5172e3dd60f2 |
child 38207 | 2ed792c9481d |
permissions | -rw-r--r-- |
23192 | 1 |
/* |
37773
e5b3e9732c3c
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36616
diff
changeset
|
2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
23192 | 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. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
10 |
* |
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
24 |
*/ |
|
25 |
||
26 |
/* |
|
27 |
* @test TestStableByte |
|
28 |
* @summary tests on stable fields and arrays |
|
36508 | 29 |
* @library /testlibrary /test/lib / |
30 |
* @modules java.base/jdk.internal.vm.annotation |
|
31 |
* @build sun.hotspot.WhiteBox |
|
32 |
* @build compiler.stable.TestStableByte |
|
23192 | 33 |
* |
37773
e5b3e9732c3c
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36616
diff
changeset
|
34 |
* @run main/bootclasspath/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
36508 | 35 |
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
36 |
* -XX:-TieredCompilation |
|
37 |
* -XX:+FoldStableValues |
|
38 |
* compiler.stable.TestStableByte |
|
37773
e5b3e9732c3c
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36616
diff
changeset
|
39 |
* @run main/bootclasspath/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
36508 | 40 |
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
41 |
* -XX:-TieredCompilation |
|
42 |
* -XX:+FoldStableValues |
|
43 |
* compiler.stable.TestStableByte |
|
23192 | 44 |
* |
37773
e5b3e9732c3c
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36616
diff
changeset
|
45 |
* @run main/bootclasspath/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
36508 | 46 |
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
47 |
* -XX:-TieredCompilation |
|
48 |
* -XX:+FoldStableValues |
|
49 |
* compiler.stable.TestStableByte |
|
37773
e5b3e9732c3c
8154956: Module system implementation refresh (4/2016)
alanb
parents:
36616
diff
changeset
|
50 |
* @run main/bootclasspath/othervm -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
36508 | 51 |
* -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
52 |
* -XX:-TieredCompilation |
|
53 |
* -XX:+FoldStableValues |
|
54 |
* compiler.stable.TestStableByte |
|
23192 | 55 |
*/ |
36508 | 56 |
|
57 |
package compiler.stable; |
|
23192 | 58 |
|
35099
982950884444
8144223: Move j.l.invoke.{ForceInline, DontInline, Stable} to jdk.internal.vm.annotation package
psandoz
parents:
33730
diff
changeset
|
59 |
import jdk.internal.vm.annotation.Stable; |
23192 | 60 |
import java.lang.reflect.InvocationTargetException; |
61 |
||
62 |
public class TestStableByte { |
|
25641
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
63 |
static final boolean isStableEnabled = StableConfiguration.isStableEnabled; |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
64 |
|
23192 | 65 |
public static void main(String[] args) throws Exception { |
66 |
run(DefaultValue.class); |
|
67 |
run(ByteStable.class); |
|
25641
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
68 |
run(DefaultStaticValue.class); |
23192 | 69 |
run(StaticByteStable.class); |
70 |
run(VolatileByteStable.class); |
|
71 |
||
72 |
// @Stable arrays: Dim 1-4 |
|
73 |
run(ByteArrayDim1.class); |
|
74 |
run(ByteArrayDim2.class); |
|
75 |
run(ByteArrayDim3.class); |
|
76 |
run(ByteArrayDim4.class); |
|
77 |
||
78 |
// @Stable Object field: dynamic arrays |
|
79 |
run(ObjectArrayLowerDim0.class); |
|
80 |
run(ObjectArrayLowerDim1.class); |
|
81 |
run(ObjectArrayLowerDim2.class); |
|
82 |
||
83 |
// Nested @Stable fields |
|
84 |
run(NestedStableField.class); |
|
85 |
run(NestedStableField1.class); |
|
86 |
run(NestedStableField2.class); |
|
87 |
run(NestedStableField3.class); |
|
88 |
||
89 |
if (failed) { |
|
90 |
throw new Error("TEST FAILED"); |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
/* ==================================================== */ |
|
95 |
||
96 |
static class DefaultValue { |
|
97 |
public @Stable byte v; |
|
98 |
||
99 |
public static final DefaultValue c = new DefaultValue(); |
|
100 |
public static byte get() { return c.v; } |
|
101 |
public static void test() throws Exception { |
|
36508 | 102 |
byte val1 = get(); |
23192 | 103 |
c.v = 1; byte val2 = get(); |
104 |
assertEquals(val1, 0); |
|
105 |
assertEquals(val2, 1); |
|
106 |
} |
|
107 |
} |
|
108 |
||
109 |
/* ==================================================== */ |
|
110 |
||
111 |
static class ByteStable { |
|
112 |
public @Stable byte v; |
|
113 |
||
114 |
public static final ByteStable c = new ByteStable(); |
|
115 |
public static byte get() { return c.v; } |
|
116 |
public static void test() throws Exception { |
|
117 |
c.v = 5; byte val1 = get(); |
|
118 |
c.v = 127; byte val2 = get(); |
|
119 |
assertEquals(val1, 5); |
|
120 |
assertEquals(val2, (isStableEnabled ? 5 : 127)); |
|
121 |
} |
|
122 |
} |
|
123 |
||
124 |
/* ==================================================== */ |
|
125 |
||
25641
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
126 |
static class DefaultStaticValue { |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
127 |
public static @Stable byte v; |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
128 |
|
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
129 |
public static final DefaultStaticValue c = new DefaultStaticValue(); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
130 |
public static byte get() { return c.v; } |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
131 |
public static void test() throws Exception { |
36508 | 132 |
byte val1 = get(); |
25641
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
133 |
c.v = 1; byte val2 = get(); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
134 |
assertEquals(val1, 0); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
135 |
assertEquals(val2, 1); |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
136 |
} |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
137 |
} |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
138 |
|
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
139 |
/* ==================================================== */ |
d99065e4572b
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
23192
diff
changeset
|
140 |
|
23192 | 141 |
static class StaticByteStable { |
142 |
public static @Stable byte v; |
|
143 |
||
144 |
public static final StaticByteStable c = new StaticByteStable(); |
|
145 |
public static byte get() { return c.v; } |
|
146 |
public static void test() throws Exception { |
|
147 |
c.v = 5; byte val1 = get(); |
|
148 |
c.v = 127; byte val2 = get(); |
|
149 |
assertEquals(val1, 5); |
|
150 |
assertEquals(val2, (isStableEnabled ? 5 : 127)); |
|
151 |
} |
|
152 |
} |
|
153 |
||
154 |
/* ==================================================== */ |
|
155 |
||
156 |
static class VolatileByteStable { |
|
157 |
public @Stable volatile byte v; |
|
158 |
||
159 |
public static final VolatileByteStable c = new VolatileByteStable(); |
|
160 |
public static byte get() { return c.v; } |
|
161 |
public static void test() throws Exception { |
|
162 |
c.v = 5; byte val1 = get(); |
|
163 |
c.v = 127; byte val2 = get(); |
|
164 |
assertEquals(val1, 5); |
|
165 |
assertEquals(val2, (isStableEnabled ? 5 : 127)); |
|
166 |
} |
|
167 |
} |
|
168 |
||
169 |
/* ==================================================== */ |
|
170 |
// @Stable array == field && all components are stable |
|
171 |
||
172 |
static class ByteArrayDim1 { |
|
173 |
public @Stable byte[] v; |
|
174 |
||
175 |
public static final ByteArrayDim1 c = new ByteArrayDim1(); |
|
176 |
public static byte get() { return c.v[0]; } |
|
177 |
public static byte get1() { return c.v[10]; } |
|
178 |
public static byte[] get2() { return c.v; } |
|
179 |
public static void test() throws Exception { |
|
180 |
{ |
|
181 |
c.v = new byte[1]; c.v[0] = 1; byte val1 = get(); |
|
36508 | 182 |
c.v[0] = 2; byte val2 = get(); |
23192 | 183 |
assertEquals(val1, 1); |
36604 | 184 |
assertEquals(val2, (isStableEnabled ? 1 : 2)); |
23192 | 185 |
|
186 |
c.v = new byte[1]; c.v[0] = 3; byte val3 = get(); |
|
36604 | 187 |
assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 188 |
: 3)); |
23192 | 189 |
} |
190 |
||
191 |
{ |
|
192 |
c.v = new byte[20]; c.v[10] = 1; byte val1 = get1(); |
|
36508 | 193 |
c.v[10] = 2; byte val2 = get1(); |
23192 | 194 |
assertEquals(val1, 1); |
36604 | 195 |
assertEquals(val2, (isStableEnabled ? 1 : 2)); |
23192 | 196 |
|
197 |
c.v = new byte[20]; c.v[10] = 3; byte val3 = get1(); |
|
36604 | 198 |
assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 199 |
: 3)); |
23192 | 200 |
} |
201 |
||
202 |
{ |
|
203 |
c.v = new byte[1]; byte[] val1 = get2(); |
|
204 |
c.v = new byte[1]; byte[] val2 = get2(); |
|
205 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
|
206 |
} |
|
207 |
} |
|
208 |
} |
|
209 |
||
210 |
/* ==================================================== */ |
|
211 |
||
212 |
static class ByteArrayDim2 { |
|
213 |
public @Stable byte[][] v; |
|
214 |
||
215 |
public static final ByteArrayDim2 c = new ByteArrayDim2(); |
|
216 |
public static byte get() { return c.v[0][0]; } |
|
217 |
public static byte[] get1() { return c.v[0]; } |
|
218 |
public static byte[][] get2() { return c.v; } |
|
219 |
public static void test() throws Exception { |
|
220 |
{ |
|
221 |
c.v = new byte[1][1]; c.v[0][0] = 1; byte val1 = get(); |
|
36508 | 222 |
c.v[0][0] = 2; byte val2 = get(); |
23192 | 223 |
assertEquals(val1, 1); |
36604 | 224 |
assertEquals(val2, (isStableEnabled ? 1 : 2)); |
23192 | 225 |
|
226 |
c.v = new byte[1][1]; c.v[0][0] = 3; byte val3 = get(); |
|
36604 | 227 |
assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 228 |
: 3)); |
23192 | 229 |
|
230 |
c.v[0] = new byte[1]; c.v[0][0] = 4; byte val4 = get(); |
|
36604 | 231 |
assertEquals(val4, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 232 |
: 4)); |
23192 | 233 |
} |
234 |
||
235 |
{ |
|
236 |
c.v = new byte[1][1]; byte[] val1 = get1(); |
|
237 |
c.v[0] = new byte[1]; byte[] val2 = get1(); |
|
36604 | 238 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
23192 | 239 |
} |
240 |
||
241 |
{ |
|
242 |
c.v = new byte[1][1]; byte[][] val1 = get2(); |
|
243 |
c.v = new byte[1][1]; byte[][] val2 = get2(); |
|
244 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
|
245 |
} |
|
246 |
} |
|
247 |
} |
|
248 |
||
249 |
/* ==================================================== */ |
|
250 |
||
251 |
static class ByteArrayDim3 { |
|
252 |
public @Stable byte[][][] v; |
|
253 |
||
254 |
public static final ByteArrayDim3 c = new ByteArrayDim3(); |
|
255 |
public static byte get() { return c.v[0][0][0]; } |
|
256 |
public static byte[] get1() { return c.v[0][0]; } |
|
257 |
public static byte[][] get2() { return c.v[0]; } |
|
258 |
public static byte[][][] get3() { return c.v; } |
|
259 |
public static void test() throws Exception { |
|
260 |
{ |
|
261 |
c.v = new byte[1][1][1]; c.v[0][0][0] = 1; byte val1 = get(); |
|
36508 | 262 |
c.v[0][0][0] = 2; byte val2 = get(); |
23192 | 263 |
assertEquals(val1, 1); |
36604 | 264 |
assertEquals(val2, (isStableEnabled ? 1 : 2)); |
23192 | 265 |
|
266 |
c.v = new byte[1][1][1]; c.v[0][0][0] = 3; byte val3 = get(); |
|
36604 | 267 |
assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 268 |
: 3)); |
23192 | 269 |
|
270 |
c.v[0] = new byte[1][1]; c.v[0][0][0] = 4; byte val4 = get(); |
|
36604 | 271 |
assertEquals(val4, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 272 |
: 4)); |
23192 | 273 |
|
274 |
c.v[0][0] = new byte[1]; c.v[0][0][0] = 5; byte val5 = get(); |
|
36604 | 275 |
assertEquals(val5, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 276 |
: 5)); |
23192 | 277 |
} |
278 |
||
279 |
{ |
|
280 |
c.v = new byte[1][1][1]; byte[] val1 = get1(); |
|
281 |
c.v[0][0] = new byte[1]; byte[] val2 = get1(); |
|
36604 | 282 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
23192 | 283 |
} |
284 |
||
285 |
{ |
|
286 |
c.v = new byte[1][1][1]; byte[][] val1 = get2(); |
|
287 |
c.v[0] = new byte[1][1]; byte[][] val2 = get2(); |
|
36604 | 288 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
23192 | 289 |
} |
290 |
||
291 |
{ |
|
292 |
c.v = new byte[1][1][1]; byte[][][] val1 = get3(); |
|
293 |
c.v = new byte[1][1][1]; byte[][][] val2 = get3(); |
|
294 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
|
295 |
} |
|
296 |
} |
|
297 |
} |
|
298 |
||
299 |
/* ==================================================== */ |
|
300 |
||
301 |
static class ByteArrayDim4 { |
|
302 |
public @Stable byte[][][][] v; |
|
303 |
||
304 |
public static final ByteArrayDim4 c = new ByteArrayDim4(); |
|
305 |
public static byte get() { return c.v[0][0][0][0]; } |
|
306 |
public static byte[] get1() { return c.v[0][0][0]; } |
|
307 |
public static byte[][] get2() { return c.v[0][0]; } |
|
308 |
public static byte[][][] get3() { return c.v[0]; } |
|
309 |
public static byte[][][][] get4() { return c.v; } |
|
310 |
public static void test() throws Exception { |
|
311 |
{ |
|
312 |
c.v = new byte[1][1][1][1]; c.v[0][0][0][0] = 1; byte val1 = get(); |
|
36508 | 313 |
c.v[0][0][0][0] = 2; byte val2 = get(); |
23192 | 314 |
assertEquals(val1, 1); |
36604 | 315 |
assertEquals(val2, (isStableEnabled ? 1 : 2)); |
23192 | 316 |
|
317 |
c.v = new byte[1][1][1][1]; c.v[0][0][0][0] = 3; byte val3 = get(); |
|
36604 | 318 |
assertEquals(val3, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 319 |
: 3)); |
23192 | 320 |
|
321 |
c.v[0] = new byte[1][1][1]; c.v[0][0][0][0] = 4; byte val4 = get(); |
|
36604 | 322 |
assertEquals(val4, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 323 |
: 4)); |
23192 | 324 |
|
325 |
c.v[0][0] = new byte[1][1]; c.v[0][0][0][0] = 5; byte val5 = get(); |
|
36604 | 326 |
assertEquals(val5, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 327 |
: 5)); |
23192 | 328 |
|
329 |
c.v[0][0][0] = new byte[1]; c.v[0][0][0][0] = 6; byte val6 = get(); |
|
36604 | 330 |
assertEquals(val6, (isStableEnabled ? (isStableEnabled ? 1 : 2) |
36508 | 331 |
: 6)); |
23192 | 332 |
} |
333 |
||
334 |
{ |
|
335 |
c.v = new byte[1][1][1][1]; byte[] val1 = get1(); |
|
336 |
c.v[0][0][0] = new byte[1]; byte[] val2 = get1(); |
|
36604 | 337 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
23192 | 338 |
} |
339 |
||
340 |
{ |
|
341 |
c.v = new byte[1][1][1][1]; byte[][] val1 = get2(); |
|
342 |
c.v[0][0] = new byte[1][1]; byte[][] val2 = get2(); |
|
36604 | 343 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
23192 | 344 |
} |
345 |
||
346 |
{ |
|
347 |
c.v = new byte[1][1][1][1]; byte[][][] val1 = get3(); |
|
348 |
c.v[0] = new byte[1][1][1]; byte[][][] val2 = get3(); |
|
36604 | 349 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
23192 | 350 |
} |
351 |
||
352 |
{ |
|
353 |
c.v = new byte[1][1][1][1]; byte[][][][] val1 = get4(); |
|
354 |
c.v = new byte[1][1][1][1]; byte[][][][] val2 = get4(); |
|
355 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
|
356 |
} |
|
357 |
||
358 |
} |
|
359 |
} |
|
360 |
||
361 |
/* ==================================================== */ |
|
362 |
// Dynamic Dim is higher than static |
|
363 |
||
364 |
static class ObjectArrayLowerDim0 { |
|
365 |
public @Stable Object v; |
|
366 |
||
367 |
public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0(); |
|
368 |
public static byte get() { return ((byte[])c.v)[0]; } |
|
369 |
public static byte[] get1() { return (byte[])c.v; } |
|
370 |
||
371 |
public static void test() throws Exception { |
|
372 |
{ |
|
373 |
c.v = new byte[1]; ((byte[])c.v)[0] = 1; byte val1 = get(); |
|
36508 | 374 |
((byte[])c.v)[0] = 2; byte val2 = get(); |
23192 | 375 |
|
376 |
assertEquals(val1, 1); |
|
377 |
assertEquals(val2, 2); |
|
378 |
} |
|
379 |
||
380 |
{ |
|
381 |
c.v = new byte[1]; byte[] val1 = get1(); |
|
382 |
c.v = new byte[1]; byte[] val2 = get1(); |
|
383 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
|
384 |
} |
|
385 |
} |
|
386 |
} |
|
387 |
||
388 |
/* ==================================================== */ |
|
389 |
||
390 |
static class ObjectArrayLowerDim1 { |
|
391 |
public @Stable Object[] v; |
|
392 |
||
393 |
public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1(); |
|
394 |
public static byte get() { return ((byte[][])c.v)[0][0]; } |
|
395 |
public static byte[] get1() { return (byte[])(c.v[0]); } |
|
396 |
public static Object[] get2() { return c.v; } |
|
397 |
||
398 |
public static void test() throws Exception { |
|
399 |
{ |
|
400 |
c.v = new byte[1][1]; ((byte[][])c.v)[0][0] = 1; byte val1 = get(); |
|
36508 | 401 |
((byte[][])c.v)[0][0] = 2; byte val2 = get(); |
23192 | 402 |
|
403 |
assertEquals(val1, 1); |
|
404 |
assertEquals(val2, 2); |
|
405 |
} |
|
406 |
||
407 |
{ |
|
408 |
c.v = new byte[1][1]; c.v[0] = new byte[0]; byte[] val1 = get1(); |
|
36508 | 409 |
c.v[0] = new byte[0]; byte[] val2 = get1(); |
23192 | 410 |
|
36604 | 411 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
23192 | 412 |
} |
413 |
||
414 |
{ |
|
415 |
c.v = new byte[0][0]; Object[] val1 = get2(); |
|
416 |
c.v = new byte[0][0]; Object[] val2 = get2(); |
|
417 |
||
418 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
|
419 |
} |
|
420 |
} |
|
421 |
} |
|
422 |
||
423 |
/* ==================================================== */ |
|
424 |
||
425 |
static class ObjectArrayLowerDim2 { |
|
426 |
public @Stable Object[][] v; |
|
427 |
||
428 |
public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2(); |
|
429 |
public static byte get() { return ((byte[][][])c.v)[0][0][0]; } |
|
430 |
public static byte[] get1() { return (byte[])(c.v[0][0]); } |
|
431 |
public static byte[][] get2() { return (byte[][])(c.v[0]); } |
|
432 |
public static Object[][] get3() { return c.v; } |
|
433 |
||
434 |
public static void test() throws Exception { |
|
435 |
{ |
|
436 |
c.v = new byte[1][1][1]; ((byte[][][])c.v)[0][0][0] = 1; byte val1 = get(); |
|
36508 | 437 |
((byte[][][])c.v)[0][0][0] = 2; byte val2 = get(); |
23192 | 438 |
|
439 |
assertEquals(val1, 1); |
|
440 |
assertEquals(val2, 2); |
|
441 |
} |
|
442 |
||
443 |
{ |
|
444 |
c.v = new byte[1][1][1]; c.v[0][0] = new byte[0]; byte[] val1 = get1(); |
|
36508 | 445 |
c.v[0][0] = new byte[0]; byte[] val2 = get1(); |
23192 | 446 |
|
36604 | 447 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
23192 | 448 |
} |
449 |
||
450 |
{ |
|
451 |
c.v = new byte[1][1][1]; c.v[0] = new byte[0][0]; byte[][] val1 = get2(); |
|
36508 | 452 |
c.v[0] = new byte[0][0]; byte[][] val2 = get2(); |
23192 | 453 |
|
36604 | 454 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
23192 | 455 |
} |
456 |
||
457 |
{ |
|
458 |
c.v = new byte[0][0][0]; Object[][] val1 = get3(); |
|
459 |
c.v = new byte[0][0][0]; Object[][] val2 = get3(); |
|
460 |
||
461 |
assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); |
|
462 |
} |
|
463 |
} |
|
464 |
} |
|
465 |
||
466 |
/* ==================================================== */ |
|
467 |
||
468 |
static class NestedStableField { |
|
469 |
static class A { |
|
470 |
public @Stable byte a; |
|
471 |
||
472 |
} |
|
473 |
public @Stable A v; |
|
474 |
||
475 |
public static final NestedStableField c = new NestedStableField(); |
|
476 |
public static A get() { return c.v; } |
|
477 |
public static byte get1() { return get().a; } |
|
478 |
||
479 |
public static void test() throws Exception { |
|
480 |
{ |
|
481 |
c.v = new A(); c.v.a = 1; A val1 = get(); |
|
36508 | 482 |
c.v.a = 2; A val2 = get(); |
23192 | 483 |
|
484 |
assertEquals(val1.a, 2); |
|
485 |
assertEquals(val2.a, 2); |
|
486 |
} |
|
487 |
||
488 |
{ |
|
489 |
c.v = new A(); c.v.a = 1; byte val1 = get1(); |
|
36508 | 490 |
c.v.a = 2; byte val2 = get1(); |
23192 | 491 |
c.v = new A(); c.v.a = 3; byte val3 = get1(); |
492 |
||
493 |
assertEquals(val1, 1); |
|
494 |
assertEquals(val2, (isStableEnabled ? 1 : 2)); |
|
495 |
assertEquals(val3, (isStableEnabled ? 1 : 3)); |
|
496 |
} |
|
497 |
} |
|
498 |
} |
|
499 |
||
500 |
/* ==================================================== */ |
|
501 |
||
502 |
static class NestedStableField1 { |
|
503 |
static class A { |
|
504 |
public @Stable byte a; |
|
505 |
public @Stable A next; |
|
506 |
} |
|
507 |
public @Stable A v; |
|
508 |
||
509 |
public static final NestedStableField1 c = new NestedStableField1(); |
|
510 |
public static A get() { return c.v.next.next.next.next.next.next.next; } |
|
511 |
public static byte get1() { return get().a; } |
|
512 |
||
513 |
public static void test() throws Exception { |
|
514 |
{ |
|
515 |
c.v = new A(); c.v.next = new A(); c.v.next.next = c.v; |
|
36508 | 516 |
c.v.a = 1; c.v.next.a = 1; A val1 = get(); |
517 |
c.v.a = 2; c.v.next.a = 2; A val2 = get(); |
|
23192 | 518 |
|
519 |
assertEquals(val1.a, 2); |
|
520 |
assertEquals(val2.a, 2); |
|
521 |
} |
|
522 |
||
523 |
{ |
|
524 |
c.v = new A(); c.v.next = c.v; |
|
36508 | 525 |
c.v.a = 1; byte val1 = get1(); |
526 |
c.v.a = 2; byte val2 = get1(); |
|
23192 | 527 |
c.v = new A(); c.v.next = c.v; |
36508 | 528 |
c.v.a = 3; byte val3 = get1(); |
23192 | 529 |
|
530 |
assertEquals(val1, 1); |
|
531 |
assertEquals(val2, (isStableEnabled ? 1 : 2)); |
|
532 |
assertEquals(val3, (isStableEnabled ? 1 : 3)); |
|
533 |
} |
|
534 |
} |
|
535 |
} |
|
536 |
/* ==================================================== */ |
|
537 |
||
538 |
static class NestedStableField2 { |
|
539 |
static class A { |
|
540 |
public @Stable byte a; |
|
541 |
public @Stable A left; |
|
542 |
public A right; |
|
543 |
} |
|
544 |
||
545 |
public @Stable A v; |
|
546 |
||
547 |
public static final NestedStableField2 c = new NestedStableField2(); |
|
548 |
public static byte get() { return c.v.left.left.left.a; } |
|
549 |
public static byte get1() { return c.v.left.left.right.left.a; } |
|
550 |
||
551 |
public static void test() throws Exception { |
|
552 |
{ |
|
553 |
c.v = new A(); c.v.left = c.v.right = c.v; |
|
36508 | 554 |
c.v.a = 1; byte val1 = get(); byte val2 = get1(); |
555 |
c.v.a = 2; byte val3 = get(); byte val4 = get1(); |
|
23192 | 556 |
|
557 |
assertEquals(val1, 1); |
|
558 |
assertEquals(val3, (isStableEnabled ? 1 : 2)); |
|
559 |
||
560 |
assertEquals(val2, 1); |
|
561 |
assertEquals(val4, 2); |
|
562 |
} |
|
563 |
} |
|
564 |
} |
|
565 |
||
566 |
/* ==================================================== */ |
|
567 |
||
568 |
static class NestedStableField3 { |
|
569 |
static class A { |
|
570 |
public @Stable byte a; |
|
571 |
public @Stable A[] left; |
|
572 |
public A[] right; |
|
573 |
} |
|
574 |
||
575 |
public @Stable A[] v; |
|
576 |
||
577 |
public static final NestedStableField3 c = new NestedStableField3(); |
|
578 |
public static byte get() { return c.v[0].left[1].left[0].left[1].a; } |
|
579 |
public static byte get1() { return c.v[1].left[0].left[1].right[0].left[1].a; } |
|
580 |
||
581 |
public static void test() throws Exception { |
|
582 |
{ |
|
583 |
A elem = new A(); |
|
584 |
c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v; |
|
36508 | 585 |
elem.a = 1; byte val1 = get(); byte val2 = get1(); |
586 |
elem.a = 2; byte val3 = get(); byte val4 = get1(); |
|
23192 | 587 |
|
588 |
assertEquals(val1, 1); |
|
36604 | 589 |
assertEquals(val3, (isStableEnabled ? 1 : 2)); |
23192 | 590 |
|
591 |
assertEquals(val2, 1); |
|
592 |
assertEquals(val4, 2); |
|
593 |
} |
|
594 |
} |
|
595 |
} |
|
596 |
||
597 |
/* ==================================================== */ |
|
598 |
// Auxiliary methods |
|
599 |
static void assertEquals(int i, int j) { if (i != j) throw new AssertionError(i + " != " + j); } |
|
600 |
static void assertTrue(boolean b) { if (!b) throw new AssertionError(); } |
|
601 |
||
602 |
static boolean failed = false; |
|
603 |
||
604 |
public static void run(Class<?> test) { |
|
605 |
Throwable ex = null; |
|
606 |
System.out.print(test.getName()+": "); |
|
607 |
try { |
|
608 |
test.getMethod("test").invoke(null); |
|
609 |
} catch (InvocationTargetException e) { |
|
610 |
ex = e.getCause(); |
|
611 |
} catch (Throwable e) { |
|
612 |
ex = e; |
|
613 |
} finally { |
|
614 |
if (ex == null) { |
|
615 |
System.out.println("PASSED"); |
|
616 |
} else { |
|
617 |
failed = true; |
|
618 |
System.out.println("FAILED"); |
|
619 |
ex.printStackTrace(System.out); |
|
620 |
} |
|
621 |
} |
|
622 |
} |
|
623 |
} |