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
28 * @summary tests on constant folding of unsafe get operations from stable arrays
29 * @library /testlibrary /test/lib
30 * @ignore 8151137
31 *
32 * @requires vm.flavor != "client"
33 *
34 * @run main/bootclasspath -XX:+UnlockDiagnosticVMOptions
35 * -Xbatch -XX:-TieredCompilation
36 * -XX:+FoldStableValues
37 * -XX:CompileCommand=dontinline,*Test::test*
38 * UnsafeGetStableArrayElement
39 */
40 import jdk.internal.misc.Unsafe;
41 import jdk.internal.vm.annotation.Stable;
42 import java.util.concurrent.Callable;
43
44 import static jdk.internal.misc.Unsafe.*;
45 import static jdk.test.lib.Asserts.*;
46
47 public class UnsafeGetStableArrayElement {
48 @Stable static final boolean[] STABLE_BOOLEAN_ARRAY = new boolean[16];
49 @Stable static final byte[] STABLE_BYTE_ARRAY = new byte[16];
50 @Stable static final short[] STABLE_SHORT_ARRAY = new short[8];
51 @Stable static final char[] STABLE_CHAR_ARRAY = new char[8];
52 @Stable static final int[] STABLE_INT_ARRAY = new int[4];
53 @Stable static final long[] STABLE_LONG_ARRAY = new long[2];
54 @Stable static final float[] STABLE_FLOAT_ARRAY = new float[4];
55 @Stable static final double[] STABLE_DOUBLE_ARRAY = new double[2];
56 @Stable static final Object[] STABLE_OBJECT_ARRAY = new Object[4];
57
58 static {
59 Setter.reset();
60 }
61 static final Unsafe U = Unsafe.getUnsafe();
202 }
203
204 if (changeResultAction != null) {
205 changeResultAction.run();
206 assertNE(first, c.call());
207 assertEQ(c.call(), c.call());
208 }
209 }
210
211 static void testMatched(Callable<?> c, Runnable setDefaultAction) throws Exception {
212 run(c, setDefaultAction, null);
213 Setter.reset();
214 }
215
216 static void testMismatched(Callable<?> c, Runnable setDefaultAction) throws Exception {
217 run(c, null, setDefaultAction);
218 Setter.reset();
219 }
220
221 public static void main(String[] args) throws Exception {
222 // boolean[], aligned accesses
223 testMatched( Test::testZ_Z, Test::changeZ);
224 testMismatched(Test::testZ_B, Test::changeZ);
225 testMismatched(Test::testZ_S, Test::changeZ);
226 testMismatched(Test::testZ_C, Test::changeZ);
227 testMismatched(Test::testZ_I, Test::changeZ);
228 testMismatched(Test::testZ_J, Test::changeZ);
229 testMismatched(Test::testZ_F, Test::changeZ);
230 testMismatched(Test::testZ_D, Test::changeZ);
231
232 // byte[], aligned accesses
233 testMismatched(Test::testB_Z, Test::changeB);
234 testMatched( Test::testB_B, Test::changeB);
235 testMismatched(Test::testB_S, Test::changeB);
236 testMismatched(Test::testB_C, Test::changeB);
237 testMismatched(Test::testB_I, Test::changeB);
238 testMismatched(Test::testB_J, Test::changeB);
239 testMismatched(Test::testB_F, Test::changeB);
240 testMismatched(Test::testB_D, Test::changeB);
241
|
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
28 * @summary tests on constant folding of unsafe get operations from stable arrays
29 * @library /testlibrary /test/lib
30 *
31 * @requires vm.flavor != "client"
32 *
33 * @run main/bootclasspath -XX:+UnlockDiagnosticVMOptions
34 * -Xbatch -XX:-TieredCompilation
35 * -XX:+FoldStableValues
36 * -XX:CompileCommand=dontinline,*Test::test*
37 * UnsafeGetStableArrayElement
38 */
39 import jdk.internal.misc.Unsafe;
40 import jdk.internal.vm.annotation.Stable;
41 import jdk.test.lib.Platform;
42
43 import java.util.concurrent.Callable;
44
45 import static jdk.internal.misc.Unsafe.*;
46 import static jdk.test.lib.Asserts.*;
47
48 public class UnsafeGetStableArrayElement {
49 @Stable static final boolean[] STABLE_BOOLEAN_ARRAY = new boolean[16];
50 @Stable static final byte[] STABLE_BYTE_ARRAY = new byte[16];
51 @Stable static final short[] STABLE_SHORT_ARRAY = new short[8];
52 @Stable static final char[] STABLE_CHAR_ARRAY = new char[8];
53 @Stable static final int[] STABLE_INT_ARRAY = new int[4];
54 @Stable static final long[] STABLE_LONG_ARRAY = new long[2];
55 @Stable static final float[] STABLE_FLOAT_ARRAY = new float[4];
56 @Stable static final double[] STABLE_DOUBLE_ARRAY = new double[2];
57 @Stable static final Object[] STABLE_OBJECT_ARRAY = new Object[4];
58
59 static {
60 Setter.reset();
61 }
62 static final Unsafe U = Unsafe.getUnsafe();
203 }
204
205 if (changeResultAction != null) {
206 changeResultAction.run();
207 assertNE(first, c.call());
208 assertEQ(c.call(), c.call());
209 }
210 }
211
212 static void testMatched(Callable<?> c, Runnable setDefaultAction) throws Exception {
213 run(c, setDefaultAction, null);
214 Setter.reset();
215 }
216
217 static void testMismatched(Callable<?> c, Runnable setDefaultAction) throws Exception {
218 run(c, null, setDefaultAction);
219 Setter.reset();
220 }
221
222 public static void main(String[] args) throws Exception {
223 if (!Platform.isServer()) {
224 return; // not applicable to Client VM
225 }
226
227 // boolean[], aligned accesses
228 testMatched( Test::testZ_Z, Test::changeZ);
229 testMismatched(Test::testZ_B, Test::changeZ);
230 testMismatched(Test::testZ_S, Test::changeZ);
231 testMismatched(Test::testZ_C, Test::changeZ);
232 testMismatched(Test::testZ_I, Test::changeZ);
233 testMismatched(Test::testZ_J, Test::changeZ);
234 testMismatched(Test::testZ_F, Test::changeZ);
235 testMismatched(Test::testZ_D, Test::changeZ);
236
237 // byte[], aligned accesses
238 testMismatched(Test::testB_Z, Test::changeB);
239 testMatched( Test::testB_B, Test::changeB);
240 testMismatched(Test::testB_S, Test::changeB);
241 testMismatched(Test::testB_C, Test::changeB);
242 testMismatched(Test::testB_I, Test::changeB);
243 testMismatched(Test::testB_J, Test::changeB);
244 testMismatched(Test::testB_F, Test::changeB);
245 testMismatched(Test::testB_D, Test::changeB);
246
|