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