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