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 -Xint -XX:+EnableValhalla runtime.valhalla.valuetypes.TestInheritedValueTypeFields 34 */ 35 36 37 /* 38 * @run main/othervm -XX:+EnableValhalla runtime.valhalla.valuetypes.TestInheritedValueTypeFields 39 */ 40 41 class A { 42 Point p; 43 } 44 45 class B extends A { 46 47 } 48 49 class C extends B { 50 int i; 51 } 52 53 class D { 54 long l; 55 } 56 57 class E extends D { 58 Point p1; 59 } 60 61 class F extends E { 62 63 } 64 65 class G extends F { 66 Point p2; 67 } 68 69 public class TestInheritedValueTypeFields { 70 71 public static void main(String[] args) { 72 for (int i = 0; i < 100000; i++) { 73 run(); 74 } 75 } 76 77 public static void run() { 78 B b = new B(); 79 Asserts.assertEquals(b.p.x, 0); 80 Asserts.assertEquals(b.p.y, 0); 81 b.p = Point.createPoint(1,2); 82 Asserts.assertEquals(b.p.x, 1); 83 Asserts.assertEquals(b.p.y, 2); 84 85 G g = new G(); 86 Asserts.assertEquals(g.p1.x, 0); 87 Asserts.assertEquals(g.p1.y, 0); 88 Asserts.assertEquals(g.p2.x, 0); 89 Asserts.assertEquals(g.p2.y, 0); 90 g.p1 = Point.createPoint(1,2); 91 g.p2 = Point.createPoint(3,4); 92 Asserts.assertEquals(g.p1.x, 1); 93 Asserts.assertEquals(g.p1.y, 2); 94 Asserts.assertEquals(g.p2.x, 3); 95 Asserts.assertEquals(g.p2.y, 4); 96 } 97 }