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