1 /*
2 * Copyright (c) 2019, 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
44 // Extra VM parameters for some test scenarios. See ValueTypeTest.getVMParameters()
45 @Override
46 public String[] getExtraVMParameters(int scenario) {
47 switch (scenario) {
48 case 1: return new String[] {"-XX:-UseOptoBiasInlining"};
49 case 2: return new String[] {"-XX:-UseBiasedLocking"};
50 case 3: return new String[] {"-XX:-MonomorphicArrayCheck", "-XX:-UseBiasedLocking", "-XX:ValueArrayElemMaxFlatSize=-1"};
51 case 4: return new String[] {"-XX:-MonomorphicArrayCheck"};
52 }
53 return null;
54 }
55
56 public static void main(String[] args) throws Throwable {
57 TestNullableValueTypes test = new TestNullableValueTypes();
58 test.run(args, MyValue1.class, MyValue2.class, MyValue2Inline.class, Test17Value.class, Test21Value.class);
59 }
60
61 static {
62 try {
63 Class<?> clazz = TestNullableValueTypes.class;
64 ClassLoader loader = clazz.getClassLoader();
65 MethodHandles.Lookup lookup = MethodHandles.lookup();
66
67 MethodType test18_mt = MethodType.methodType(void.class, MyValue1.class.asNullableType());
68 test18_mh1 = lookup.findStatic(clazz, "test18_target1", test18_mt);
69 test18_mh2 = lookup.findStatic(clazz, "test18_target2", test18_mt);
70
71 MethodType test19_mt = MethodType.methodType(void.class, MyValue1.class.asNullableType());
72 test19_mh1 = lookup.findStatic(clazz, "test19_target1", test19_mt);
73 test19_mh2 = lookup.findStatic(clazz, "test19_target2", test19_mt);
74 } catch (NoSuchMethodException | IllegalAccessException e) {
75 e.printStackTrace();
76 throw new RuntimeException("Method handle lookup failed");
77 }
78 }
79
80 private static final MyValue1 testValue1 = MyValue1.createWithFieldsInline(rI, rL);
81 private static final MyValue1[] testValue1Array = new MyValue1[] {testValue1,
82 testValue1,
83 testValue1};
84
863
864 // Verify that static nullable inline-type fields are not
865 // treated as never-null by C2 when initialized at compile time.
866 private static MyValue1? test34Val;
867
868 @Test
869 public void test34(MyValue1 vt) {
870 if (test34Val == null) {
871 test34Val = vt;
872 }
873 }
874
875 @DontCompile
876 public void test34_verifier(boolean warmup) {
877 test34(testValue1);
878 if (!warmup) {
879 test34Val = null;
880 test34(testValue1);
881 Asserts.assertEquals(test34Val, testValue1);
882 }
883 }
884 }
|
1 /*
2 * Copyright (c) 2019, 2020, 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.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
44 // Extra VM parameters for some test scenarios. See ValueTypeTest.getVMParameters()
45 @Override
46 public String[] getExtraVMParameters(int scenario) {
47 switch (scenario) {
48 case 1: return new String[] {"-XX:-UseOptoBiasInlining"};
49 case 2: return new String[] {"-XX:-UseBiasedLocking"};
50 case 3: return new String[] {"-XX:-MonomorphicArrayCheck", "-XX:-UseBiasedLocking", "-XX:ValueArrayElemMaxFlatSize=-1"};
51 case 4: return new String[] {"-XX:-MonomorphicArrayCheck"};
52 }
53 return null;
54 }
55
56 public static void main(String[] args) throws Throwable {
57 TestNullableValueTypes test = new TestNullableValueTypes();
58 test.run(args, MyValue1.class, MyValue2.class, MyValue2Inline.class, Test17Value.class, Test21Value.class);
59 }
60
61 static {
62 try {
63 Class<?> clazz = TestNullableValueTypes.class;
64 MethodHandles.Lookup lookup = MethodHandles.lookup();
65
66 MethodType test18_mt = MethodType.methodType(void.class, MyValue1.class.asNullableType());
67 test18_mh1 = lookup.findStatic(clazz, "test18_target1", test18_mt);
68 test18_mh2 = lookup.findStatic(clazz, "test18_target2", test18_mt);
69
70 MethodType test19_mt = MethodType.methodType(void.class, MyValue1.class.asNullableType());
71 test19_mh1 = lookup.findStatic(clazz, "test19_target1", test19_mt);
72 test19_mh2 = lookup.findStatic(clazz, "test19_target2", test19_mt);
73 } catch (NoSuchMethodException | IllegalAccessException e) {
74 e.printStackTrace();
75 throw new RuntimeException("Method handle lookup failed");
76 }
77 }
78
79 private static final MyValue1 testValue1 = MyValue1.createWithFieldsInline(rI, rL);
80 private static final MyValue1[] testValue1Array = new MyValue1[] {testValue1,
81 testValue1,
82 testValue1};
83
862
863 // Verify that static nullable inline-type fields are not
864 // treated as never-null by C2 when initialized at compile time.
865 private static MyValue1? test34Val;
866
867 @Test
868 public void test34(MyValue1 vt) {
869 if (test34Val == null) {
870 test34Val = vt;
871 }
872 }
873
874 @DontCompile
875 public void test34_verifier(boolean warmup) {
876 test34(testValue1);
877 if (!warmup) {
878 test34Val = null;
879 test34(testValue1);
880 Asserts.assertEquals(test34Val, testValue1);
881 }
882 }
883
884 // Same as test17 but with non-allocated value at withfield
885 @Test()
886 public Test17Value test35(boolean b) {
887 Test17Value vt1 = Test17Value.default;
888 if ((Object)vt1.valueField != null) {
889 throw new RuntimeException("Should be null");
890 }
891 MyValue1 vt3 = MyValue1.createWithFieldsInline(rI, rL);
892 Test17Value vt2 = new Test17Value(vt3);
893 return b ? vt1 : vt2;
894 }
895
896 @DontCompile
897 public void test35_verifier(boolean warmup) {
898 test35(true);
899 test35(false);
900 }
901 }
|