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