< prev index next >

hotspot/test/compiler/valhalla/valuetypes/ValueTypeTestBench.java

Print this page




  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 // TODO add bugid and summary
  25 
  26 /*
  27  * @test
  28  * @library /testlibrary /test/lib /compiler/whitebox /
  29  * @requires os.simpleArch == "x64"
  30  * @modules java.base/jdk.experimental.value

  31  *          java.base/jdk.internal.misc:+open
  32  *          jdk.incubator.mvt
  33  * @compile -XDenableValueTypes ValueCapableClass1.java ValueCapableClass2.java ValueTypeTestBench.java
  34  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  35  * @run main ClassFileInstaller jdk.test.lib.Platform
  36  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -noverify -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  37  *                   -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:-TieredCompilation -XX:+VerifyAdapterSharing -XX:+VerifyStack
  38  *                   -XX:+EnableValhalla -XX:+EnableMVT -XX:+ValueTypePassFieldsAsArgs -XX:+ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
  39  *                   -XX:ValueArrayElemMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatOops=-1
  40  *                   -Djdk.lang.reflect.DVT=true
  41  *                   compiler.valhalla.valuetypes.ValueTypeTestBench
  42  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -noverify -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  43  *                   -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:-TieredCompilation -XX:+VerifyStack
  44  *                   -XX:+EnableValhalla -XX:+EnableMVT -XX:-ValueTypePassFieldsAsArgs -XX:-ValueTypeReturnedAsFields -XX:-ValueArrayFlatten
  45  *                   -Djdk.lang.reflect.DVT=true
  46  *                   compiler.valhalla.valuetypes.ValueTypeTestBench
  47  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -noverify -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  48  *                   -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:-TieredCompilation -XX:+AlwaysIncrementalInline
  49  *                   -XX:+EnableValhalla -XX:+EnableMVT -XX:+ValueTypePassFieldsAsArgs -XX:+ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
  50  *                   -XX:ValueArrayElemMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatOops=-1
  51  *                   -Djdk.lang.reflect.DVT=true
  52  *                   compiler.valhalla.valuetypes.ValueTypeTestBench
  53  */
  54 
  55 package compiler.valhalla.valuetypes;
  56 
  57 import compiler.whitebox.CompilerWhiteBoxTest;


  58 import jdk.experimental.value.MethodHandleBuilder;
  59 import jdk.incubator.mvt.ValueType;
  60 import jdk.test.lib.Asserts;
  61 import jdk.test.lib.management.InputArguments;
  62 import jdk.test.lib.Platform;
  63 import jdk.test.lib.process.ProcessTools;
  64 import jdk.test.lib.process.OutputAnalyzer;
  65 import jdk.test.lib.Utils;
  66 import sun.hotspot.WhiteBox;
  67 
  68 import java.lang.annotation.Retention;
  69 import java.lang.annotation.RetentionPolicy;
  70 import java.lang.annotation.Repeatable;
  71 import java.lang.invoke.*;
  72 import java.lang.reflect.Method;
  73 import java.util.ArrayList;
  74 import java.util.Arrays;
  75 import java.util.Hashtable;
  76 import java.util.LinkedHashMap;
  77 import java.util.List;


1758         return (long)nullvccUnboxLoadLongMH.invokeExact();
1759     }
1760 
1761     @DontCompile
1762     public void test61_verifier(boolean warmup) throws Throwable {
1763         try {
1764             long result = test61();
1765             throw new RuntimeException("Test failed because no exception was thrown");
1766         } catch (NullPointerException e) {
1767         }
1768     }
1769 
1770     public static MethodHandle generateNullVCCUnboxLoadLongMH() {
1771         return MethodHandleBuilder.loadCode(MethodHandles.lookup(),
1772                 "nullvccUnboxLoadLong",
1773                 MethodType.methodType(long.class),
1774                 CODE -> {
1775                     CODE.
1776                     aconst_null().
1777                     vunbox(ValueType.forClass(ValueCapableClass1.class).valueClass()).
1778                     getfield(ValueCapableClass1.class, "t", "J").
1779                     lreturn();
1780                 }
1781                 );
1782     }
1783 
1784     /* The compiler is supposed to determine that the allocated
1785      * ValueCapableClass1 instance is never null (and therefore not
1786      * generate a null check). Also, the source and target type match
1787      * (known at compile time), so no type check is needed either.*/
1788     @Test(failOn = NPE)
1789     public long test62() throws Throwable {
1790         return (long)checkedvccUnboxLoadLongMH.invokeExact();
1791     }
1792 
1793     @DontCompile
1794     public void test62_verifier(boolean warmup) throws Throwable {
1795         long result = test62();
1796         Asserts.assertEQ(result, 17L);
1797     }
1798 


