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