< prev index next >

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

Print this page

        

*** 56,83 **** testSanityCheckcasts(); testObjectArrayOfValues(); testReflectArray(); ! // testUtilArrays(); } void testClassForName() { String arrayClsName = "[Lruntime.valhalla.valuetypes.Point;"; try { Class<?> arrayCls = Class.forName(arrayClsName); assertTrue(arrayCls.isArray(), "Expected an array class"); ! // array-of-L-type not supported yet ! // the component type of a flattened value array is of the value type ! // the component type of a non-flattened array is of the box type ! assertTrue(arrayCls.getComponentType().asBoxType() == Point.class, "Expected component type of Point.class got: " + arrayCls.getComponentType()); arrayClsName = "[" + arrayClsName; Class<?> mulArrayCls = Class.forName(arrayClsName); assertTrue(mulArrayCls.isArray()); assertTrue(mulArrayCls.getComponentType() == arrayCls); } catch (ClassNotFoundException cnfe) { fail("Class.forName(" + arrayClsName + ") failed", cnfe); } } --- 56,96 ---- testSanityCheckcasts(); testObjectArrayOfValues(); testReflectArray(); ! testUtilArrays(); } void testClassForName() { String arrayClsName = "[Lruntime.valhalla.valuetypes.Point;"; + String qarrayClsName = "[Qruntime.valhalla.valuetypes.Point;"; try { + // L-type.. Class<?> arrayCls = Class.forName(arrayClsName); assertTrue(arrayCls.isArray(), "Expected an array class"); ! ! assertTrue(arrayCls.getComponentType() == Point.class.asBoxType(), "Expected component type of Point.class got: " + arrayCls.getComponentType()); arrayClsName = "[" + arrayClsName; Class<?> mulArrayCls = Class.forName(arrayClsName); assertTrue(mulArrayCls.isArray()); assertTrue(mulArrayCls.getComponentType() == arrayCls); + + // Q-type... + arrayCls = Class.forName(qarrayClsName); + assertTrue(arrayCls.isArray(), "Expected an array class"); + + assertTrue(arrayCls.getComponentType() == Point.class.asValueType(), + arrayCls + + " Expected component type of Point.class got: " + arrayCls.getComponentType()); + + qarrayClsName = "[" + qarrayClsName; + mulArrayCls = Class.forName(qarrayClsName); + assertTrue(mulArrayCls.isArray()); + assertTrue(mulArrayCls.getComponentType() == arrayCls); } catch (ClassNotFoundException cnfe) { fail("Class.forName(" + arrayClsName + ") failed", cnfe); } }
*** 185,201 **** assertEquals(array3.length, 1, "Incorrect length"); assertEquals(array3[0].length, 2, "Incorrect length"); assertTrue(array3[0][0] == null, "Expected NULL"); // Now create ObjArrays of ValueArray... ! cls = (Class<?>) Point.class; ! array = (Point[][]) Array.newInstance(cls, 1, 2); ! assertEquals(array.length, 1, "Incorrect length"); ! assertEquals(array[0].length, 2, "Incorrect length"); ! Point p = array[0][1]; ! int x = p.x; ! assertEquals(x, 0, "Bad Point Value"); } static final value class MyInt implements Comparable<MyInt> { final int value; --- 198,215 ---- assertEquals(array3.length, 1, "Incorrect length"); assertEquals(array3[0].length, 2, "Incorrect length"); assertTrue(array3[0][0] == null, "Expected NULL"); // Now create ObjArrays of ValueArray... ! cls = (Class<?>) Point.class.asBoxType(); ! Point.box[][] barray = (Point.box[][]) Array.newInstance(cls, 1, 2); ! assertEquals(barray.length, 1, "Incorrect length"); ! assertEquals(barray[0].length, 2, "Incorrect length"); ! barray[0][1] = Point.createPoint(1, 2); ! Point.box pb = barray[0][1]; ! int x = pb.getX(); ! assertEquals(x, 1, "Bad Point Value"); } static final value class MyInt implements Comparable<MyInt> { final int value;
*** 219,246 **** public static final MyInt.box MIN = MyInt.create(Integer.MIN_VALUE); public static final MyInt.box ZERO = MyInt.create(0); public static final MyInt.box MAX = MyInt.create(Integer.MAX_VALUE); } static interface SomeSecondaryType { default String hi() { return "Hi"; } } static final value class MyOtherInt implements SomeSecondaryType { final int value; private MyOtherInt() { value = 0; } } void testSanityCheckcasts() { - // TODO Re-enable if value type arrays become covariant with object arrays - /* - MyInt[] myInts = new MyInt[1]; assertTrue(myInts instanceof Object[]); assertTrue(myInts instanceof Comparable[]); ! Object arrObj = Array.newInstance(MyInt.class, 1); assertTrue(arrObj instanceof Object[], "Not Object array"); assertTrue(arrObj instanceof Comparable[], "Not Comparable array"); assertTrue(arrObj instanceof MyInt[], "Not MyInt array"); Object[] arr = (Object[]) arrObj; --- 233,263 ---- public static final MyInt.box MIN = MyInt.create(Integer.MIN_VALUE); public static final MyInt.box ZERO = MyInt.create(0); public static final MyInt.box MAX = MyInt.create(Integer.MAX_VALUE); } + static MyInt staticMyInt = MyInt.create(-1); + static MyInt[] staticMyIntArray = new MyInt[] { staticMyInt }; + static MyInt[][] staticMyIntArrayArray = new MyInt[][] { staticMyIntArray, staticMyIntArray }; + static interface SomeSecondaryType { default String hi() { return "Hi"; } } static final value class MyOtherInt implements SomeSecondaryType { final int value; private MyOtherInt() { value = 0; } } void testSanityCheckcasts() { MyInt[] myInts = new MyInt[1]; assertTrue(myInts instanceof Object[]); assertTrue(myInts instanceof Comparable[]); ! Class<?> cls = MyInt.class.asValueType(); ! assertTrue(cls.isValue()); ! Object arrObj = Array.newInstance(cls, 1); assertTrue(arrObj instanceof Object[], "Not Object array"); assertTrue(arrObj instanceof Comparable[], "Not Comparable array"); assertTrue(arrObj instanceof MyInt[], "Not MyInt array"); Object[] arr = (Object[]) arrObj;
*** 251,267 **** // multi-dim, check secondary array types are setup... MyOtherInt[][] matrix = new MyOtherInt[1][1]; assertTrue(matrix[0] instanceof MyOtherInt[]); assertTrue(matrix[0] instanceof SomeSecondaryType[]); ! */ } ! /* ! * Comment out this test because value type arrays are not assignable to the array ! * parameter types used by the methods in class java.util.Arrays. ! * void testUtilArrays() { // Sanity check j.u.Arrays MyInt[] myInts = new MyInt[] { MyInt.MAX, MyInt.MIN }; // Sanity sort another copy MyInt[] copyMyInts = Arrays.copyOf(myInts, myInts.length + 1); --- 268,286 ---- // multi-dim, check secondary array types are setup... MyOtherInt[][] matrix = new MyOtherInt[1][1]; assertTrue(matrix[0] instanceof MyOtherInt[]); assertTrue(matrix[0] instanceof SomeSecondaryType[]); ! ! // Box types vs Value... ! MyInt.box[] myValueRefs = new MyInt.box[1]; ! assertTrue(myValueRefs instanceof MyInt.box[]); ! assertTrue(myValueRefs instanceof Object[]); ! assertTrue(myValueRefs instanceof Comparable[]); } ! void testUtilArrays() { // Sanity check j.u.Arrays MyInt[] myInts = new MyInt[] { MyInt.MAX, MyInt.MIN }; // Sanity sort another copy MyInt[] copyMyInts = Arrays.copyOf(myInts, myInts.length + 1);
*** 281,300 **** assertTrue(aList.indexOf(MyInt.ZERO) == 1, "Bad Index"); assertTrue(aList.indexOf(MyInt.MAX) == 2, "Bad Index"); aList.remove(2); aList.add(MyInt.create(5)); - - // Interesting: - //aList.add((MyInt)getNull()); - - // javac currently generating "java/util/Objects.requireNonNull - // should checkcast treat null against Value class as CCE ? - // Then in the end, ArrayList.elementData is Object[], (that's why remove works) - // why can't I write add(null) then ? } ! */ void testObjectArrayOfValues() { testSanityObjectArrays(); testMixedLayoutArrays(); } --- 300,311 ---- assertTrue(aList.indexOf(MyInt.ZERO) == 1, "Bad Index"); assertTrue(aList.indexOf(MyInt.MAX) == 2, "Bad Index"); aList.remove(2); aList.add(MyInt.create(5)); } ! void testObjectArrayOfValues() { testSanityObjectArrays(); testMixedLayoutArrays(); }
*** 328,337 **** --- 339,352 ---- checkArrayElementsEqual(comparables, copyObjects); comparables[0] = null; comparables[1] = null; assertTrue(comparables[0] == null && comparables[1] == null, "Not null ?"); + + MyInt.box[] myIntRefArray = new MyInt.box[1]; + assertTrue(myIntRefArray[0] == null, "Got: " + myIntRefArray[0]); + myIntRefArray[0] = null; } void testMixedLayoutArrays() { Object[] objArray = new Object[3]; Comparable[] compArray = new Comparable[3];
*** 363,372 **** --- 378,397 ---- objArray[0] = "Not a value object"; try { System.arraycopy(objArray, 0, valArray, 0, 3); throw new RuntimeException("Expected ArrayStoreException"); } catch (ArrayStoreException ase) {} + + MyInt.box[] myIntRefArray = new MyInt.box[3]; + System.arraycopy(valArray, 0, myIntRefArray, 0, 3); + checkArrayElementsEqual(valArray, myIntRefArray); + + myIntRefArray[0] = null; + try { + System.arraycopy(myIntRefArray, 0, valArray, 0, 3); + throw new RuntimeException("Expected NullPointerException"); + } catch (NullPointerException npe) {} } static final value class MyPoint { final MyInt.val x; final MyInt y;
< prev index next >