1889             long result = test65(vcc2, false);
1890             throw new RuntimeException("Test failed because no exception was thrown");
1891         } catch (ClassCastException e) {
1892         }
1893 
1894         try {
1895             long result = test65(vcc, false);
1896             throw new RuntimeException("Test failed because no exception was thrown");
1897         } catch (ClassCastException e) {
1898         }
1899     }
1900 
1901     private static MethodHandle generateObjectBoxMH() {
1902         return MethodHandleBuilder.loadCode(MethodHandles.lookup(),
1903                 "ObjectBox",
1904                 MethodType.methodType(long.class, Object.class, boolean.class),
1905                 CODE -> {
1906                     CODE.
1907                     iload_1().
1908                     iconst_1().
1909                     if_icmpne((short)14).
1910                     aload_0().
1911                     vunbox(ValueType.forClass(ValueCapableClass1.class).valueClass()).
1912                     vbox(ValueCapableClass1.class).
1913                     getfield(ValueCapableClass1.class, "t", "J").
1914                     lreturn().

1915                     aload_0().
1916                     vunbox(ValueType.forClass(ValueCapableClass2.class).valueClass()).
1917                     vbox(ValueCapableClass1.class).
1918                     getfield(ValueCapableClass1.class, "t", "J").
1919                     lreturn();
1920                 }
1921                 );
1922     }
1923 
1924     // Test deoptimization at call return with return value in registers
1925     @DontCompile
1926     public MyValue2 test66_interp(boolean deopt) {
1927         if (deopt) {
1928             // uncommon trap
1929             WHITE_BOX.deoptimizeMethod(tests.get("ValueTypeTestBench::test66"));
1930         }
1931         return MyValue2.createWithFieldsInline(rI, true);
1932     }
1933 
1934     @Test()




  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 // TODO add bugid and summary
  25 
  26 /*
  27  * @test
  28  * @library /testlibrary /test/lib /compiler/whitebox /
  29  * @requires os.simpleArch == "x64"
  30  * @modules java.base/jdk.experimental.bytecode
  31  *          java.base/jdk.experimental.value
  32  *          java.base/jdk.internal.misc:+open
  33  *          jdk.incubator.mvt
  34  * @compile -XDenableValueTypes ValueCapableClass1.java ValueCapableClass2.java ValueTypeTestBench.java
  35  * @run main ClassFileInstaller sun.hotspot.WhiteBox
  36  * @run main ClassFileInstaller jdk.test.lib.Platform
  37  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  38  *                   -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:-TieredCompilation -XX:+VerifyAdapterSharing -XX:+VerifyStack
  39  *                   -XX:+EnableValhalla -XX:+EnableMVT -XX:+ValueTypePassFieldsAsArgs -XX:+ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
  40  *                   -XX:ValueArrayElemMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatOops=-1
  41  *                   -Djdk.lang.reflect.DVT=true
  42  *                   compiler.valhalla.valuetypes.ValueTypeTestBench
  43  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  44  *                   -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:-TieredCompilation -XX:+VerifyStack
  45  *                   -XX:+EnableValhalla -XX:+EnableMVT -XX:-ValueTypePassFieldsAsArgs -XX:-ValueTypeReturnedAsFields -XX:-ValueArrayFlatten
  46  *                   -Djdk.lang.reflect.DVT=true
  47  *                   compiler.valhalla.valuetypes.ValueTypeTestBench
  48  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  49  *                   -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:-TieredCompilation -XX:+AlwaysIncrementalInline
  50  *                   -XX:+EnableValhalla -XX:+EnableMVT -XX:+ValueTypePassFieldsAsArgs -XX:+ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
  51  *                   -XX:ValueArrayElemMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatOops=-1
  52  *                   -Djdk.lang.reflect.DVT=true
  53  *                   compiler.valhalla.valuetypes.ValueTypeTestBench
  54  */
  55 
  56 package compiler.valhalla.valuetypes;
  57 
  58 import compiler.whitebox.CompilerWhiteBoxTest;
  59 import jdk.experimental.bytecode.MacroCodeBuilder.CondKind;
  60 import jdk.experimental.bytecode.TypeTag;
  61 import jdk.experimental.value.MethodHandleBuilder;
  62 import jdk.incubator.mvt.ValueType;
  63 import jdk.test.lib.Asserts;
  64 import jdk.test.lib.management.InputArguments;
  65 import jdk.test.lib.Platform;
  66 import jdk.test.lib.process.ProcessTools;
  67 import jdk.test.lib.process.OutputAnalyzer;
  68 import jdk.test.lib.Utils;
  69 import sun.hotspot.WhiteBox;
  70 
  71 import java.lang.annotation.Retention;
  72 import java.lang.annotation.RetentionPolicy;
  73 import java.lang.annotation.Repeatable;
  74 import java.lang.invoke.*;
  75 import java.lang.reflect.Method;
  76 import java.util.ArrayList;
  77 import java.util.Arrays;
  78 import java.util.Hashtable;
  79 import java.util.LinkedHashMap;
  80 import java.util.List;


