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