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