--- old/test/valhalla/mvt/MVTAccessCheck.java 2017-06-22 17:00:08.000000000 -0700 +++ new/test/valhalla/mvt/MVTAccessCheck.java 2017-06-22 17:00:08.000000000 -0700 @@ -4,9 +4,7 @@ * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. Oracle designates this - * particular file as subject to the "Classpath" exception as provided - * by Oracle in the LICENSE file that accompanied this code. + * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or @@ -25,59 +23,74 @@ /* * @test - * @run main/othervm -Xint -Xverify:none -XX:+EnableMVT -XX:+ValueArrayFlatten MVTAccessCheck - * @run main/othervm -Xint -Xverify:none -XX:+EnableMVT -XX:-ValueArrayFlatten MVTAccessCheck - * @run main/othervm -Xint -Xverify:none -XX:+EnableMVT -Dvalhalla.enableValueLambdaForms=true MVTAccessCheck - * @run main/othervm -Xint -Xverify:none -XX:+EnableMVT -Dvalhalla.enableValueLambdaForms=true -Dvalhalla.enablePoolPatches=true MVTAccessCheck + * @run testng/othervm -Xint -Xverify:none -XX:+EnableMVT -XX:+ValueArrayFlatten MVTAccessCheck + * @run testng/othervm -Xint -Xverify:none -XX:+EnableMVT -XX:-ValueArrayFlatten MVTAccessCheck + * @run testng/othervm -Xint -Xverify:none -XX:+EnableMVT -Dvalhalla.enableValueLambdaForms=true MVTAccessCheck + * @run testng/othervm -Xint -Xverify:none -XX:+EnableMVT -Dvalhalla.enableValueLambdaForms=true -Dvalhalla.enablePoolPatches=true MVTAccessCheck */ import jdk.experimental.value.ValueType; +import org.testng.Assert; +import org.testng.annotations.Test; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +@Test public class MVTAccessCheck { - public static void main(String[] args) throws Throwable { - MethodHandles.Lookup lookup = MethodHandles.lookup(); - Class VCC = PrivatePoint.class; - ValueType VT = ValueType.forClass(VCC); - String[] fieldNames = {"x", "y", "z"}; - Class[] fieldTypes = {int.class, short.class, short.class}; + static final ValueType VT_Point = ValueType.forClass(Point.class); + static final ValueType VT_PrivatePoint = ValueType.forClass(PrivatePoint.class); + + static final String[] FIELD_NAMES = {"x", "y", "z"}; + static final Class[] FIELD_TYPES = {int.class, short.class, short.class}; - for (int i = 0; i < fieldNames.length; i++) { + public void testGetter() throws Throwable { + for (int i = 0; i < FIELD_NAMES.length; i++) { final int offset = i; - assertThrow(() -> VT.findGetter(lookup, fieldNames[offset], fieldTypes[offset]),IllegalAccessException.class); + assertThrow(() -> VT_PrivatePoint.findGetter( + MethodHandles.lookup(), FIELD_NAMES[offset], FIELD_TYPES[offset]), IllegalAccessException.class); } + } + + public void testWither() throws Throwable { + testWither(VT_Point); + testWither(VT_PrivatePoint); + } - for (int i = 0; i < fieldNames.length; i++) { + void testWither(ValueType vt) throws Throwable { + for (int i = 0; i < FIELD_NAMES.length; i++) { final int offset = i; - assertThrow(() -> VT.findWither(lookup, fieldNames[offset], fieldTypes[offset]), IllegalAccessException.class); + assertThrow(() -> vt.findWither( + MethodHandles.lookup(), FIELD_NAMES[offset], FIELD_TYPES[offset]), IllegalAccessException.class); } + } + public void testSubstitutability() throws Throwable { PrivatePoint[] pts = {new PrivatePoint(1, (short) 6, (short) 3), new PrivatePoint(1, (short) 2, (short) 3)}; - MethodHandle substTest = VT.substitutabilityTest(); + MethodHandle substTest = VT_PrivatePoint.substitutabilityTest(); for (PrivatePoint p1 : pts) { for (PrivatePoint p2 : pts) { boolean b1 = (boolean) substTest.invoke(p1, p2); boolean b2 = p1.equals(p2); - assertTrue(b1 == b2); + assertEquals(b1, b2); } } - MethodHandle hash = VT.substitutabilityHashCode(); + MethodHandle hash = VT_PrivatePoint.substitutabilityHashCode(); for (PrivatePoint p1 : pts) { for (PrivatePoint p2 : pts) { boolean vHashEq = (int) hash.invoke(p1) == (int) hash.invoke(p2); boolean rHashEq = p1.hashCode() == p2.hashCode(); - assertTrue(vHashEq == rHashEq); + assertEquals(vHashEq, rHashEq); } } } - static int assertCount = 0; - interface MHAction { void run() throws Throwable; } @@ -85,16 +98,9 @@ static void assertThrow(MHAction action, Class ex) { try { action.run(); - assertTrue(false); + Assert.fail(); } catch (Throwable t) { assertTrue(ex.isAssignableFrom(t.getClass())); } } - - static void assertTrue(boolean cond) { - assertCount++; - if (!cond) { - throw new AssertionError(); - } - } }