1761         return (long)nullvccUnboxLoadLongMH.invokeExact();
1762     }
1763 
1764     @DontCompile
1765     public void test61_verifier(boolean warmup) throws Throwable {
1766         try {
1767             long result = test61();
1768             throw new RuntimeException("Test failed because no exception was thrown");
1769         } catch (NullPointerException e) {
1770         }
1771     }
1772 
1773     public static MethodHandle generateNullVCCUnboxLoadLongMH() {
1774         return MethodHandleBuilder.loadCode(MethodHandles.lookup(),
1775                 "nullvccUnboxLoadLong",
1776                 MethodType.methodType(long.class),
1777                 CODE -> {
1778                     CODE.
1779                     aconst_null().
1780                     vunbox(ValueType.forClass(ValueCapableClass1.class).valueClass()).
1781                     getfield(ValueType.forClass(ValueCapableClass1.class).valueClass(), "t", "J").
1782                     lreturn();
1783                 }
1784                 );
1785     }
1786 
1787     /* The compiler is supposed to determine that the allocated
1788      * ValueCapableClass1 instance is never null (and therefore not
1789      * generate a null check). Also, the source and target type match
1790      * (known at compile time), so no type check is needed either.*/
1791     @Test(failOn = NPE)
1792     public long test62() throws Throwable {
1793         return (long)checkedvccUnboxLoadLongMH.invokeExact();
1794     }
1795 
1796     @DontCompile
1797     public void test62_verifier(boolean warmup) throws Throwable {
1798         long result = test62();
1799         Asserts.assertEQ(result, 17L);
1800     }
1801 


1892             long result = test65(vcc2, false);
1893             throw new RuntimeException("Test failed because no exception was thrown");
1894         } catch (ClassCastException e) {
1895         }
1896 
1897         try {
1898             long result = test65(vcc, false);
1899             throw new RuntimeException("Test failed because no exception was thrown");
1900         } catch (ClassCastException e) {
1901         }
1902     }
1903 
1904     private static MethodHandle generateObjectBoxMH() {
1905         return MethodHandleBuilder.loadCode(MethodHandles.lookup(),
1906                 "ObjectBox",
1907                 MethodType.methodType(long.class, Object.class, boolean.class),
1908                 CODE -> {
1909                     CODE.
1910                     iload_1().
1911                     iconst_1().
1912                     ifcmp(TypeTag.I, CondKind.NE, "not_equal").
1913                     aload_0().
1914                     vunbox(ValueType.forClass(ValueCapableClass1.class).valueClass()).
1915                     vbox(ValueCapableClass1.class).
1916                     getfield(ValueCapableClass1.class, "t", "J").
1917                     lreturn().
1918                     label("not_equal").
1919                     aload_0().
1920                     vunbox(ValueType.forClass(ValueCapableClass2.class).valueClass()).
1921                     vbox(ValueCapableClass1.class).
1922                     getfield(ValueCapableClass1.class, "t", "J").
1923                     lreturn();
1924                 }
1925                 );
1926     }
1927 
1928     // Test deoptimization at call return with return value in registers
1929     @DontCompile
1930     public MyValue2 test66_interp(boolean deopt) {
1931         if (deopt) {
1932             // uncommon trap
1933             WHITE_BOX.deoptimizeMethod(tests.get("ValueTypeTestBench::test66"));
1934         }
1935         return MyValue2.createWithFieldsInline(rI, true);
1936     }
1937 
1938     @Test()


< prev index next >