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 24 package runtime.valhalla.inlinetypes; 25 26 import jdk.internal.vm.annotation.NullRestricted; 27 import jdk.test.lib.Asserts; 28 29 /* 30 * @test TestInheritedInlineTypeFields 31 * @summary Test if inline field klasses are correctly retrieved for inherited fields 32 * @library /test/lib 33 * @modules java.base/jdk.internal.vm.annotation 34 * @enablePreview 35 * @compile Point.java TestInheritedInlineTypeFields.java 36 * @run main/othervm runtime.valhalla.inlinetypes.TestInheritedInlineTypeFields 37 */ 38 39 class A { 40 @NullRestricted 41 Point p; 42 } 43 44 class B extends A { 45 46 } 47 48 class C extends B { 49 int i; 50 } 51 52 class D { 53 long l; 54 } 55 56 class E extends D { 57 @NullRestricted 58 Point p1; 59 } 60 61 class F extends E { 62 63 } 64 65 class G extends F { 66 @NullRestricted 67 Point p2; 68 } 69 70 public class TestInheritedInlineTypeFields { 71 72 public static void main(String[] args) { 73 for (int i = 0; i < 100000; i++) { 74 run(); 75 } 76 } 77 78 public static void run() { 79 B b = new B(); 80 Asserts.assertEquals(b.p.x, 0); 81 Asserts.assertEquals(b.p.y, 0); 82 b.p = new Point(1,2); 83 Asserts.assertEquals(b.p.x, 1); 84 Asserts.assertEquals(b.p.y, 2); 85 86 G g = new G(); 87 Asserts.assertEquals(g.p1.x, 0); 88 Asserts.assertEquals(g.p1.y, 0); 89 Asserts.assertEquals(g.p2.x, 0); 90 Asserts.assertEquals(g.p2.y, 0); 91 g.p1 = new Point(1,2); 92 g.p2 = new Point(3,4); 93 Asserts.assertEquals(g.p1.x, 1); 94 Asserts.assertEquals(g.p1.y, 2); 95 Asserts.assertEquals(g.p2.x, 3); 96 Asserts.assertEquals(g.p2.y, 4); 97 } 98 }