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