1 /*
   2  * Copyright (c) 2017, 2018, 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 compiler.valhalla.valuetypes;
  25 
  26 value final class MyValue2Inline {
  27     final boolean b;
  28     final long c;
  29 
  30     private MyValue2Inline() {
  31         this.b = false;
  32         this.c = 0;
  33     }
  34 
  35     @ForceInline
  36     static MyValue2Inline setB(MyValue2Inline v, boolean b) {
  37         v = __WithField(v.b, b);
  38         return v;
  39     }
  40 
  41     @ForceInline
  42     static MyValue2Inline setC(MyValue2Inline v, long c) {
  43         v = __WithField(v.c, c);
  44         return v;
  45     }
  46 
  47     @ForceInline
  48     public static MyValue2Inline createDefault() {
  49         return MyValue2Inline.default;
  50     }
  51 
  52     @ForceInline
  53     public static MyValue2Inline createWithFieldsInline(boolean b, long c) {
  54         MyValue2Inline v = MyValue2Inline.createDefault();
  55         v = MyValue2Inline.setB(v, b);
  56         v = MyValue2Inline.setC(v, c);
  57         return v;
  58     }
  59 }
  60 
  61 value public final class MyValue2 implements MyInterface {
  62     final int x;
  63     final byte y;
  64     final MyValue2Inline.val v1;
  65 
  66     private MyValue2() {
  67         this.x = 0;
  68         this.y = 0;
  69         this.v1 = MyValue2Inline.createDefault();
  70     }
  71 
  72     @ForceInline
  73     public static MyValue2 createDefaultInline() {
  74         return MyValue2.default;
  75     }
  76 
  77     @ForceInline
  78     public static MyValue2 createWithFieldsInline(int x, boolean b) {
  79         MyValue2 v = createDefaultInline();
  80         v = setX(v, x);
  81         v = setY(v, (byte)x);
  82         v = setV1(v, MyValue2Inline.createWithFieldsInline(b, ValueTypeTest.rL));
  83         return v;
  84     }
  85 
  86     @DontInline
  87     public static MyValue2 createWithFieldsDontInline(int x, boolean b) {
  88         MyValue2 v = createDefaultInline();
  89         v = setX(v, x);
  90         v = setY(v, (byte)x);
  91         v = setV1(v, MyValue2Inline.createWithFieldsInline(b, ValueTypeTest.rL));
  92         return v;
  93     }
  94 
  95     @ForceInline
  96     public long hash() {
  97         return x + y + (v1.b ? 0 : 1) + v1.c;
  98     }
  99 
 100     @DontInline
 101     public long hashInterpreted() {
 102         return x + y + (v1.b ? 0 : 1) + v1.c;
 103     }
 104 
 105     @ForceInline
 106     public void print() {
 107         System.out.print("x=" + x + ", y=" + y + ", b=" + v1.b + ", c=" + v1.c);
 108     }
 109 
 110     @ForceInline
 111     static MyValue2 setX(MyValue2 v, int x) {
 112         v = __WithField(v.x, x);
 113         return v;
 114     }
 115 
 116     @ForceInline
 117     static MyValue2 setY(MyValue2 v, byte y) {
 118         v = __WithField(v.y, y);
 119         return v;
 120     }
 121 
 122     @ForceInline
 123     static MyValue2 setV1(MyValue2 v, MyValue2Inline v1) {
 124         v = __WithField(v.v1, v1);
 125         return v;
 126     }
 127 }