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 package runtime.valhalla.valuetypes; 24 25 final class ContainerValue2 { 26 static TestValue2.box staticValueField; 27 TestValue2.val nonStaticValueField; 28 TestValue2[] valueArray; 29 } 30 31 public value final class TestValue2 { 32 static TestValue2.box staticValue = getInstance(); 33 34 final long l; 35 final double d; 36 final String s; 37 38 private TestValue2() { 39 l = System.nanoTime(); 40 s = Long.valueOf(l).toString(); 41 d = Double.parseDouble(s); 42 } 43 44 public static TestValue2 create(long l) { 45 TestValue2 v = TestValue2.default; 46 v = __WithField(v.l, l); 47 v = __WithField(v.s, Long.valueOf(l).toString()); 48 v = __WithField(v.d, Double.parseDouble(v.s)); 49 return v; 50 } 51 52 public static TestValue2 create() { 53 TestValue2 v = TestValue2.default; 54 v = __WithField(v.l, System.nanoTime()); 55 v = __WithField(v.s, Long.valueOf(v.l).toString()); 56 v = __WithField(v.d, Double.parseDouble(v.s)); 57 return v; 58 } 59 60 public static TestValue2 getInstance() { 61 return create(); 62 } 63 64 public static TestValue2 getNonBufferedInstance() { 65 return staticValue; 66 } 67 68 public boolean verify() { 69 if (s == null) { 70 return d == 0 && l == 0; 71 } 72 return Long.valueOf(l).toString().compareTo(s) == 0 73 && Double.parseDouble(s) == d; 74 } 75 }