< prev index next >

test/jdk/valhalla/valuetypes/Value.java

Print this page
rev 55117 : 8223350: [lworld] Use inline classes instead of value classes


   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 public value class Value {
  25     char char_v;
  26     byte byte_v;
  27     boolean boolean_v;
  28     int int_v;
  29     short short_v;
  30     long long_v;
  31     double double_v;
  32     float float_v;
  33     Number number_v;
  34     Point point_v;
  35     Object ref_v;
  36 
  37     Value() {
  38         char_v = 'z';
  39         byte_v = 0;
  40         boolean_v = true;
  41         int_v = 1;
  42         short_v = 2;
  43         long_v = 3;
  44         float_v = 0.1f;


 130         default int intValue() {
 131             throw new UnsupportedOperationException();
 132         }
 133         default short shortValue() {
 134             throw new UnsupportedOperationException();
 135         }
 136 
 137         static IntValue intValue(int i) {
 138             IntValue v = IntValue.default;
 139             v = __WithField(v.i, i);
 140             return v;
 141         }
 142 
 143         static ShortValue shortValue(short s) {
 144             ShortValue v = ShortValue.default;
 145             v = __WithField(v.s, s);
 146             return v;
 147         }
 148     }
 149 
 150     static value class IntValue implements Number {
 151         int i;
 152         IntValue() {
 153             i = 0;
 154         }
 155         public int intValue() {
 156             return i;
 157         }
 158     }
 159 
 160     static value class ShortValue implements Number {
 161         short s;
 162         ShortValue() {
 163             s = 0;
 164         }
 165         public short shortValue() {
 166             return s;
 167         }
 168     }
 169 
 170     static class IntNumber implements Number {
 171         final int i;
 172         public IntNumber(int i) {
 173             this.i = i;
 174         }
 175 
 176         public int intValue() {
 177             return i;
 178         }
 179 
 180         @Override


   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 public inline class Value {
  25     char char_v;
  26     byte byte_v;
  27     boolean boolean_v;
  28     int int_v;
  29     short short_v;
  30     long long_v;
  31     double double_v;
  32     float float_v;
  33     Number number_v;
  34     Point point_v;
  35     Object ref_v;
  36 
  37     Value() {
  38         char_v = 'z';
  39         byte_v = 0;
  40         boolean_v = true;
  41         int_v = 1;
  42         short_v = 2;
  43         long_v = 3;
  44         float_v = 0.1f;


 130         default int intValue() {
 131             throw new UnsupportedOperationException();
 132         }
 133         default short shortValue() {
 134             throw new UnsupportedOperationException();
 135         }
 136 
 137         static IntValue intValue(int i) {
 138             IntValue v = IntValue.default;
 139             v = __WithField(v.i, i);
 140             return v;
 141         }
 142 
 143         static ShortValue shortValue(short s) {
 144             ShortValue v = ShortValue.default;
 145             v = __WithField(v.s, s);
 146             return v;
 147         }
 148     }
 149 
 150     static inline class IntValue implements Number {
 151         int i;
 152         IntValue() {
 153             i = 0;
 154         }
 155         public int intValue() {
 156             return i;
 157         }
 158     }
 159 
 160     static inline class ShortValue implements Number {
 161         short s;
 162         ShortValue() {
 163             s = 0;
 164         }
 165         public short shortValue() {
 166             return s;
 167         }
 168     }
 169 
 170     static class IntNumber implements Number {
 171         final int i;
 172         public IntNumber(int i) {
 173             this.i = i;
 174         }
 175 
 176         public int intValue() {
 177             return i;
 178         }
 179 
 180         @Override
< prev index next >