1 /*
 2  * Copyright (c) 2017, 2024, 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  */
23 package runtime.valhalla.inlinetypes;
24 
25 import jdk.internal.vm.annotation.NullRestricted;
26 import jdk.test.lib.Asserts;
27 
28 /*
29  * @test
30  * @summary Uninitialized inline fields test
31  * @library /test/lib
32  * @modules java.base/jdk.internal.vm.annotation
33  * @enablePreview
34  * @compile Point.java JumboInline.java UninitializedInlineFieldsTest.java
35  * @run main/othervm -XX:InlineFieldMaxFlatSize=64 runtime.valhalla.inlinetypes.UninitializedInlineFieldsTest
36  */
37 public class UninitializedInlineFieldsTest {
38     static Point nonFlattenableStaticPoint;
39     @NullRestricted
40     static Point staticPoint;
41 
42     @NullRestricted
43     Point instancePoint;
44 
45     static JumboInline sj1;
46     @NullRestricted
47     static JumboInline sj2;
48 
49     JumboInline j1;
50     @NullRestricted
51     JumboInline j2;
52 
53     static Object getNull() {
54         return null;
55     }
56 
57     UninitializedInlineFieldsTest() { }
58 
59     public static void main(String[] args) {
60         checkUninitializedPoint(UninitializedInlineFieldsTest.staticPoint, 0, 0);
61         Asserts.assertEquals(nonFlattenableStaticPoint, null, "invalid non flattenable static inline field");
62         UninitializedInlineFieldsTest.staticPoint = new Point(456, 678);
63         checkUninitializedPoint(UninitializedInlineFieldsTest.staticPoint, 456, 678);
64         UninitializedInlineFieldsTest test = new UninitializedInlineFieldsTest();
65         checkUninitializedPoint(test.instancePoint, 0, 0);
66         test.instancePoint = new Point(123, 345);
67         checkUninitializedPoint(test.instancePoint, 123, 345);
68 
69         Asserts.assertEquals(test.j1, null, "invalid non flattenable instance inline field");
70         Asserts.assertEquals(test.j2.l0, 0L, "invalid flattenable instance inline field");
71     }
72 
73     static void checkUninitializedPoint(Point p, int x, int y) {
74         Asserts.assertEquals(p.x, x, "invalid x value");
75         Asserts.assertEquals(p.y, y, "invalid y value");
76     }
77 }