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 VWithFieldTest 30 * @summary vwithfield bytecode test 31 * @library /test/lib 32 * @compile -XDenableValueTypes --add-modules jdk.incubator.mvt Point.java 33 * @compile -XDenableValueTypes VWithFieldTest.java 34 * @run main/othervm -Xint -XX:+EnableValhalla runtime.valhalla.valuetypes.VWithFieldTest 35 */ 36 37 38 39 /* 40 * @run main/othervm -Xcomp -XX:+EnableValhalla runtime.valhalla.valuetypes.VWithFieldTest 41 */ 42 43 public class VWithFieldTest { 44 45 static __ByValue final class Point { 46 final private int x; 47 final private int y; 48 49 __ValueFactory static Point make(int x, int y) { 50 Point p = __MakeDefault Point(); 51 Asserts.assertEquals(p.x, 0, "invalid x default value"); 52 Asserts.assertEquals(p.y, 0, "invalid y default value"); 53 p.x = x; 54 Asserts.assertEquals(p.x, x, "invalid x value"); 55 Asserts.assertEquals(p.y, 0, "invalid y value"); 56 p.y = y; 57 Asserts.assertEquals(p.x, x, "invalid x value"); 58 Asserts.assertEquals(p.y, y, "invalid y value"); 59 return p; 60 } 61 62 Point () { 63 x = 0; 64 y = 0; 65 } 66 67 public int getX() { 68 return x; 69 } 70 71 __ValueFactory static Point setX(Point p, int x) { 72 p.x = x; 73 return p; 74 } 75 76 public int getY() { 77 return y; 78 } 79 80 __ValueFactory static Point setY(Point p, int y) { 81 p.y = y; 82 return p; 83 } 84 } 85 86 public static void main(String[] args) { 87 creationTest(); 88 creationTest(); 89 witherTest(); 90 witherTest(); 91 } 92 93 static void creationTest() { 94 Point p = Point.make(10,20); 95 Asserts.assertEquals(p.x, 10, "invalid x value"); 96 Asserts.assertEquals(p.y, 20, "invalid y value"); 97 } 98 99 static void witherTest() { 100 Point p1 = Point.make(2,12); 101 Asserts.assertEquals(p1.x, 2, "invalid x value"); 102 Asserts.assertEquals(p1.y, 12, "invalid y value"); 103 Point p2 = Point.setX(p1,3); 104 Asserts.assertEquals(p2.x, 3, "invalid x value"); 105 Asserts.assertEquals(p2.y, 12, "invalid y value"); 106 Point p3 = Point.setY(p2, 14); 107 Asserts.assertEquals(p3.x, 3, "invalid x value"); 108 Asserts.assertEquals(p3.y, 14, "invalid y value"); 109 } 110 111 }