Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8243627: [lworld] Co-evolve jdk-valhalla tests along with JDK-8237072 #27

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -156,7 +156,7 @@ void compareAndExchange(Object[] array, Object[] elements) {
Point.makePoint(100, 200)
};

private static final Point?[] NULLABLE_POINTS = new Point?[]{
private static final Point.ref[] NULLABLE_POINTS = new Point.ref[]{
Point.makePoint(11, 22),
Point.makePoint(110, 220),
null
@@ -181,13 +181,13 @@ void compareAndExchange(Object[] array, Object[] elements) {
@Test
public static void testObjectArrayVarHandle() throws Throwable {
ArrayElementVarHandleTest test = new ArrayElementVarHandleTest(Object[].class);
// Point[] <: Point?[] <: Object
// Point[] <: Point.ref[] <: Object
Object[] array1 = test.newArray(POINTS.length);
test.setElements(array1, POINTS);
test.setElements(array1, NULLABLE_POINTS);
test.setElements(array1, new Object[] { "abc", Point.makePoint(1, 2) });

Point ?[]array2 = new Point ?[NULLABLE_POINTS.length];
Point.ref []array2 = new Point.ref [NULLABLE_POINTS.length];
test.setElements(array2, POINTS);
test.setElements(array2, NULLABLE_POINTS);

@@ -196,20 +196,20 @@ public static void testObjectArrayVarHandle() throws Throwable {
}

/*
* VarHandle of Point?[].class
* VarHandle of Point.ref[].class
*/
@Test
public static void testIndirectPointVarHandle() throws Throwable {
Object o = new Point?[0];
Object o = new Point.ref[0];
ArrayElementVarHandleTest test = new ArrayElementVarHandleTest(o.getClass());
assertTrue(test.componentType.isIndirectType());

// Point[] <: Point?[] <: Object
Point?[] array1 = (Point?[])test.newArray(POINTS.length);
// Point[] <: Point.ref[] <: Object
Point.ref[] array1 = (Point.ref[])test.newArray(POINTS.length);
test.setElements(array1, POINTS);
test.setElements(array1, NULLABLE_POINTS);

Point?[] array2 = new Point?[NULLABLE_POINTS.length];
Point.ref[] array2 = new Point.ref[NULLABLE_POINTS.length];
test.setElements(array2, POINTS);
test.setElements(array2, NULLABLE_POINTS);

@@ -225,7 +225,7 @@ public static void testPointArrayVarHandle() throws Throwable {
ArrayElementVarHandleTest test = new ArrayElementVarHandleTest(Point[].class);
assertFalse(test.componentType.isIndirectType());

// Point[] <: Point?[] <: Object
// Point[] <: Point.ref[] <: Object
Point[] array1 = (Point[]) test.newArray(POINTS.length);
test.setElements(array1, POINTS);

@@ -234,20 +234,20 @@ public static void testPointArrayVarHandle() throws Throwable {
}

/*
* VarHandle of Line?[].class
* VarHandle of Line.ref[].class
*/
@Test
public static void testIndirectLineVarHandle() throws Throwable {
Line?[] nullableLines = new Line?[] { null, null };
Line.ref[] nullableLines = new Line.ref[] { null, null };
ArrayElementVarHandleTest test = new ArrayElementVarHandleTest(nullableLines.getClass());
assertTrue(test.componentType.isIndirectType());

// Line[] <: Line?[]
Line?[] array1 = (Line?[])test.newArray(LINES.length);
// Line[] <: Line.ref[]
Line.ref[] array1 = (Line.ref[])test.newArray(LINES.length);
test.setElements(array1, LINES);
test.setElements(array1, nullableLines);

Line?[] array2 = new Line?[LINES.length];
Line.ref[] array2 = new Line.ref[LINES.length];
test.setElements(array2, LINES);
test.setElements(array2, nullableLines);

@@ -39,14 +39,14 @@

@Test(expectedExceptions = IllegalArgumentException.class)
static void test1() {
Point? p = new Point(10,20);
WeakReference<Point?> r = new WeakReference<>(p);
Point.ref p = new Point(10,20);
WeakReference<Point.ref> r = new WeakReference<>(p);
}

@Test(expectedExceptions = IllegalArgumentException.class)
static void test2() {
ReferenceQueue<Object> q = new ReferenceQueue<>();
Point? p = new Point(1,2);
WeakReference<Point?> r = new WeakReference<>(p, q);
Point.ref p = new Point(1,2);
WeakReference<Point.ref> r = new WeakReference<>(p, q);
}
}
@@ -133,9 +133,9 @@ static void testArray(Class<?> c, Object o) throws Throwable {

@Test
public static void testNullableArray() throws Throwable {
Class<?> arrayClass = (new Point?[0]).getClass();
Class<?> arrayClass = (new Point.ref[0]).getClass();
Class<?> elementType = arrayClass.getComponentType();
assertTrue(elementType == Point.class.asIndirectType(), arrayClass.getComponentType().toString());
assertTrue(elementType == Point.ref.class, arrayClass.getComponentType().toString());

MethodHandle setter = MethodHandles.arrayElementSetter(arrayClass);
MethodHandle getter = MethodHandles.arrayElementGetter(arrayClass);
@@ -195,7 +195,8 @@ void unreflectField(Field f) throws Throwable {
void setValueField(String name, Object obj, Object value) throws Throwable {
Field f = c.getDeclaredField(name);
boolean isStatic = Modifier.isStatic(f.getModifiers());
assertTrue(f.getType().isInlineClass());
assertTrue(f.getType().isInlineClass() ||
f.getType().getCanonicalName().endsWith("$ref"));
assertTrue((isStatic && obj == null) || (!isStatic && obj != null));
Object v = f.get(obj);

@@ -25,12 +25,12 @@

public class MixedValues {
static Point staticPoint = Point.makePoint(10, 10);
static Line? staticLine; // null static field of non-flattened type
static Line.ref staticLine; // null static field of non-flattened type
Point p;
Line l;
MutablePath mutablePath;
List<String> list;
Point? nfp;
Point.ref nfp;

public MixedValues(Point p, Line l, MutablePath path, String... names) {
this.p = p;
@@ -22,21 +22,21 @@
*/

public inline class NonFlattenValue {
Point? nfp;
Point.ref nfp;

NonFlattenValue() {
this.nfp = Point.makePoint(0,0);
}
NonFlattenValue(Point p) {
this.nfp = p;
}
public Point? point() {
public Point.ref point() {
return nfp;
}
public Point pointValue() {
return (Point) nfp;
}
public boolean has(Point p1, Point? p2) {
public boolean has(Point p1, Point.ref p2) {
return nfp.equals(p1) || nfp.equals(p2);
}

@@ -208,9 +208,9 @@ private static int hash(Object... values) {

static inline class MyValue1 {
private Point p;
private Point? np;
private Point.ref np;

MyValue1(int x, int y, Point? np) {
MyValue1(int x, int y, Point.ref np) {
this.p = Point.makePoint(x, y);
this.np = np;
}
@@ -125,9 +125,9 @@ public Object invoke(Object proxy, Method method, Object[] args) throws Throwabl

@DataProvider
static Object[][] descriptors() {
Class<?> pointLType = Point.class.asIndirectType();
Class<?> pointLType = Point.ref.class;
Class<?> pointQType = Point.class;
Class<?> nonFlattenValueLType = NonFlattenValue.class.asIndirectType();
Class<?> nonFlattenValueLType = NonFlattenValue.ref.class;
Class<?> nonFlattenValueQType = NonFlattenValue.class;
return new Object[][]{
{ QTypeDescriptorTest.class, "toLine", new Class<?>[] {pointQType, nonFlattenValueQType}, true},
@@ -152,7 +152,7 @@ public static void testDescriptors(Class<?> defc, String name, Class<?>[] params

@DataProvider
static Object[][] methodTypes() {
Class<?> pointLType = Point.class.asIndirectType();
Class<?> pointLType = Point.ref.class;
Class<?> pointQType = Point.class;
ClassLoader loader = QTypeDescriptorTest.class.getClassLoader();
return new Object[][]{
@@ -162,12 +162,12 @@ public static void testDescriptors(Class<?> defc, String name, Class<?>[] params
{ "point", MethodType.methodType(pointQType), false },
{ "pointValue", MethodType.methodType(pointLType), false },
{ "has", MethodType.methodType(boolean.class, pointLType, pointQType), false },
{ "point", MethodType.fromMethodDescriptorString("()LPoint;", loader), true },
{ "point", MethodType.fromMethodDescriptorString("()LPoint$ref;", loader), true },
{ "point", MethodType.fromMethodDescriptorString("()QPoint;", loader), false },
{ "pointValue", MethodType.fromMethodDescriptorString("()QPoint;", loader), true },
{ "pointValue", MethodType.fromMethodDescriptorString("()LPoint;", loader), false },
{ "has", MethodType.fromMethodDescriptorString("(QPoint;LPoint;)Z", loader), true },
{ "has", MethodType.fromMethodDescriptorString("(LPoint;LPoint;)Z", loader), false },
{ "has", MethodType.fromMethodDescriptorString("(QPoint;LPoint$ref;)Z", loader), true },
{ "has", MethodType.fromMethodDescriptorString("(LPoint$ref;LPoint$ref;)Z", loader), false },
};
}

@@ -64,26 +64,26 @@ static void testLineClass() throws Exception {
static void testNonFlattenValue() throws Exception {
NonFlattenValue nfv = NonFlattenValue.make(10, 20);
Reflection test = new Reflection(NonFlattenValue.class, "NonFlattenValue", nfv);
test.checkField("final Point? NonFlattenValue.nfp", "nfp", Point.class.asIndirectType());
test.checkField("final Point$ref NonFlattenValue.nfp", "nfp", Point.ref.class);
test.checkMethod("public Point NonFlattenValue.pointValue()", "pointValue", Point.class);
test.checkMethod("public Point? NonFlattenValue.point()", "point", Point.class.asIndirectType());
test.checkMethod("public boolean NonFlattenValue.has(Point,Point?)", "has", boolean.class, Point.class, Point.class.asIndirectType());
test.checkMethod("public Point$ref NonFlattenValue.point()", "point", Point.ref.class);
test.checkMethod("public boolean NonFlattenValue.has(Point,Point$ref)", "has", boolean.class, Point.class, Point.ref.class);
}

/*
* Tests reflection APIs with the primary type and indirect/nullable projection type
*/
static void testMirrors() throws Exception {
Class<?> primary = Point.class;
Class<?> indirect = Point.class.asIndirectType();
Class<?> indirect = Point.ref.class;

assertEquals(primary, Point.class);
assertEquals(indirect, Point.class.asNullableType());
assertEquals(indirect, Point.ref.class);
assertTrue(primary.isInlineClass());
assertFalse(primary.isIndirectType());
assertFalse(primary.isNullableType());

assertTrue(indirect.isInlineClass());
assertTrue(!indirect.isInlineClass());
assertTrue(indirect.isIndirectType());
assertTrue(indirect.isNullableType());

@@ -116,7 +116,7 @@ static void testClassName() {
assertEquals(Point.class.asNullableType().getName(), "Point");
assertEquals(Line.class.getName(), "Line");
assertEquals((new Point[0]).getClass().getName(), "[QPoint;");
assertEquals((new Point?[0][0]).getClass().getName(), "[[LPoint;");
assertEquals((new Point.ref[0][0]).getClass().getName(), "[[LPoint$ref;");
}

private final Class<?> c;
@@ -67,8 +67,8 @@ public void testInlineType() {
static inline class Value {
int i;
Point p;
Point? nullable;
Value(int i, Point p, Point? np) {
Point.ref nullable;
Value(int i, Point p, Point.ref np) {
this.i = i;
this.p = p;
this.nullable = np;
@@ -78,7 +78,7 @@ Point point() {
return p;
}

Point? nullablePoint() {
Point.ref nullablePoint() {
return nullable;
}
}
@@ -39,8 +39,8 @@
Object[][] substitutableCases() {
Point p1 = Point.makePoint(10, 10);
Point p2 = Point.makePoint(20, 20);
Point? box1 = p1;
Point? box2 = p2;
Point.ref box1 = p1;
Point.ref box2 = p2;
Line l1 = Line.makeLine(p1, p2);
var mpath = MutablePath.makePath(10, 20, 30, 40);
var mixedValues = new MixedValues(p1, l1, mpath, "value");
@@ -49,7 +49,7 @@
}

private static Class<?> nullablePointArrayClass() {
Object a = new Point?[0];
Object a = new Point.ref[0];
return a.getClass();
}

@@ -153,7 +153,7 @@ void testInlineArrayCovariance(Class<?> componentType, Object[] qArray, Object[]
new Point[][] { new Point[] { Point.makePoint(1, 2),
Point.makePoint(10, 20)}}},
new Object[] { nullablePointArrayClass(),
new Point?[] { Point.makePoint(11, 22),
new Point.ref[] { Point.makePoint(11, 22),
Point.makePoint(110, 220),
null }},
new Object[] { NonFlattenValue[].class,
@@ -201,16 +201,16 @@ public static void testNonArrayObject() {
@Test
static void testPointArray() {
Point[] qArray = new Point[0];
Point?[] lArray = new Point?[0];
Point.ref[] lArray = new Point.ref[0];

ValueArray test = new ValueArray(Point[].class, qArray);
test.run();

ValueArray test1 = new ValueArray(Point?[].class, lArray);
ValueArray test1 = new ValueArray(Point.ref[].class, lArray);
test.run();

// language instanceof
assertTrue(qArray instanceof Point[]);
assertTrue(lArray instanceof Point?[]);
assertTrue(lArray instanceof Point.ref[]);
}
}