< prev index next >

test/hotspot/jtreg/runtime/valhalla/valuetypes/ValueTypeArray.java

Print this page
rev 55127 : 8223351: [lworld] Primary mirror and nullable mirror for inline type
Reviewed-by: tbd


  52         testLong8Array();
  53         testMixedPersonArray();
  54         testMultiDimPointArray();
  55         testComposition();
  56 
  57         testSanityCheckcasts();
  58         testObjectArrayOfValues();
  59 
  60         testReflectArray();
  61         testUtilArrays();
  62     }
  63 
  64     void testClassForName() {
  65         String arrayClsName = "[Lruntime.valhalla.valuetypes.Point;";
  66         String qarrayClsName = "[Qruntime.valhalla.valuetypes.Point;";
  67         try {
  68             // L-type..
  69             Class<?> arrayCls = Class.forName(arrayClsName);
  70             assertTrue(arrayCls.isArray(), "Expected an array class");
  71 
  72             assertTrue(arrayCls.getComponentType() == Point.class.asBoxType(),
  73                        "Expected component type of Point.class got: " + arrayCls.getComponentType());
  74 
  75             arrayClsName = "[" + arrayClsName;
  76             Class<?> mulArrayCls = Class.forName(arrayClsName);
  77             assertTrue(mulArrayCls.isArray());
  78             assertTrue(mulArrayCls.getComponentType() == arrayCls);
  79 
  80             // Q-type...
  81             arrayCls = Class.forName(qarrayClsName);
  82             assertTrue(arrayCls.isArray(), "Expected an array class");
  83 
  84             assertTrue(arrayCls.getComponentType() == Point.class.asValueType(),
  85                        arrayCls +
  86                        " Expected component type of Point.class got: " + arrayCls.getComponentType());
  87 
  88             qarrayClsName = "[" + qarrayClsName;
  89             mulArrayCls = Class.forName(qarrayClsName);
  90             assertTrue(mulArrayCls.isArray());
  91             assertTrue(mulArrayCls.getComponentType() == arrayCls);
  92         }
  93         catch (ClassNotFoundException cnfe) {
  94             fail("Class.forName(" + arrayClsName + ") failed", cnfe);
  95         }
  96     }
  97 
  98     void testSimplePointArray() {
  99         Point[] defaultPoint = new Point[1];
 100         Point p = defaultPoint[0];
 101         assertEquals(p.x, 0, "invalid default loaded from array");
 102         assertEquals(p.y, 0, "invalid default loaded from array");
 103         boolean gotNpe = false;
 104         try {


 183         assertEquals(multiPoints[0][0].length, 4, "3rd dim length");
 184 
 185         Point defaultPoint = multiPoints[1][2][3];
 186         assertEquals(defaultPoint.x, 0, "invalid point x value");
 187         assertEquals(defaultPoint.y, 0, "invalid point x value");
 188     }
 189 
 190     void testReflectArray() {
 191         // Check the java.lang.reflect.Array.newInstance methods...
 192         Class<?> cls = (Class<?>) Point[].class;
 193         Point[][] array = (Point[][]) Array.newInstance(cls, 1);
 194         assertEquals(array.length, 1, "Incorrect length");
 195         assertTrue(array[0] == null, "Expected NULL");
 196 
 197         Point[][][] array3 = (Point[][][]) Array.newInstance(cls, 1, 2);
 198         assertEquals(array3.length, 1, "Incorrect length");
 199         assertEquals(array3[0].length, 2, "Incorrect length");
 200         assertTrue(array3[0][0] == null, "Expected NULL");
 201 
 202         // Now create ObjArrays of ValueArray...
 203         cls = (Class<?>) Point.class.asBoxType();
 204         Point?[][] barray = (Point?[][]) Array.newInstance(cls, 1, 2);
 205         assertEquals(barray.length, 1, "Incorrect length");
 206         assertEquals(barray[0].length, 2, "Incorrect length");
 207         barray[0][1] = Point.createPoint(1, 2);
 208         Point? pb = barray[0][1];
 209         int x = pb.getX();
 210         assertEquals(x, 1, "Bad Point Value");
 211     }
 212 
 213     static final inline class MyInt implements Comparable<MyInt?> {
 214         final int value;
 215 
 216         private MyInt() { value = 0; }
 217         public int getValue() { return value; }
 218         public String toString() { return "MyInt: " + getValue(); }
 219         public int compareTo(MyInt? that) { return Integer.compare(this.getValue(), that.getValue()); }
 220         public boolean equals(Object o) {
 221             if (o instanceof MyInt) {
 222                 return this.getValue() == ((MyInt) o).getValue();
 223             }


 238 
 239     static MyInt staticMyInt = MyInt.create(-1);
 240     static MyInt[] staticMyIntArray = new MyInt[] { staticMyInt };
 241     static MyInt[][] staticMyIntArrayArray = new MyInt[][] { staticMyIntArray, staticMyIntArray };
 242 
 243     static interface SomeSecondaryType {
 244         default String hi() { return "Hi"; }
 245     }
 246 
 247     static final inline class MyOtherInt implements SomeSecondaryType {
 248         final int value;
 249         private MyOtherInt() { value = 0; }
 250     }
 251 
 252     void testSanityCheckcasts() {
 253         MyInt[] myInts = new MyInt[1];
 254         assertTrue(myInts instanceof Object[]);
 255         assertTrue(myInts instanceof Comparable[]);
 256         assertTrue(myInts instanceof MyInt?[]);
 257 
 258         Class<?> cls = MyInt.class.asValueType();
 259         assertTrue(cls.isValue());
 260         Object arrObj = Array.newInstance(cls, 1);
 261         assertTrue(arrObj instanceof Object[], "Not Object array");
 262         assertTrue(arrObj instanceof Comparable[], "Not Comparable array");
 263         assertTrue(arrObj instanceof MyInt[], "Not MyInt array");
 264 
 265         Object[] arr = (Object[]) arrObj;
 266         assertTrue(arr instanceof Comparable[], "Not Comparable array");
 267         assertTrue(arr instanceof MyInt[], "Not MyInt array");
 268         Comparable[] comparables = (Comparable[])arr;
 269         MyInt[] myIntArr = (MyInt[]) arr;
 270 
 271         // multi-dim, check secondary array types are setup...
 272         MyOtherInt[][] matrix = new MyOtherInt[1][1];
 273         assertTrue(matrix[0] instanceof MyOtherInt[]);
 274         assertTrue(matrix[0] instanceof SomeSecondaryType[]);
 275         assertTrue(matrix[0] instanceof MyOtherInt?[]);
 276 
 277         // Box types vs Inline...
 278         MyInt?[] myValueRefs = new MyInt?[1];
 279         assertTrue(myValueRefs instanceof MyInt?[]);




  52         testLong8Array();
  53         testMixedPersonArray();
  54         testMultiDimPointArray();
  55         testComposition();
  56 
  57         testSanityCheckcasts();
  58         testObjectArrayOfValues();
  59 
  60         testReflectArray();
  61         testUtilArrays();
  62     }
  63 
  64     void testClassForName() {
  65         String arrayClsName = "[Lruntime.valhalla.valuetypes.Point;";
  66         String qarrayClsName = "[Qruntime.valhalla.valuetypes.Point;";
  67         try {
  68             // L-type..
  69             Class<?> arrayCls = Class.forName(arrayClsName);
  70             assertTrue(arrayCls.isArray(), "Expected an array class");
  71 
  72             assertTrue(arrayCls.getComponentType() == Point.class.asNullableType(),
  73                        "Expected component type of Point.class got: " + arrayCls.getComponentType());
  74 
  75             arrayClsName = "[" + arrayClsName;
  76             Class<?> mulArrayCls = Class.forName(arrayClsName);
  77             assertTrue(mulArrayCls.isArray());
  78             assertTrue(mulArrayCls.getComponentType() == arrayCls);
  79 
  80             // Q-type...
  81             arrayCls = Class.forName(qarrayClsName);
  82             assertTrue(arrayCls.isArray(), "Expected an array class");
  83 
  84             assertTrue(arrayCls.getComponentType() == Point.class.asPrimaryType(),
  85                        arrayCls +
  86                        " Expected component type of Point.class got: " + arrayCls.getComponentType());
  87 
  88             qarrayClsName = "[" + qarrayClsName;
  89             mulArrayCls = Class.forName(qarrayClsName);
  90             assertTrue(mulArrayCls.isArray());
  91             assertTrue(mulArrayCls.getComponentType() == arrayCls);
  92         }
  93         catch (ClassNotFoundException cnfe) {
  94             fail("Class.forName(" + arrayClsName + ") failed", cnfe);
  95         }
  96     }
  97 
  98     void testSimplePointArray() {
  99         Point[] defaultPoint = new Point[1];
 100         Point p = defaultPoint[0];
 101         assertEquals(p.x, 0, "invalid default loaded from array");
 102         assertEquals(p.y, 0, "invalid default loaded from array");
 103         boolean gotNpe = false;
 104         try {


 183         assertEquals(multiPoints[0][0].length, 4, "3rd dim length");
 184 
 185         Point defaultPoint = multiPoints[1][2][3];
 186         assertEquals(defaultPoint.x, 0, "invalid point x value");
 187         assertEquals(defaultPoint.y, 0, "invalid point x value");
 188     }
 189 
 190     void testReflectArray() {
 191         // Check the java.lang.reflect.Array.newInstance methods...
 192         Class<?> cls = (Class<?>) Point[].class;
 193         Point[][] array = (Point[][]) Array.newInstance(cls, 1);
 194         assertEquals(array.length, 1, "Incorrect length");
 195         assertTrue(array[0] == null, "Expected NULL");
 196 
 197         Point[][][] array3 = (Point[][][]) Array.newInstance(cls, 1, 2);
 198         assertEquals(array3.length, 1, "Incorrect length");
 199         assertEquals(array3[0].length, 2, "Incorrect length");
 200         assertTrue(array3[0][0] == null, "Expected NULL");
 201 
 202         // Now create ObjArrays of ValueArray...
 203         cls = (Class<?>) Point.class.asNullableType();
 204         Point?[][] barray = (Point?[][]) Array.newInstance(cls, 1, 2);
 205         assertEquals(barray.length, 1, "Incorrect length");
 206         assertEquals(barray[0].length, 2, "Incorrect length");
 207         barray[0][1] = Point.createPoint(1, 2);
 208         Point? pb = barray[0][1];
 209         int x = pb.getX();
 210         assertEquals(x, 1, "Bad Point Value");
 211     }
 212 
 213     static final inline class MyInt implements Comparable<MyInt?> {
 214         final int value;
 215 
 216         private MyInt() { value = 0; }
 217         public int getValue() { return value; }
 218         public String toString() { return "MyInt: " + getValue(); }
 219         public int compareTo(MyInt? that) { return Integer.compare(this.getValue(), that.getValue()); }
 220         public boolean equals(Object o) {
 221             if (o instanceof MyInt) {
 222                 return this.getValue() == ((MyInt) o).getValue();
 223             }


 238 
 239     static MyInt staticMyInt = MyInt.create(-1);
 240     static MyInt[] staticMyIntArray = new MyInt[] { staticMyInt };
 241     static MyInt[][] staticMyIntArrayArray = new MyInt[][] { staticMyIntArray, staticMyIntArray };
 242 
 243     static interface SomeSecondaryType {
 244         default String hi() { return "Hi"; }
 245     }
 246 
 247     static final inline class MyOtherInt implements SomeSecondaryType {
 248         final int value;
 249         private MyOtherInt() { value = 0; }
 250     }
 251 
 252     void testSanityCheckcasts() {
 253         MyInt[] myInts = new MyInt[1];
 254         assertTrue(myInts instanceof Object[]);
 255         assertTrue(myInts instanceof Comparable[]);
 256         assertTrue(myInts instanceof MyInt?[]);
 257 
 258         Class<?> cls = MyInt.class.asPrimaryType();
 259         assertTrue(cls.isInlineClass());
 260         Object arrObj = Array.newInstance(cls, 1);
 261         assertTrue(arrObj instanceof Object[], "Not Object array");
 262         assertTrue(arrObj instanceof Comparable[], "Not Comparable array");
 263         assertTrue(arrObj instanceof MyInt[], "Not MyInt array");
 264 
 265         Object[] arr = (Object[]) arrObj;
 266         assertTrue(arr instanceof Comparable[], "Not Comparable array");
 267         assertTrue(arr instanceof MyInt[], "Not MyInt array");
 268         Comparable[] comparables = (Comparable[])arr;
 269         MyInt[] myIntArr = (MyInt[]) arr;
 270 
 271         // multi-dim, check secondary array types are setup...
 272         MyOtherInt[][] matrix = new MyOtherInt[1][1];
 273         assertTrue(matrix[0] instanceof MyOtherInt[]);
 274         assertTrue(matrix[0] instanceof SomeSecondaryType[]);
 275         assertTrue(matrix[0] instanceof MyOtherInt?[]);
 276 
 277         // Box types vs Inline...
 278         MyInt?[] myValueRefs = new MyInt?[1];
 279         assertTrue(myValueRefs instanceof MyInt?[]);


< prev index next >