< prev index next >

test/valhalla/mvt/MVTTest.java

Print this page


   1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /*
  27  * @test
  28  * @run testng/othervm -Xint -Xverify:none -XX:+EnableMVT -XX:+ValueArrayFlatten MVTTest
  29  * @run testng/othervm -Xint -Xverify:none -XX:+EnableMVT -XX:-ValueArrayFlatten MVTTest


  82             PRINT_POINT = LOOKUP.findStatic(MVTTest.class, "print", methodType(String.class, Point.class))
  83                     .asType(methodType(String.class, DVT));
  84         }
  85         catch (Exception e) {
  86             throw new RuntimeException(e);
  87         }
  88     }
  89 
  90     public void testDefaultValue() throws Throwable {
  91         for (int i = 0; i < FIELD_NAMES.length; i++) {
  92             MethodHandle getter = MethodHandles.collectArguments(
  93                     VT.findGetter(LOOKUP, FIELD_NAMES[i], FIELD_TYPES[i]),
  94                     0,
  95                     VT.defaultValueConstant());
  96 
  97             assertEquals((int) getter.invoke(), 0);
  98         }
  99     }
 100 
 101     public void testWither() throws Throwable {






 102         for (int i = 0; i < FIELD_NAMES.length; i++) {
 103             MethodHandle wither = MethodHandles.collectArguments(
 104                     VT.findWither(LOOKUP, FIELD_NAMES[i], FIELD_TYPES[i]), 0, VT.defaultValueConstant());
 105             String expected = TEMPLATE.replace("#" + FIELD_NAMES[i], String.valueOf(FIELD_VALUES[i]))
 106                     .replaceAll("#[xyz]", "0");
 107 
 108             assertEquals(printReturn(wither).invoke(FIELD_VALUES[i]), expected);
 109         }
 110     }
 111 
 112     public void testSubstitutability() throws Throwable {
 113         Point[] pts = {new Point(1, (short) 6, (short) 3), new Point(1, (short) 2, (short) 3)};
 114 
 115         MethodHandle substTest = VT.substitutabilityTest();
 116         for (Point p1 : pts) {
 117             for (Point p2 : pts) {
 118                 assertEquals((boolean) substTest.invoke(p1, p2), p1.equals(p2));
 119             }
 120         }
 121 
 122         MethodHandle hash = VT.substitutabilityHashCode();
 123         for (Point p1 : pts) {
 124             for (Point p2 : pts) {


   1 /*
   2  * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @run testng/othervm -Xint -Xverify:none -XX:+EnableMVT -XX:+ValueArrayFlatten MVTTest
  27  * @run testng/othervm -Xint -Xverify:none -XX:+EnableMVT -XX:-ValueArrayFlatten MVTTest


  80             PRINT_POINT = LOOKUP.findStatic(MVTTest.class, "print", methodType(String.class, Point.class))
  81                     .asType(methodType(String.class, DVT));
  82         }
  83         catch (Exception e) {
  84             throw new RuntimeException(e);
  85         }
  86     }
  87 
  88     public void testDefaultValue() throws Throwable {
  89         for (int i = 0; i < FIELD_NAMES.length; i++) {
  90             MethodHandle getter = MethodHandles.collectArguments(
  91                     VT.findGetter(LOOKUP, FIELD_NAMES[i], FIELD_TYPES[i]),
  92                     0,
  93                     VT.defaultValueConstant());
  94 
  95             assertEquals((int) getter.invoke(), 0);
  96         }
  97     }
  98 
  99     public void testWither() throws Throwable {
 100         testWither(Point.lookup());
 101         testWither(MethodHandles.privateLookupIn(VT.boxClass(), LOOKUP));
 102         testWither(MethodHandles.privateLookupIn(VT.valueClass(), LOOKUP));
 103     }
 104 
 105     void testWither(MethodHandles.Lookup l ) throws Throwable {
 106         for (int i = 0; i < FIELD_NAMES.length; i++) {
 107             MethodHandle wither = MethodHandles.collectArguments(
 108                     VT.findWither(l, FIELD_NAMES[i], FIELD_TYPES[i]), 0, VT.defaultValueConstant());
 109             String expected = TEMPLATE.replace("#" + FIELD_NAMES[i], String.valueOf(FIELD_VALUES[i]))
 110                     .replaceAll("#[xyz]", "0");
 111 
 112             assertEquals(printReturn(wither).invoke(FIELD_VALUES[i]), expected);
 113         }
 114     }
 115 
 116     public void testSubstitutability() throws Throwable {
 117         Point[] pts = {new Point(1, (short) 6, (short) 3), new Point(1, (short) 2, (short) 3)};
 118 
 119         MethodHandle substTest = VT.substitutabilityTest();
 120         for (Point p1 : pts) {
 121             for (Point p2 : pts) {
 122                 assertEquals((boolean) substTest.invoke(p1, p2), p1.equals(p2));
 123             }
 124         }
 125 
 126         MethodHandle hash = VT.substitutabilityHashCode();
 127         for (Point p1 : pts) {
 128             for (Point p2 : pts) {


< prev index next >