< prev index next >

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

Print this page




 236         public static final MyInt? MAX = MyInt.create(Integer.MAX_VALUE);
 237     }
 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 
 257         Class<?> cls = MyInt.class.asValueType();
 258         assertTrue(cls.isValue());
 259         Object arrObj = Array.newInstance(cls, 1);
 260         assertTrue(arrObj instanceof Object[], "Not Object array");
 261         assertTrue(arrObj instanceof Comparable[], "Not Comparable array");
 262         assertTrue(arrObj instanceof MyInt[], "Not MyInt array");
 263 
 264         Object[] arr = (Object[]) arrObj;
 265         assertTrue(arr instanceof Comparable[], "Not Comparable array");
 266         assertTrue(arr instanceof MyInt[], "Not MyInt array");
 267         Comparable[] comparables = (Comparable[])arr;
 268         MyInt[] myIntArr = (MyInt[]) arr;
 269 
 270         // multi-dim, check secondary array types are setup...
 271         MyOtherInt[][] matrix = new MyOtherInt[1][1];
 272         assertTrue(matrix[0] instanceof MyOtherInt[]);
 273         assertTrue(matrix[0] instanceof SomeSecondaryType[]);

 274 
 275         // Box types vs Inline...
 276         MyInt?[] myValueRefs = new MyInt?[1];
 277         // JDK-8222974
 278         //assertTrue(myValueRefs instanceof MyInt?[]);
 279         assertFalse(myValueRefs instanceof MyInt[]);
 280         assertTrue(myValueRefs instanceof Object[]);
 281         assertTrue(myValueRefs instanceof Comparable[]);
 282         assertFalse(myValueRefs instanceof MyInt[]);
















 283     }
 284 
 285 
 286     void testUtilArrays() {
 287         // Sanity check j.u.Arrays
 288 
 289         // cast to q-type temp effect of avoiding circularity error (decl static MyInt?)
 290         MyInt[] myInts = new MyInt[] { (MyInt) MyInt.MAX, (MyInt) MyInt.MIN };
 291         // Sanity sort another copy
 292         MyInt[] copyMyInts = Arrays.copyOf(myInts, myInts.length + 1);
 293         checkArrayElementsEqual(copyMyInts, new MyInt[] { myInts[0], myInts[1], (MyInt) MyInt.ZERO});
 294 
 295         Arrays.sort(copyMyInts);
 296         checkArrayElementsEqual(copyMyInts, new MyInt[] { (MyInt) MyInt.MIN, (MyInt) MyInt.ZERO, (MyInt) MyInt.MAX });
 297 
 298         List myIntList = Arrays.asList(copyMyInts);
 299         checkArrayElementsEqual(copyMyInts, myIntList.toArray(new MyInt[copyMyInts.length]));
 300         // This next line needs testMixedLayoutArrays to work
 301         checkArrayElementsEqual(copyMyInts, myIntList.toArray());
 302 




 236         public static final MyInt? MAX = MyInt.create(Integer.MAX_VALUE);
 237     }
 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?[]);


 280         assertTrue(myValueRefs instanceof Object[]);
 281         assertTrue(myValueRefs instanceof Comparable[]);
 282         assertFalse(myValueRefs instanceof MyInt[]);
 283 
 284         MyInt?[][] myMdValueRefs = new MyInt?[1][1];
 285         assertTrue(myMdValueRefs[0] instanceof MyInt?[]);
 286         assertTrue(myMdValueRefs[0] instanceof Object[]);
 287         assertTrue(myMdValueRefs[0] instanceof Comparable[]);
 288         assertFalse(myMdValueRefs[0] instanceof MyInt[]);
 289 
 290         // Did we break checkcast...
 291         MyInt?[]     va1 = (MyInt?[])null;
 292         MyInt?[]     va2 = null;
 293         MyInt?[][]   va3 = (MyInt?[][])null;
 294         MyInt?[][][] va4 = (MyInt?[][][])null;
 295         MyInt[]      va5 = null;
 296         MyInt[]      va6 = (MyInt[])null;
 297         MyInt[][]    va7 = (MyInt[][])null;
 298         MyInt[][][]  va8 = (MyInt[][][])null;
 299     }
 300 
 301 
 302     void testUtilArrays() {
 303         // Sanity check j.u.Arrays
 304 
 305         // cast to q-type temp effect of avoiding circularity error (decl static MyInt?)
 306         MyInt[] myInts = new MyInt[] { (MyInt) MyInt.MAX, (MyInt) MyInt.MIN };
 307         // Sanity sort another copy
 308         MyInt[] copyMyInts = Arrays.copyOf(myInts, myInts.length + 1);
 309         checkArrayElementsEqual(copyMyInts, new MyInt[] { myInts[0], myInts[1], (MyInt) MyInt.ZERO});
 310 
 311         Arrays.sort(copyMyInts);
 312         checkArrayElementsEqual(copyMyInts, new MyInt[] { (MyInt) MyInt.MIN, (MyInt) MyInt.ZERO, (MyInt) MyInt.MAX });
 313 
 314         List myIntList = Arrays.asList(copyMyInts);
 315         checkArrayElementsEqual(copyMyInts, myIntList.toArray(new MyInt[copyMyInts.length]));
 316         // This next line needs testMixedLayoutArrays to work
 317         checkArrayElementsEqual(copyMyInts, myIntList.toArray());
 318 


< prev index next >