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