Mercurial > hg > truffle
annotate test/compiler/stable/TestStableByte.java @ 20228:f72d8917322a
8050978: Fix bad field access check in C1 and C2
Summary: JCK8 test vm/constantpool/accessControl/accessControl004/accessControl00402m3/accessControl00402m3.html fails with -Xbatch -Xcomp due to bad field access check in C1 and C2. Fix: In ciField::ciField(), just before the canonical holder is stored into the _holder variable (and which is used by ciField::will_link()) perform an additional access check with the holder declared in the class file. If this check fails, store the declared holder instead and ciField::will_link() will bail out compilation for this field later on. Then, the interpreter will throw an PrivilegedAccessException at runtime.
Reviewed-by: kvn, vlivanov
Contributed-by: andreas.schoesser@sap.com
author | goetz |
---|---|
date | Fri, 18 Jul 2014 09:04:01 +0200 |
parents | 5fbeae2a02d3 |
children |
rev | line source |
---|---|
17820 | 1 /* |
2 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
5 * This code is free software; you can redistribute it and/or modify it | |
6 * under the terms of the GNU General Public License version 2 only, as | |
7 * published by the Free Software Foundation. Oracle designates this | |
8 * particular file as subject to the "Classpath" exception as provided | |
9 * by Oracle in the LICENSE file that accompanied this code. | |
10 * | |
11 * This code is distributed in the hope that it will be useful, but WITHOUT | |
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
14 * version 2 for more details (a copy is included in the LICENSE file that | |
15 * accompanied this code). | |
16 * | |
17 * You should have received a copy of the GNU General Public License version | |
18 * 2 along with this work; if not, write to the Free Software Foundation, | |
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 * | |
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | |
22 * or visit www.oracle.com if you need additional information or have any | |
23 * questions. | |
24 */ | |
25 | |
26 /* | |
27 * @test TestStableByte | |
28 * @summary tests on stable fields and arrays | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
29 * @library /testlibrary /testlibrary/whitebox |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
30 * @build TestStableByte StableConfiguration sun.hotspot.WhiteBox |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
31 * @run main ClassFileInstaller sun.hotspot.WhiteBox sun.hotspot.WhiteBox$WhiteBoxPermission |
17820 | 32 * @run main ClassFileInstaller |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
33 * java/lang/invoke/StableConfiguration |
17820 | 34 * java/lang/invoke/TestStableByte |
35 * java/lang/invoke/TestStableByte$ByteStable | |
36 * java/lang/invoke/TestStableByte$StaticByteStable | |
37 * java/lang/invoke/TestStableByte$VolatileByteStable | |
38 * java/lang/invoke/TestStableByte$ByteArrayDim1 | |
39 * java/lang/invoke/TestStableByte$ByteArrayDim2 | |
40 * java/lang/invoke/TestStableByte$ByteArrayDim3 | |
41 * java/lang/invoke/TestStableByte$ByteArrayDim4 | |
42 * java/lang/invoke/TestStableByte$ObjectArrayLowerDim0 | |
43 * java/lang/invoke/TestStableByte$ObjectArrayLowerDim1 | |
44 * java/lang/invoke/TestStableByte$NestedStableField | |
45 * java/lang/invoke/TestStableByte$NestedStableField$A | |
46 * java/lang/invoke/TestStableByte$NestedStableField1 | |
47 * java/lang/invoke/TestStableByte$NestedStableField1$A | |
48 * java/lang/invoke/TestStableByte$NestedStableField2 | |
49 * java/lang/invoke/TestStableByte$NestedStableField2$A | |
50 * java/lang/invoke/TestStableByte$NestedStableField3 | |
51 * java/lang/invoke/TestStableByte$NestedStableField3$A | |
52 * java/lang/invoke/TestStableByte$DefaultValue | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
53 * java/lang/invoke/TestStableByte$DefaultStaticValue |
17820 | 54 * java/lang/invoke/TestStableByte$ObjectArrayLowerDim2 |
55 * | |
56 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
57 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
58 * -server -XX:-TieredCompilation |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
59 * -XX:+FoldStableValues |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
60 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
61 * java.lang.invoke.TestStableByte |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
62 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
63 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
64 * -server -XX:-TieredCompilation |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
65 * -XX:-FoldStableValues |
17820 | 66 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
67 * java.lang.invoke.TestStableByte | |
68 * | |
69 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
70 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
71 * -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1 |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
72 * -XX:+FoldStableValues |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
73 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
74 * java.lang.invoke.TestStableByte |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
75 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
76 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
77 * -server -XX:+TieredCompilation -XX:TieredStopAtLevel=1 |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
78 * -XX:-FoldStableValues |
17820 | 79 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
80 * java.lang.invoke.TestStableByte | |
81 * | |
82 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
83 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
84 * -client -XX:-TieredCompilation |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
85 * -XX:+FoldStableValues |
17820 | 86 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
87 * java.lang.invoke.TestStableByte | |
88 * @run main/othervm -Xbootclasspath/a:. -XX:+IgnoreUnrecognizedVMOptions | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
89 * -XX:+UnlockDiagnosticVMOptions -XX:+WhiteBoxAPI -Xcomp |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
90 * -client -XX:-TieredCompilation |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
91 * -XX:-FoldStableValues |
17820 | 92 * -XX:CompileOnly=::get,::get1,::get2,::get3,::get4 |
93 * java.lang.invoke.TestStableByte | |
94 */ | |
95 package java.lang.invoke; | |
96 | |
97 import java.lang.reflect.InvocationTargetException; | |
98 | |
99 public class TestStableByte { | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
100 static final boolean isStableEnabled = StableConfiguration.isStableEnabled; |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
101 static final boolean isServerWithStable = StableConfiguration.isServerWithStable; |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
102 |
17820 | 103 public static void main(String[] args) throws Exception { |
104 run(DefaultValue.class); | |
105 run(ByteStable.class); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
106 run(DefaultStaticValue.class); |
17820 | 107 run(StaticByteStable.class); |
108 run(VolatileByteStable.class); | |
109 | |
110 // @Stable arrays: Dim 1-4 | |
111 run(ByteArrayDim1.class); | |
112 run(ByteArrayDim2.class); | |
113 run(ByteArrayDim3.class); | |
114 run(ByteArrayDim4.class); | |
115 | |
116 // @Stable Object field: dynamic arrays | |
117 run(ObjectArrayLowerDim0.class); | |
118 run(ObjectArrayLowerDim1.class); | |
119 run(ObjectArrayLowerDim2.class); | |
120 | |
121 // Nested @Stable fields | |
122 run(NestedStableField.class); | |
123 run(NestedStableField1.class); | |
124 run(NestedStableField2.class); | |
125 run(NestedStableField3.class); | |
126 | |
127 if (failed) { | |
128 throw new Error("TEST FAILED"); | |
129 } | |
130 } | |
131 | |
132 /* ==================================================== */ | |
133 | |
134 static class DefaultValue { | |
135 public @Stable byte v; | |
136 | |
137 public static final DefaultValue c = new DefaultValue(); | |
138 public static byte get() { return c.v; } | |
139 public static void test() throws Exception { | |
140 byte val1 = get(); | |
141 c.v = 1; byte val2 = get(); | |
142 assertEquals(val1, 0); | |
143 assertEquals(val2, 1); | |
144 } | |
145 } | |
146 | |
147 /* ==================================================== */ | |
148 | |
149 static class ByteStable { | |
150 public @Stable byte v; | |
151 | |
152 public static final ByteStable c = new ByteStable(); | |
153 public static byte get() { return c.v; } | |
154 public static void test() throws Exception { | |
155 c.v = 5; byte val1 = get(); | |
156 c.v = 127; byte val2 = get(); | |
157 assertEquals(val1, 5); | |
158 assertEquals(val2, (isStableEnabled ? 5 : 127)); | |
159 } | |
160 } | |
161 | |
162 /* ==================================================== */ | |
163 | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
164 static class DefaultStaticValue { |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
165 public static @Stable byte v; |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
166 |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
167 public static final DefaultStaticValue c = new DefaultStaticValue(); |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
168 public static byte get() { return c.v; } |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
169 public static void test() throws Exception { |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
170 byte val1 = get(); |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
171 c.v = 1; byte val2 = get(); |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
172 assertEquals(val1, 0); |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
173 assertEquals(val2, 1); |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
174 } |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
175 } |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
176 |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
177 /* ==================================================== */ |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
178 |
17820 | 179 static class StaticByteStable { |
180 public static @Stable byte v; | |
181 | |
182 public static final StaticByteStable c = new StaticByteStable(); | |
183 public static byte get() { return c.v; } | |
184 public static void test() throws Exception { | |
185 c.v = 5; byte val1 = get(); | |
186 c.v = 127; byte val2 = get(); | |
187 assertEquals(val1, 5); | |
188 assertEquals(val2, (isStableEnabled ? 5 : 127)); | |
189 } | |
190 } | |
191 | |
192 /* ==================================================== */ | |
193 | |
194 static class VolatileByteStable { | |
195 public @Stable volatile byte v; | |
196 | |
197 public static final VolatileByteStable c = new VolatileByteStable(); | |
198 public static byte get() { return c.v; } | |
199 public static void test() throws Exception { | |
200 c.v = 5; byte val1 = get(); | |
201 c.v = 127; byte val2 = get(); | |
202 assertEquals(val1, 5); | |
203 assertEquals(val2, (isStableEnabled ? 5 : 127)); | |
204 } | |
205 } | |
206 | |
207 /* ==================================================== */ | |
208 // @Stable array == field && all components are stable | |
209 | |
210 static class ByteArrayDim1 { | |
211 public @Stable byte[] v; | |
212 | |
213 public static final ByteArrayDim1 c = new ByteArrayDim1(); | |
214 public static byte get() { return c.v[0]; } | |
215 public static byte get1() { return c.v[10]; } | |
216 public static byte[] get2() { return c.v; } | |
217 public static void test() throws Exception { | |
218 { | |
219 c.v = new byte[1]; c.v[0] = 1; byte val1 = get(); | |
220 c.v[0] = 2; byte val2 = get(); | |
221 assertEquals(val1, 1); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
222 assertEquals(val2, (isServerWithStable ? 1 : 2)); |
17820 | 223 |
224 c.v = new byte[1]; c.v[0] = 3; byte val3 = get(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
225 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
226 : 3)); |
17820 | 227 } |
228 | |
229 { | |
230 c.v = new byte[20]; c.v[10] = 1; byte val1 = get1(); | |
231 c.v[10] = 2; byte val2 = get1(); | |
232 assertEquals(val1, 1); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
233 assertEquals(val2, (isServerWithStable ? 1 : 2)); |
17820 | 234 |
235 c.v = new byte[20]; c.v[10] = 3; byte val3 = get1(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
236 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
237 : 3)); |
17820 | 238 } |
239 | |
240 { | |
241 c.v = new byte[1]; byte[] val1 = get2(); | |
242 c.v = new byte[1]; byte[] val2 = get2(); | |
243 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
244 } | |
245 } | |
246 } | |
247 | |
248 /* ==================================================== */ | |
249 | |
250 static class ByteArrayDim2 { | |
251 public @Stable byte[][] v; | |
252 | |
253 public static final ByteArrayDim2 c = new ByteArrayDim2(); | |
254 public static byte get() { return c.v[0][0]; } | |
255 public static byte[] get1() { return c.v[0]; } | |
256 public static byte[][] get2() { return c.v; } | |
257 public static void test() throws Exception { | |
258 { | |
259 c.v = new byte[1][1]; c.v[0][0] = 1; byte val1 = get(); | |
260 c.v[0][0] = 2; byte val2 = get(); | |
261 assertEquals(val1, 1); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
262 assertEquals(val2, (isServerWithStable ? 1 : 2)); |
17820 | 263 |
264 c.v = new byte[1][1]; c.v[0][0] = 3; byte val3 = get(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
265 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
266 : 3)); |
17820 | 267 |
268 c.v[0] = new byte[1]; c.v[0][0] = 4; byte val4 = get(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
269 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
270 : 4)); |
17820 | 271 } |
272 | |
273 { | |
274 c.v = new byte[1][1]; byte[] val1 = get1(); | |
275 c.v[0] = new byte[1]; byte[] val2 = get1(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
276 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 277 } |
278 | |
279 { | |
280 c.v = new byte[1][1]; byte[][] val1 = get2(); | |
281 c.v = new byte[1][1]; byte[][] val2 = get2(); | |
282 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
283 } | |
284 } | |
285 } | |
286 | |
287 /* ==================================================== */ | |
288 | |
289 static class ByteArrayDim3 { | |
290 public @Stable byte[][][] v; | |
291 | |
292 public static final ByteArrayDim3 c = new ByteArrayDim3(); | |
293 public static byte get() { return c.v[0][0][0]; } | |
294 public static byte[] get1() { return c.v[0][0]; } | |
295 public static byte[][] get2() { return c.v[0]; } | |
296 public static byte[][][] get3() { return c.v; } | |
297 public static void test() throws Exception { | |
298 { | |
299 c.v = new byte[1][1][1]; c.v[0][0][0] = 1; byte val1 = get(); | |
300 c.v[0][0][0] = 2; byte val2 = get(); | |
301 assertEquals(val1, 1); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
302 assertEquals(val2, (isServerWithStable ? 1 : 2)); |
17820 | 303 |
304 c.v = new byte[1][1][1]; c.v[0][0][0] = 3; byte val3 = get(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
305 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
306 : 3)); |
17820 | 307 |
308 c.v[0] = new byte[1][1]; c.v[0][0][0] = 4; byte val4 = get(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
309 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
310 : 4)); |
17820 | 311 |
312 c.v[0][0] = new byte[1]; c.v[0][0][0] = 5; byte val5 = get(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
313 assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
314 : 5)); |
17820 | 315 } |
316 | |
317 { | |
318 c.v = new byte[1][1][1]; byte[] val1 = get1(); | |
319 c.v[0][0] = new byte[1]; byte[] val2 = get1(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
320 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 321 } |
322 | |
323 { | |
324 c.v = new byte[1][1][1]; byte[][] val1 = get2(); | |
325 c.v[0] = new byte[1][1]; byte[][] val2 = get2(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
326 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 327 } |
328 | |
329 { | |
330 c.v = new byte[1][1][1]; byte[][][] val1 = get3(); | |
331 c.v = new byte[1][1][1]; byte[][][] val2 = get3(); | |
332 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
333 } | |
334 } | |
335 } | |
336 | |
337 /* ==================================================== */ | |
338 | |
339 static class ByteArrayDim4 { | |
340 public @Stable byte[][][][] v; | |
341 | |
342 public static final ByteArrayDim4 c = new ByteArrayDim4(); | |
343 public static byte get() { return c.v[0][0][0][0]; } | |
344 public static byte[] get1() { return c.v[0][0][0]; } | |
345 public static byte[][] get2() { return c.v[0][0]; } | |
346 public static byte[][][] get3() { return c.v[0]; } | |
347 public static byte[][][][] get4() { return c.v; } | |
348 public static void test() throws Exception { | |
349 { | |
350 c.v = new byte[1][1][1][1]; c.v[0][0][0][0] = 1; byte val1 = get(); | |
351 c.v[0][0][0][0] = 2; byte val2 = get(); | |
352 assertEquals(val1, 1); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
353 assertEquals(val2, (isServerWithStable ? 1 : 2)); |
17820 | 354 |
355 c.v = new byte[1][1][1][1]; c.v[0][0][0][0] = 3; byte val3 = get(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
356 assertEquals(val3, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
357 : 3)); |
17820 | 358 |
359 c.v[0] = new byte[1][1][1]; c.v[0][0][0][0] = 4; byte val4 = get(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
360 assertEquals(val4, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
361 : 4)); |
17820 | 362 |
363 c.v[0][0] = new byte[1][1]; c.v[0][0][0][0] = 5; byte val5 = get(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
364 assertEquals(val5, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
365 : 5)); |
17820 | 366 |
367 c.v[0][0][0] = new byte[1]; c.v[0][0][0][0] = 6; byte val6 = get(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
368 assertEquals(val6, (isStableEnabled ? (isServerWithStable ? 1 : 2) |
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
369 : 6)); |
17820 | 370 } |
371 | |
372 { | |
373 c.v = new byte[1][1][1][1]; byte[] val1 = get1(); | |
374 c.v[0][0][0] = new byte[1]; byte[] val2 = get1(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
375 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 376 } |
377 | |
378 { | |
379 c.v = new byte[1][1][1][1]; byte[][] val1 = get2(); | |
380 c.v[0][0] = new byte[1][1]; byte[][] val2 = get2(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
381 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 382 } |
383 | |
384 { | |
385 c.v = new byte[1][1][1][1]; byte[][][] val1 = get3(); | |
386 c.v[0] = new byte[1][1][1]; byte[][][] val2 = get3(); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
387 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 388 } |
389 | |
390 { | |
391 c.v = new byte[1][1][1][1]; byte[][][][] val1 = get4(); | |
392 c.v = new byte[1][1][1][1]; byte[][][][] val2 = get4(); | |
393 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
394 } | |
395 | |
396 } | |
397 } | |
398 | |
399 /* ==================================================== */ | |
400 // Dynamic Dim is higher than static | |
401 | |
402 static class ObjectArrayLowerDim0 { | |
403 public @Stable Object v; | |
404 | |
405 public static final ObjectArrayLowerDim0 c = new ObjectArrayLowerDim0(); | |
406 public static byte get() { return ((byte[])c.v)[0]; } | |
407 public static byte[] get1() { return (byte[])c.v; } | |
408 | |
409 public static void test() throws Exception { | |
410 { | |
411 c.v = new byte[1]; ((byte[])c.v)[0] = 1; byte val1 = get(); | |
412 ((byte[])c.v)[0] = 2; byte val2 = get(); | |
413 | |
414 assertEquals(val1, 1); | |
415 assertEquals(val2, 2); | |
416 } | |
417 | |
418 { | |
419 c.v = new byte[1]; byte[] val1 = get1(); | |
420 c.v = new byte[1]; byte[] val2 = get1(); | |
421 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
422 } | |
423 } | |
424 } | |
425 | |
426 /* ==================================================== */ | |
427 | |
428 static class ObjectArrayLowerDim1 { | |
429 public @Stable Object[] v; | |
430 | |
431 public static final ObjectArrayLowerDim1 c = new ObjectArrayLowerDim1(); | |
432 public static byte get() { return ((byte[][])c.v)[0][0]; } | |
433 public static byte[] get1() { return (byte[])(c.v[0]); } | |
434 public static Object[] get2() { return c.v; } | |
435 | |
436 public static void test() throws Exception { | |
437 { | |
438 c.v = new byte[1][1]; ((byte[][])c.v)[0][0] = 1; byte val1 = get(); | |
439 ((byte[][])c.v)[0][0] = 2; byte val2 = get(); | |
440 | |
441 assertEquals(val1, 1); | |
442 assertEquals(val2, 2); | |
443 } | |
444 | |
445 { | |
446 c.v = new byte[1][1]; c.v[0] = new byte[0]; byte[] val1 = get1(); | |
447 c.v[0] = new byte[0]; byte[] val2 = get1(); | |
448 | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
449 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 450 } |
451 | |
452 { | |
453 c.v = new byte[0][0]; Object[] val1 = get2(); | |
454 c.v = new byte[0][0]; Object[] val2 = get2(); | |
455 | |
456 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
457 } | |
458 } | |
459 } | |
460 | |
461 /* ==================================================== */ | |
462 | |
463 static class ObjectArrayLowerDim2 { | |
464 public @Stable Object[][] v; | |
465 | |
466 public static final ObjectArrayLowerDim2 c = new ObjectArrayLowerDim2(); | |
467 public static byte get() { return ((byte[][][])c.v)[0][0][0]; } | |
468 public static byte[] get1() { return (byte[])(c.v[0][0]); } | |
469 public static byte[][] get2() { return (byte[][])(c.v[0]); } | |
470 public static Object[][] get3() { return c.v; } | |
471 | |
472 public static void test() throws Exception { | |
473 { | |
474 c.v = new byte[1][1][1]; ((byte[][][])c.v)[0][0][0] = 1; byte val1 = get(); | |
475 ((byte[][][])c.v)[0][0][0] = 2; byte val2 = get(); | |
476 | |
477 assertEquals(val1, 1); | |
478 assertEquals(val2, 2); | |
479 } | |
480 | |
481 { | |
482 c.v = new byte[1][1][1]; c.v[0][0] = new byte[0]; byte[] val1 = get1(); | |
483 c.v[0][0] = new byte[0]; byte[] val2 = get1(); | |
484 | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
485 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 486 } |
487 | |
488 { | |
489 c.v = new byte[1][1][1]; c.v[0] = new byte[0][0]; byte[][] val1 = get2(); | |
490 c.v[0] = new byte[0][0]; byte[][] val2 = get2(); | |
491 | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
492 assertTrue((isServerWithStable ? (val1 == val2) : (val1 != val2))); |
17820 | 493 } |
494 | |
495 { | |
496 c.v = new byte[0][0][0]; Object[][] val1 = get3(); | |
497 c.v = new byte[0][0][0]; Object[][] val2 = get3(); | |
498 | |
499 assertTrue((isStableEnabled ? (val1 == val2) : (val1 != val2))); | |
500 } | |
501 } | |
502 } | |
503 | |
504 /* ==================================================== */ | |
505 | |
506 static class NestedStableField { | |
507 static class A { | |
508 public @Stable byte a; | |
509 | |
510 } | |
511 public @Stable A v; | |
512 | |
513 public static final NestedStableField c = new NestedStableField(); | |
514 public static A get() { return c.v; } | |
515 public static byte get1() { return get().a; } | |
516 | |
517 public static void test() throws Exception { | |
518 { | |
519 c.v = new A(); c.v.a = 1; A val1 = get(); | |
520 c.v.a = 2; A val2 = get(); | |
521 | |
522 assertEquals(val1.a, 2); | |
523 assertEquals(val2.a, 2); | |
524 } | |
525 | |
526 { | |
527 c.v = new A(); c.v.a = 1; byte val1 = get1(); | |
528 c.v.a = 2; byte val2 = get1(); | |
529 c.v = new A(); c.v.a = 3; byte val3 = get1(); | |
530 | |
531 assertEquals(val1, 1); | |
532 assertEquals(val2, (isStableEnabled ? 1 : 2)); | |
533 assertEquals(val3, (isStableEnabled ? 1 : 3)); | |
534 } | |
535 } | |
536 } | |
537 | |
538 /* ==================================================== */ | |
539 | |
540 static class NestedStableField1 { | |
541 static class A { | |
542 public @Stable byte a; | |
543 public @Stable A next; | |
544 } | |
545 public @Stable A v; | |
546 | |
547 public static final NestedStableField1 c = new NestedStableField1(); | |
548 public static A get() { return c.v.next.next.next.next.next.next.next; } | |
549 public static byte get1() { return get().a; } | |
550 | |
551 public static void test() throws Exception { | |
552 { | |
553 c.v = new A(); c.v.next = new A(); c.v.next.next = c.v; | |
554 c.v.a = 1; c.v.next.a = 1; A val1 = get(); | |
555 c.v.a = 2; c.v.next.a = 2; A val2 = get(); | |
556 | |
557 assertEquals(val1.a, 2); | |
558 assertEquals(val2.a, 2); | |
559 } | |
560 | |
561 { | |
562 c.v = new A(); c.v.next = c.v; | |
563 c.v.a = 1; byte val1 = get1(); | |
564 c.v.a = 2; byte val2 = get1(); | |
565 c.v = new A(); c.v.next = c.v; | |
566 c.v.a = 3; byte val3 = get1(); | |
567 | |
568 assertEquals(val1, 1); | |
569 assertEquals(val2, (isStableEnabled ? 1 : 2)); | |
570 assertEquals(val3, (isStableEnabled ? 1 : 3)); | |
571 } | |
572 } | |
573 } | |
574 /* ==================================================== */ | |
575 | |
576 static class NestedStableField2 { | |
577 static class A { | |
578 public @Stable byte a; | |
579 public @Stable A left; | |
580 public A right; | |
581 } | |
582 | |
583 public @Stable A v; | |
584 | |
585 public static final NestedStableField2 c = new NestedStableField2(); | |
586 public static byte get() { return c.v.left.left.left.a; } | |
587 public static byte get1() { return c.v.left.left.right.left.a; } | |
588 | |
589 public static void test() throws Exception { | |
590 { | |
591 c.v = new A(); c.v.left = c.v.right = c.v; | |
592 c.v.a = 1; byte val1 = get(); byte val2 = get1(); | |
593 c.v.a = 2; byte val3 = get(); byte val4 = get1(); | |
594 | |
595 assertEquals(val1, 1); | |
596 assertEquals(val3, (isStableEnabled ? 1 : 2)); | |
597 | |
598 assertEquals(val2, 1); | |
599 assertEquals(val4, 2); | |
600 } | |
601 } | |
602 } | |
603 | |
604 /* ==================================================== */ | |
605 | |
606 static class NestedStableField3 { | |
607 static class A { | |
608 public @Stable byte a; | |
609 public @Stable A[] left; | |
610 public A[] right; | |
611 } | |
612 | |
613 public @Stable A[] v; | |
614 | |
615 public static final NestedStableField3 c = new NestedStableField3(); | |
616 public static byte get() { return c.v[0].left[1].left[0].left[1].a; } | |
617 public static byte get1() { return c.v[1].left[0].left[1].right[0].left[1].a; } | |
618 | |
619 public static void test() throws Exception { | |
620 { | |
621 A elem = new A(); | |
622 c.v = new A[] { elem, elem }; c.v[0].left = c.v[0].right = c.v; | |
623 elem.a = 1; byte val1 = get(); byte val2 = get1(); | |
624 elem.a = 2; byte val3 = get(); byte val4 = get1(); | |
625 | |
626 assertEquals(val1, 1); | |
20199
5fbeae2a02d3
8043546: C1 optimizes @Stable instance fields with default values
vlivanov
parents:
17820
diff
changeset
|
627 assertEquals(val3, (isServerWithStable ? 1 : 2)); |
17820 | 628 |
629 assertEquals(val2, 1); | |
630 assertEquals(val4, 2); | |
631 } | |
632 } | |
633 } | |
634 | |
635 /* ==================================================== */ | |
636 // Auxiliary methods | |
637 static void assertEquals(int i, int j) { if (i != j) throw new AssertionError(i + " != " + j); } | |
638 static void assertTrue(boolean b) { if (!b) throw new AssertionError(); } | |
639 | |
640 static boolean failed = false; | |
641 | |
642 public static void run(Class<?> test) { | |
643 Throwable ex = null; | |
644 System.out.print(test.getName()+": "); | |
645 try { | |
646 test.getMethod("test").invoke(null); | |
647 } catch (InvocationTargetException e) { | |
648 ex = e.getCause(); | |
649 } catch (Throwable e) { | |
650 ex = e; | |
651 } finally { | |
652 if (ex == null) { | |
653 System.out.println("PASSED"); | |
654 } else { | |
655 failed = true; | |
656 System.out.println("FAILED"); | |
657 ex.printStackTrace(System.out); | |
658 } | |
659 } | |
660 } | |
661 } |