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