1 package runtime.valhalla.valuetypes;
   2 
   3 import jdk.test.lib.Asserts;
   4 
   5 /*
   6  * @test ValueTypeGetField
   7  * @summary Value Type get field test
   8  * @library /test/lib
   9  * @compile -XDenableValueTypes Point.java ValueTypeGetField.java
  10  * @run main/othervm -noverify -Xint runtime.valhalla.valuetypes.ValueTypeGetField
  11  * @run main/othervm -noverify -Xcomp runtime.valhalla.valuetypes.ValueTypeGetField
  12  */
  13 public class ValueTypeGetField {
  14 
  15     static Point staticPoint0;
  16     static Point staticPoint1;
  17     Point instancePoint0;
  18     Point instancePoint1;
  19 
  20     static {
  21         staticPoint0 = Point.createPoint(358, 406);
  22         staticPoint1 = Point.createPoint(101, 2653);
  23     }
  24     
  25     ValueTypeGetField() {
  26         instancePoint0 = Point.createPoint(1890, 1918);
  27         instancePoint1 = Point.createPoint(91, 102);
  28     }
  29     
  30     public static void main(String[] args) {
  31         ValueTypeGetField valueTypeGetField = new ValueTypeGetField();
  32         System.gc(); // check that VTs survive GC
  33         valueTypeGetField.run();
  34     }
  35 
  36     public void run() {
  37         // testing initial configuration 
  38         checkPoint(staticPoint0, 358, 406);
  39         checkPoint(staticPoint1, 101, 2653);
  40         checkPoint(instancePoint0, 1890, 1918);
  41         checkPoint(instancePoint1, 91, 102);
  42         // swapping static fields
  43         Point p = staticPoint1;
  44         staticPoint1 = staticPoint0;
  45         staticPoint0 = p;
  46         System.gc();
  47         checkPoint(staticPoint0, 101, 2653);
  48         checkPoint(staticPoint1, 358, 406);
  49         //swapping instance fields
  50         p = instancePoint1;
  51         instancePoint1 = instancePoint0;
  52         instancePoint0 = p;
  53         System.gc();
  54         checkPoint(instancePoint0, 91, 102);
  55         checkPoint(instancePoint1, 1890, 1918);
  56         // instance to static
  57         staticPoint0 = instancePoint0;
  58         System.gc();
  59         checkPoint(staticPoint0, 91, 102);
  60         // static to instance
  61         instancePoint1 = staticPoint1;
  62         System.gc();
  63         checkPoint(instancePoint1, 358, 406);
  64     }
  65 
  66     static void checkPoint(Point p , int x, int y) {
  67         Asserts.assertEquals(p.x, x, "invalid x value");
  68         Asserts.assertEquals(p.y, y, "invalid y value");
  69     }
  70     
  71 }