1 /* 2 * Copyright (c) 2016, 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 VDefaultTest 30 * @summary vdefault bytecode test 31 * @library /test/lib 32 * @compile -XDenableValueTypes Point.java VDefaultTest.java 33 * @run main/othervm -Xint -XX:+EnableValhalla runtime.valhalla.valuetypes.VDefaultTest 34 * @run main/othervm -Xcomp -XX:+EnableValhalla runtime.valhalla.valuetypes.VDefaultTest 35 */ 36 37 public class VDefaultTest { 38 39 static __ByValue final class Point { 40 final int x; 41 final int y; 42 43 __ValueFactory static Point make() { 44 Point p = __MakeDefault Point(); 45 return p; 46 } 47 48 Point() { 49 x = 0; 50 y = 0; 51 } 52 } 53 54 static __ByValue final class Value { 55 final char c; 56 final byte b; 57 final short s; 58 final int i; 59 final long l; 60 final float f; 61 final double d; 62 final Point p; 63 64 __ValueFactory static Value make() { 65 Value p = __MakeDefault Value(); 66 return p; 67 } 68 69 Value () { 70 c = 0; 71 b = 0; 72 s = 0; 73 i = 0; 74 l = 0; 75 f = 0; 76 d = 0; 77 p = Point.make(); 78 } 79 } 80 81 public static void main(String[] args) { 82 creationTest(); 83 creationTest(); 84 } 85 86 static void creationTest() { 87 Value v = Value.make(); 88 Asserts.assertEquals(v.c, (char)0, "invalid char default value"); 89 Asserts.assertEquals(v.b, (byte)0, "invalid char default value"); 90 Asserts.assertEquals(v.s, (short)0, "invalid short default value"); 91 Asserts.assertEquals(v.i, 0, "invalid int default value"); 92 Asserts.assertEquals(v.l, 0L, "invalid long default value"); 93 Asserts.assertEquals(v.f, 0.0F, "invalid float default value"); 94 Asserts.assertEquals(v.d, 0.0D, "invalid double default value"); 95 Asserts.assertEquals(v.p.x, 0, "invalid embedded value type value"); 96 Asserts.assertEquals(v.p.y, 0, "invalid embedded value type value"); 97 } 98 } 99