Mercurial > hg > graal-jvmci-8
annotate test/compiler/stable/TestStableChar.java @ 24094:9b69cec6d01b
Merge with jdk8u121-b13
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Mon, 06 Feb 2017 17:18:57 +0100 |
parents | 1ec24746bb40 |
children |
rev | line source |
---|---|
17820 | 1 /* |
2 * Copyright (c) 2014, Oracle 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. 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 TestStableChar | |
28 * @summary tests on stable fields and arrays | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
29 * @library /testlibrary /testlibrary/whitebox |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
30 * @build TestStableChar StableConfiguration sun.hotspot.WhiteBox |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
31 * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission |
17820 | 32 * @run main ClassFileInstaller |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
33 * java/lang/invoke/StableConfiguration |
17820 | 34 * java/lang/invoke/TestStableChar |
35 * java/lang/invoke/TestStableChar$CharStable | |
36 * java/lang/invoke/TestStableChar$StaticCharStable | |
37 * java/lang/invoke/TestStableChar$VolatileCharStable | |
38 * java/lang/invoke/TestStableChar$CharArrayDim1 | |
39 * java/lang/invoke/TestStableChar$CharArrayDim2 | |
40 * java/lang/invoke/TestStableChar$CharArrayDim3 | |
41 * java/lang/invoke/TestStableChar$CharArrayDim4 | |
42 * java/lang/invoke/TestStableChar$ObjectArrayLowerDim0 | |
43 * java/lang/invoke/TestStableChar$ObjectArrayLowerDim1 | |
44 * java/lang/invoke/TestStableChar$NestedStableField | |
45 * java/lang/invoke/TestStableChar$NestedStableField$A | |
46 * java/lang/invoke/TestStableChar$NestedStableField1 | |
47 * java/lang/invoke/TestStableChar$NestedStableField1$A | |
48 * java/lang/invoke/TestStableChar$NestedStableField2 | |
49 * java/lang/invoke/TestStableChar$NestedStableField2$A | |
50 * java/lang/invoke/TestStableChar$NestedStableField3 | |
51 * java/lang/invoke/TestStableChar$NestedStableField3$A | |
52 * java/lang/invoke/TestStableChar$DefaultValue | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
53 * java/lang/invoke/TestStableChar$DefaultStaticValue |
17820 | 54 * java/lang/invoke/TestStableChar$ObjectArrayLowerDim2 |
55 * | |
22983
1ec24746bb40
8038098: [TESTBUG] remove explicit set build flavor from hotspot/test/compiler/* tests
eistepan
parents:
18004
diff
changeset
|
56 * @run main/othervm -Xbootclasspath/a:. |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
57 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
22983
1ec24746bb40
8038098: [TESTBUG] remove explicit set build flavor from hotspot/test/compiler/* tests
eistepan
parents:
18004
diff
changeset
|
58 * -XX:-TieredCompilation |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
59 * -XX:+FoldStableValues |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
60 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
61 * java.lang.invoke.TestStableChar |
22983
1ec24746bb40
8038098: [TESTBUG] remove explicit set build flavor from hotspot/test/compiler/* tests
eistepan
parents:
18004
diff
changeset
|
62 * @run main/othervm -Xbootclasspath/a:. |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
63 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
22983
1ec24746bb40
8038098: [TESTBUG] remove explicit set build flavor from hotspot/test/compiler/* tests
eistepan
parents:
18004
diff
changeset
|
64 * -XX:-TieredCompilation |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
65 * -XX:-FoldStableValues |
17820 | 66 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
67 * java.lang.invoke.TestStableChar | |
68 * | |
22983
1ec24746bb40
8038098: [TESTBUG] remove explicit set build flavor from hotspot/test/compiler/* tests
eistepan
parents:
18004
diff
changeset
|
69 * @run main/othervm -Xbootclasspath/a:. |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
70 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
22983
1ec24746bb40
8038098: [TESTBUG] remove explicit set build flavor from hotspot/test/compiler/* tests
eistepan
parents:
18004
diff
changeset
|
71 * -XX:+TieredCompilation -XX:TieredStopAtLevel=1 |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
72 * -XX:+FoldStableValues |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
73 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
74 * java.lang.invoke.TestStableChar |
22983
1ec24746bb40
8038098: [TESTBUG] remove explicit set build flavor from hotspot/test/compiler/* tests
eistepan
parents:
18004
diff
changeset
|
75 * @run main/othervm -Xbootclasspath/a:. |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
76 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
22983
1ec24746bb40
8038098: [TESTBUG] remove explicit set build flavor from hotspot/test/compiler/* tests
eistepan
parents:
18004
diff
changeset
|
77 * -XX:+TieredCompilation -XX:TieredStopAtLevel=1 |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
78 * -XX:-FoldStableValues |
17820 | 79 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
80 * java.lang.invoke.TestStableChar | |
81 * | |
82 */ | |
83 package java.lang.invoke; | |
84 | |
85 import java.lang.reflect.InvocationTargetException; | |
86 | |
87 public class TestStableChar { | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
88 static final boolean isStableEnabled = StableConfiguration.isStableEnabled; |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
89 static final boolean isServerWithStable = StableConfiguration.isServerWithStable; |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
90 |
17820 | 91 public static void main(String[] args) throws Exception { |
92 run(DefaultValue.class); | |
93 run(CharStable.class); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
94 run(DefaultStaticValue.class); |
17820 | 95 run(StaticCharStable.class); |
96 run(VolatileCharStable.class); | |
97 | |
98 // @Stable arrays: Dim 1-4 | |
99 run(CharArrayDim1.class); | |
100 run(CharArrayDim2.class); | |
101 run(CharArrayDim3.class); | |
102 run(CharArrayDim4.class); | |
103 | |
104 // @Stable Object field: dynamic arrays | |
105 run(ObjectArrayLowerDim0.class); | |
106 run(ObjectArrayLowerDim1.class); | |
107 run(ObjectArrayLowerDim2.class); | |
108 | |
109 // Nested @Stable fields | |
110 run(NestedStableField.class); | |
111 run(NestedStableField1.class); | |
112 run(NestedStableField2.class); | |
113 run(NestedStableField3.class); | |
114 | |
115 if (failed) { | |
116 throw new Error("TEST FAILED"); | |
117 } | |
118 } | |
119 | |
120 /* ==================================================== */ | |
121 | |
122 static class DefaultValue { | |
123 public @Stable char v; | |
124 | |
125 public static final DefaultValue c = new DefaultValue(); | |
126 public static char get() { return c.v; } | |
127 public static void test() throws Exception { | |
128 char val1 = get(); | |
129 c.v = 'a'; char val2 = get(); | |
130 assertEquals(val1, 0); | |
131 assertEquals(val2, 'a'); | |
132 } | |
133 } | |
134 | |
135 /* ==================================================== */ | |
136 | |
137 static class CharStable { | |
138 public @Stable char v; | |
139 | |
140 public static final CharStable c = new CharStable(); | |
141 public static char get() { return c.v; } | |
142 public static void test() throws Exception { | |
143 c.v = 'a'; char val1 = get(); | |
144 c.v = 'b'; char val2 = get(); | |
145 assertEquals(val1, 'a'); | |
146 assertEquals(val2, (isStableEnabled ? 'a' : 'b')); | |
147 } | |
148 } | |
149 | |
150 /* ==================================================== */ | |
151 | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
152 static class DefaultStaticValue { |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
153 public static @Stable char v; |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
154 |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
155 public static final DefaultStaticValue c = new DefaultStaticValue(); |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
156 public static char get() { return c.v; } |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
157 public static void test() throws Exception { |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
158 char val1 = get(); |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
159 c.v = 'a'; char val2 = get(); |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
160 assertEquals(val1, 0); |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
161 assertEquals(val2, 'a'); |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
162 } |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
163 } |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
164 |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
165 /* ==================================================== */ |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
166 |
17820 | 167 static class StaticCharStable { |
168 public @Stable char v; | |
169 | |
170 public static final StaticCharStable c = new StaticCharStable(); | |
171 public static char get() { return c.v; } | |
172 public static void test() throws Exception { | |
173 c.v = 'a'; char val1 = get(); | |
174 c.v = 'b'; char val2 = get(); | |
175 assertEquals(val1, 'a'); | |
176 assertEquals(val2, (isStableEnabled ? 'a' : 'b')); | |
177 } | |
178 } | |
179 | |
180 /* ==================================================== */ | |
181 | |
182 static class VolatileCharStable { | |
183 public @Stable volatile char v; | |
184 | |
185 public static final VolatileCharStable c = new VolatileCharStable(); | |
186 public static char get() { return c.v; } | |
187 public static void test() throws Exception { | |
188 c.v = 'a'; char val1 = get(); | |
189 c.v = 'b'; char val2 = get(); | |
190 assertEquals(val1, 'a'); | |
191 assertEquals(val2, (isStableEnabled ? 'a' : 'b')); | |
192 } | |
193 } | |
194 | |
195 /* ==================================================== */ | |
196 // @Stable array == field && all components are stable | |
197 | |
198 static class CharArrayDim1 { | |
199 public @Stable char[] v; | |
200 | |
201 public static final CharArrayDim1 c = new CharArrayDim1(); | |
202 public static char get() { return c.v[0]; } | |
203 public static char get1() { return c.v[10]; } | |
204 public static char[] get2() { return c.v; } | |
205 public static void test() throws Exception { | |
206 { | |
207 c.v = new char[1]; c.v[0] = 'a'; char val1 = get(); | |
208 c.v[0] = 'b'; char val2 = get(); | |
209 assertEquals(val1, 'a'); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
210 assertEquals(val2, (isServerWithStable ? 'a' : 'b')); |
17820 | 211 |
212 c.v = new char[1]; c.v[0] = 'c'; char val3 = get(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
213 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
214 : 'c')); |
17820 | 215 } |
216 | |
217 { | |
218 c.v = new char[20]; c.v[10] = 'a'; char val1 = get1(); | |
219 c.v[10] = 'b'; char val2 = get1(); | |
220 assertEquals(val1, 'a'); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
221 assertEquals(val2, (isServerWithStable ? 'a' : 'b')); |
17820 | 222 |
223 c.v = new char[20]; c.v[10] = 'c'; char val3 = get1(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
224 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
225 : 'c')); |
17820 | 226 } |
227 | |
228 { | |
229 c.v = new char[1]; char[] val1 = get2(); | |
230 c.v = new char[1]; char[] val2 = get2(); | |
231 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
232 } | |
233 } | |
234 } | |
235 | |
236 /* ==================================================== */ | |
237 | |
238 static class CharArrayDim2 { | |
239 public @Stable char[][] v; | |
240 | |
241 public static final CharArrayDim2 c = new CharArrayDim2(); | |
242 public static char get() { return c.v[0][0]; } | |
243 public static char[] get1() { return c.v[0]; } | |
244 public static char[][] get2() { return c.v; } | |
245 public static void test() throws Exception { | |
246 { | |
247 c.v = new char[1][1]; c.v[0][0] = 'a'; char val1 = get(); | |
248 c.v[0][0] = 'b'; char val2 = get(); | |
249 assertEquals(val1, 'a'); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
250 assertEquals(val2, (isServerWithStable ? 'a' : 'b')); |
17820 | 251 |
252 c.v = new char[1][1]; c.v[0][0] = 'c'; char val3 = get(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
253 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
254 : 'c')); |
17820 | 255 |
256 c.v[0] = new char[1]; c.v[0][0] = 'd'; char val4 = get(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
257 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
258 : 'd')); |
17820 | 259 } |
260 | |
261 { | |
262 c.v = new char[1][1]; char[] val1 = get1(); | |
263 c.v[0] = new char[1]; char[] val2 = get1(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
264 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 265 } |
266 | |
267 { | |
268 c.v = new char[1][1]; char[][] val1 = get2(); | |
269 c.v = new char[1][1]; char[][] val2 = get2(); | |
270 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
271 } | |
272 } | |
273 } | |
274 | |
275 /* ==================================================== */ | |
276 | |
277 static class CharArrayDim3 { | |
278 public @Stable char[][][] v; | |
279 | |
280 public static final CharArrayDim3 c = new CharArrayDim3(); | |
281 public static char get() { return c.v[0][0][0]; } | |
282 public static char[] get1() { return c.v[0][0]; } | |
283 public static char[][] get2() { return c.v[0]; } | |
284 public static char[][][] get3() { return c.v; } | |
285 public static void test() throws Exception { | |
286 { | |
287 c.v = new char[1][1][1]; c.v[0][0][0] = 'a'; char val1 = get(); | |
288 c.v[0][0][0] = 'b'; char val2 = get(); | |
289 assertEquals(val1, 'a'); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
290 assertEquals(val2, (isServerWithStable ? 'a' : 'b')); |
17820 | 291 |
292 c.v = new char[1][1][1]; c.v[0][0][0] = 'c'; char val3 = get(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
293 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
294 : 'c')); |
17820 | 295 |
296 c.v[0] = new char[1][1]; c.v[0][0][0] = 'd'; char val4 = get(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
297 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
298 : 'd')); |
17820 | 299 |
300 c.v[0][0] = new char[1]; c.v[0][0][0] = 'e'; char val5 = get(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
301 assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
302 : 'e')); |
17820 | 303 } |
304 | |
305 { | |
306 c.v = new char[1][1][1]; char[] val1 = get1(); | |
307 c.v[0][0] = new char[1]; char[] val2 = get1(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
308 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 309 } |
310 | |
311 { | |
312 c.v = new char[1][1][1]; char[][] val1 = get2(); | |
313 c.v[0] = new char[1][1]; char[][] val2 = get2(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
314 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 315 } |
316 | |
317 { | |
318 c.v = new char[1][1][1]; char[][][] val1 = get3(); | |
319 c.v = new char[1][1][1]; char[][][] val2 = get3(); | |
320 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
321 } | |
322 } | |
323 } | |
324 | |
325 /* ==================================================== */ | |
326 | |
327 static class CharArrayDim4 { | |
328 public @Stable char[][][][] v; | |
329 | |
330 public static final CharArrayDim4 c = new CharArrayDim4(); | |
331 public static char get() { return c.v[0][0][0][0]; } | |
332 public static char[] get1() { return c.v[0][0][0]; } | |
333 public static char[][] get2() { return c.v[0][0]; } | |
334 public static char[][][] get3() { return c.v[0]; } | |
335 public static char[][][][] get4() { return c.v; } | |
336 public static void test() throws Exception { | |
337 { | |
338 c.v = new char[1][1][1][1]; c.v[0][0][0][0] = 'a'; char val1 = get(); | |
339 c.v[0][0][0][0] = 'b'; char val2 = get(); | |
340 assertEquals(val1, 'a'); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
341 assertEquals(val2, (isServerWithStable ? 'a' : 'b')); |
17820 | 342 |
343 c.v = new char[1][1][1][1]; c.v[0][0][0][0] = 'c'; char val3 = get(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
344 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
345 : 'c')); |
17820 | 346 |
347 c.v[0] = new char[1][1][1]; c.v[0][0][0][0] = 'd'; char val4 = get(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
348 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
349 : 'd')); |
17820 | 350 |
351 c.v[0][0] = new char[1][1]; c.v[0][0][0][0] = 'e'; char val5 = get(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
352 assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
353 : 'e')); |
17820 | 354 |
355 c.v[0][0][0] = new char[1]; c.v[0][0][0][0] = 'f'; char val6 = get(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
356 assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 'a' : 'b') |
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
357 : 'f')); |
17820 | 358 } |
359 | |
360 { | |
361 c.v = new char[1][1][1][1]; char[] val1 = get1(); | |
362 c.v[0][0][0] = new char[1]; char[] val2 = get1(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
363 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 364 } |
365 | |
366 { | |
367 c.v = new char[1][1][1][1]; char[][] val1 = get2(); | |
368 c.v[0][0] = new char[1][1]; char[][] val2 = get2(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
369 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 370 } |
371 | |
372 { | |
373 c.v = new char[1][1][1][1]; char[][][] val1 = get3(); | |
374 c.v[0] = new char[1][1][1]; char[][][] val2 = get3(); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
375 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 376 } |
377 | |
378 { | |
379 c.v = new char[1][1][1][1]; char[][][][] val1 = get4(); | |
380 c.v = new char[1][1][1][1]; char[][][][] val2 = get4(); | |
381 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
382 } | |
383 } | |
384 } | |
385 | |
386 /* ==================================================== */ | |
387 // Dynamic Dim is higher than static | |
388 static class ObjectArrayLowerDim0 { | |
389 public @Stable Object v; | |
390 | |
391 public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0(); | |
392 public static char get() { return ((char[])c.v)[0]; } | |
393 public static char[] get1() { return (char[])c.v; } | |
394 | |
395 public static void test() throws Exception { | |
396 { | |
397 c.v = new char[1]; ((char[])c.v)[0] = 'a'; char val1 = get(); | |
398 ((char[])c.v)[0] = 'b'; char val2 = get(); | |
399 | |
400 assertEquals(val1, 'a'); | |
401 assertEquals(val2, 'b'); | |
402 } | |
403 | |
404 { | |
405 c.v = new char[1]; char[] val1 = get1(); | |
406 c.v = new char[1]; char[] val2 = get1(); | |
407 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
408 } | |
409 } | |
410 } | |
411 | |
412 /* ==================================================== */ | |
413 | |
414 static class ObjectArrayLowerDim1 { | |
415 public @Stable Object[] v; | |
416 | |
417 public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1(); | |
418 public static char get() { return ((char[][])c.v)[0][0]; } | |
419 public static char[] get1() { return (char[])(c.v[0]); } | |
420 public static Object[] get2() { return c.v; } | |
421 | |
422 public static void test() throws Exception { | |
423 { | |
424 c.v = new char[1][1]; ((char[][])c.v)[0][0] = 'a'; char val1 = get(); | |
425 ((char[][])c.v)[0][0] = 'b'; char val2 = get(); | |
426 | |
427 assertEquals(val1, 'a'); | |
428 assertEquals(val2, 'b'); | |
429 } | |
430 | |
431 { | |
432 c.v = new char[1][1]; c.v[0] = new char[0]; char[] val1 = get1(); | |
433 c.v[0] = new char[0]; char[] val2 = get1(); | |
434 | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
435 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 436 } |
437 | |
438 { | |
439 c.v = new char[0][0]; Object[] val1 = get2(); | |
440 c.v = new char[0][0]; Object[] val2 = get2(); | |
441 | |
442 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
443 } | |
444 } | |
445 } | |
446 | |
447 /* ==================================================== */ | |
448 | |
449 static class ObjectArrayLowerDim2 { | |
450 public @Stable Object[][] v; | |
451 | |
452 public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2(); | |
453 public static char get() { return ((char[][][])c.v)[0][0][0]; } | |
454 public static char[] get1() { return (char[])(c.v[0][0]); } | |
455 public static char[][] get2() { return (char[][])(c.v[0]); } | |
456 public static Object[][] get3() { return c.v; } | |
457 | |
458 public static void test() throws Exception { | |
459 { | |
460 c.v = new char[1][1][1]; ((char[][][])c.v)[0][0][0] = 'a'; char val1 = get(); | |
461 ((char[][][])c.v)[0][0][0] = 'b'; char val2 = get(); | |
462 | |
463 assertEquals(val1, 'a'); | |
464 assertEquals(val2, 'b'); | |
465 } | |
466 | |
467 { | |
468 c.v = new char[1][1][1]; c.v[0][0] = new char[0]; char[] val1 = get1(); | |
469 c.v[0][0] = new char[0]; char[] val2 = get1(); | |
470 | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
471 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 472 } |
473 | |
474 { | |
475 c.v = new char[1][1][1]; c.v[0] = new char[0][0]; char[][] val1 = get2(); | |
476 c.v[0] = new char[0][0]; char[][] val2 = get2(); | |
477 | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
478 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 479 } |
480 | |
481 { | |
482 c.v = new char[0][0][0]; Object[][] val1 = get3(); | |
483 c.v = new char[0][0][0]; Object[][] val2 = get3(); | |
484 | |
485 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
486 } | |
487 } | |
488 } | |
489 | |
490 /* ==================================================== */ | |
491 | |
492 static class NestedStableField { | |
493 static class A { | |
494 public @Stable char a; | |
495 | |
496 } | |
497 public @Stable A v; | |
498 | |
499 public static final NestedStableField c = new NestedStableField(); | |
500 public static A get() { return c.v; } | |
501 public static char get1() { return get().a; } | |
502 | |
503 public static void test() throws Exception { | |
504 { | |
505 c.v = new A(); c.v.a = 'a'; A val1 = get(); | |
506 c.v.a = 'b'; A val2 = get(); | |
507 | |
508 assertEquals(val1.a, 'b'); | |
509 assertEquals(val2.a, 'b'); | |
510 } | |
511 | |
512 { | |
513 c.v = new A(); c.v.a = 'a'; char val1 = get1(); | |
514 c.v.a = 'b'; char val2 = get1(); | |
515 c.v = new A(); c.v.a = 'c'; char val3 = get1(); | |
516 | |
517 assertEquals(val1, 'a'); | |
518 assertEquals(val2, (isStableEnabled ? 'a' : 'b')); | |
519 assertEquals(val3, (isStableEnabled ? 'a' : 'c')); | |
520 } | |
521 } | |
522 } | |
523 | |
524 /* ==================================================== */ | |
525 | |
526 static class NestedStableField1 { | |
527 static class A { | |
528 public @Stable char a; | |
529 public @Stable A next; | |
530 } | |
531 public @Stable A v; | |
532 | |
533 public static final NestedStableField1 c = new NestedStableField1(); | |
534 public static A get() { return c.v.next.next.next.next.next.next.next; } | |
535 public static char get1() { return get().a; } | |
536 | |
537 public static void test() throws Exception { | |
538 { | |
539 c.v = new A(); c.v.next = new A(); c.v.next.next = c.v; | |
540 c.v.a = 'a'; c.v.next.a = 'a'; A val1 = get(); | |
541 c.v.a = 'b'; c.v.next.a = 'b'; A val2 = get(); | |
542 | |
543 assertEquals(val1.a, 'b'); | |
544 assertEquals(val2.a, 'b'); | |
545 } | |
546 | |
547 { | |
548 c.v = new A(); c.v.next = c.v; | |
549 c.v.a = 'a'; char val1 = get1(); | |
550 c.v.a = 'b'; char val2 = get1(); | |
551 c.v = new A(); c.v.next = c.v; | |
552 c.v.a = 'c'; char val3 = get1(); | |
553 | |
554 assertEquals(val1, 'a'); | |
555 assertEquals(val2, (isStableEnabled ? 'a' : 'b')); | |
556 assertEquals(val3, (isStableEnabled ? 'a' : 'c')); | |
557 } | |
558 } | |
559 } | |
560 /* ==================================================== */ | |
561 | |
562 static class NestedStableField2 { | |
563 static class A { | |
564 public @Stable char a; | |
565 public @Stable A left; | |
566 public A right; | |
567 } | |
568 | |
569 public @Stable A v; | |
570 | |
571 public static final NestedStableField2 c = new NestedStableField2(); | |
572 public static char get() { return c.v.left.left.left.a; } | |
573 public static char get1() { return c.v.left.left.right.left.a; } | |
574 | |
575 public static void test() throws Exception { | |
576 { | |
577 c.v = new A(); c.v.left = c.v.right = c.v; | |
578 c.v.a = 'a'; char val1 = get(); char val2 = get1(); | |
579 c.v.a = 'b'; char val3 = get(); char val4 = get1(); | |
580 | |
581 assertEquals(val1, 'a'); | |
582 assertEquals(val3, (isStableEnabled ? 'a' : 'b')); | |
583 | |
584 assertEquals(val2, 'a'); | |
585 assertEquals(val4, 'b'); | |
586 } | |
587 } | |
588 } | |
589 | |
590 /* ==================================================== */ | |
591 | |
592 static class NestedStableField3 { | |
593 static class A { | |
594 public @Stable char a; | |
595 public @Stable A[] left; | |
596 public A[] right; | |
597 } | |
598 | |
599 public @Stable A[] v; | |
600 | |
601 public static final NestedStableField3 c = new NestedStableField3(); | |
602 public static char get() { return c.v[0].left[1].left[0].left[1].a; } | |
603 public static char get1() { return c.v[1].left[0].left[1].right[0].left[1].a; } | |
604 | |
605 public static void test() throws Exception { | |
606 { | |
607 A elem = new A(); | |
608 c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v; | |
609 elem.a = 'a'; char val1 = get(); char val2 = get1(); | |
610 elem.a = 'b'; char val3 = get(); char val4 = get1(); | |
611 | |
612 assertEquals(val1, 'a'); | |
18004
ee1c924763d2
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
613 assertEquals(val3, (isServerWithStable ? 'a' : 'b')); |
17820 | 614 |
615 assertEquals(val2, 'a'); | |
616 assertEquals(val4, 'b'); | |
617 } | |
618 } | |
619 } | |
620 | |
621 /* ==================================================== */ | |
622 // Auxiliary methods | |
623 static void assertEquals(int i, int j) { if (i != j) throw new AssertionError(i + " != " + j); } | |
624 static void assertTrue(boolean b) { if (!b) throw new AssertionError(); } | |
625 | |
626 static boolean failed = false; | |
627 | |
628 public static void run(Class<?> test) { | |
629 Throwable ex = null; | |
630 System.out.print(test.getName()+": "); | |
631 try { | |
632 test.getMethod("test").invoke(null); | |
633 } catch (InvocationTargetException e) { | |
634 ex = e.getCause(); | |
635 } catch (Throwable e) { | |
636 ex = e; | |
637 } finally { | |
638 if (ex == null) { | |
639 System.out.println("PASSED"); | |
640 } else { | |
641 failed = true; | |
642 System.out.println("FAILED"); | |
643 ex.printStackTrace(System.out); | |
644 } | |
645 } | |
646 } | |
647 } |