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