1 /* 2 * Copyright (c) 2017, 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 import jdk.test.lib.Asserts; 26 27 /* 28 * @test ValueTypeGetField 29 * @summary Value Type get field test 30 * @library /test/lib 31 * @compile -XDenableValueTypes Point.java ValueTypeGetField.java 32 * @run main/othervm -Xint -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueTypeGetField 33 */ 34 35 /* 36 * @run main/othervm -Xcomp -XX:+EnableValhalla runtime.valhalla.valuetypes.ValueTypeGetField 37 */ 38 public class ValueTypeGetField { 39 40 static Point staticPoint0; 41 static Point staticPoint1; 42 Point instancePoint0; 43 Point instancePoint1; 44 45 static { 46 staticPoint0 = Point.createPoint(358, 406); 47 staticPoint1 = Point.createPoint(101, 2653); 48 } 49 50 ValueTypeGetField() { 51 instancePoint0 = Point.createPoint(1890, 1918); 52 instancePoint1 = Point.createPoint(91, 102); 53 } 54 55 public static void main(String[] args) { 56 ValueTypeGetField valueTypeGetField = new ValueTypeGetField(); 57 System.gc(); // check that VTs survive GC 58 valueTypeGetField.run(); 59 } 60 61 public void run() { 62 // testing initial configuration 63 checkPoint(staticPoint0, 358, 406); 64 checkPoint(staticPoint1, 101, 2653); 65 checkPoint(instancePoint0, 1890, 1918); 66 checkPoint(instancePoint1, 91, 102); 67 // swapping static fields 68 Point p = staticPoint1; 69 staticPoint1 = staticPoint0; 70 staticPoint0 = p; 71 System.gc(); 72 checkPoint(staticPoint0, 101, 2653); 73 checkPoint(staticPoint1, 358, 406); 74 //swapping instance fields 75 p = instancePoint1; 76 instancePoint1 = instancePoint0; 77 instancePoint0 = p; 78 System.gc(); 79 checkPoint(instancePoint0, 91, 102); 80 checkPoint(instancePoint1, 1890, 1918); 81 // instance to static 82 staticPoint0 = instancePoint0; 83 System.gc(); 84 checkPoint(staticPoint0, 91, 102); 85 // static to instance 86 instancePoint1 = staticPoint1; 87 System.gc(); 88 checkPoint(instancePoint1, 358, 406); 89 } 90 91 static void checkPoint(Point p , int x, int y) { 92 Asserts.assertEquals(p.x, x, "invalid x value"); 93 Asserts.assertEquals(p.y, y, "invalid y value"); 94 } 95 }