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