29 import jdk.experimental.bytecode.MacroCodeBuilder;
30 import jdk.experimental.bytecode.MacroCodeBuilder.CondKind;
31 import jdk.experimental.bytecode.TypeTag;
32 import jdk.test.lib.Asserts;
33
34 /*
35 * @test
36 * @summary Test value types in LWorld.
37 * @modules java.base/jdk.experimental.bytecode
38 * java.base/jdk.experimental.value
39 * @library /testlibrary /test/lib /compiler/whitebox /
40 * @requires os.simpleArch == "x64"
41 * @compile -XDenableValueTypes -XDallowFlattenabilityModifiers TestLWorld.java
42 * @run driver ClassFileInstaller sun.hotspot.WhiteBox jdk.test.lib.Platform
43 * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
44 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:+AlwaysIncrementalInline
45 * -XX:+EnableValhalla -XX:+ValueTypePassFieldsAsArgs -XX:+ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
46 * -XX:ValueFieldMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatOops=-1
47 * compiler.valhalla.valuetypes.TestLWorld
48 * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
49 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:-UseCompressedOops
50 * -XX:+EnableValhalla -XX:-ValueTypePassFieldsAsArgs -XX:-ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
51 * -XX:ValueFieldMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatOops=-1
52 * compiler.valhalla.valuetypes.TestLWorld
53 * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
54 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:-UseCompressedOops
55 * -XX:+EnableValhalla -XX:+ValueTypePassFieldsAsArgs -XX:+ValueTypeReturnedAsFields -XX:-ValueArrayFlatten
56 * -XX:ValueFieldMaxFlatSize=0 -XX:ValueArrayElemMaxFlatSize=0 -XX:ValueArrayElemMaxFlatOops=0
57 * -DVerifyIR=false compiler.valhalla.valuetypes.TestLWorld
58 * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
59 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:+AlwaysIncrementalInline
60 * -XX:+EnableValhalla -XX:-ValueTypePassFieldsAsArgs -XX:-ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
61 * -XX:ValueFieldMaxFlatSize=0 -XX:ValueArrayElemMaxFlatSize=0 -XX:ValueArrayElemMaxFlatOops=0
62 * -XX:-MonomorphicArrayCheck
63 * -DVerifyIR=false compiler.valhalla.valuetypes.TestLWorld
64 * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
65 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI
66 * -XX:+EnableValhalla -XX:+ValueTypePassFieldsAsArgs -XX:-ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
67 * -XX:ValueFieldMaxFlatSize=0 -XX:ValueArrayElemMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatOops=-1
68 * -XX:-MonomorphicArrayCheck
69 * -DVerifyIR=false compiler.valhalla.valuetypes.TestLWorld
70 */
71 public class TestLWorld extends ValueTypeTest {
72
73 public static void main(String[] args) throws Throwable {
74 TestLWorld test = new TestLWorld();
75 test.run(args, MyValue1.class, MyValue2.class, MyValue2Inline.class, MyValue3.class, MyValue3Inline.class, Test65Value.class);
76 }
77
78 // Helper methods
79
843 public MyInterface test26(int state) {
844 MyInterface res = null;
845 if (state == 0) {
846 res = new MyObject(rI);
847 } else if (state == 1) {
848 res = MyValue1.createWithFieldsInline(rI, rL);
849 } else if (state == 2) {
850 res = MyValue1.createWithFieldsDontInline(rI, rL);
851 } else if (state == 3) {
852 res = (MyValue1)objectField1;
853 } else if (state == 4) {
854 res = valueField1;
855 } else if (state == 5) {
856 res = null;
857 }
858 return res;
859 }
860
861 @DontCompile
862 public void test26_verifier(boolean warmup) {
863 interfaceField1 = valueField1;
864 MyInterface result = null;
865 result = test26(0);
866 Asserts.assertEQ(((MyObject)result).x, rI);
867 result = test26(1);
868 Asserts.assertEQ(((MyValue1)result).hash(), hash());
869 result = test26(2);
870 Asserts.assertEQ(((MyValue1)result).hash(), hash());
871 result = test26(3);
872 Asserts.assertEQ(((MyValue1)result).hash(), hash());
873 result = test26(4);
874 Asserts.assertEQ(((MyValue1)result).hash(), hash());
875 result = test26(5);
876 Asserts.assertEQ(result, null);
877 }
878
879 // Test merging value types and interfaces in loops
880 @Test()
881 public MyInterface test27(int iters) {
882 MyInterface res = new MyObject(rI);
883 for (int i = 0; i < iters; ++i) {
1907 public void test68_verifier(boolean warmup) {
1908 MyValue1 result1 = (MyValue1)test68(true);
1909 Asserts.assertEQ(result1.hash(), hash());
1910 MyValue2 result2 = (MyValue2)test68(false);
1911 Asserts.assertEQ(result2.hash(), testValue2.hash());
1912 }
1913
1914 @Test()
1915 public Object test69(boolean b) {
1916 MyValue1 vt1 = MyValue1.createWithFieldsInline(rI, rL);
1917 MyValue2 vt2 = MyValue2.createWithFieldsInline(rI, true);
1918 return b ? vt1 : vt2;
1919 }
1920
1921 @DontCompile
1922 public void test69_verifier(boolean warmup) {
1923 MyValue1 result1 = (MyValue1)test69(true);
1924 Asserts.assertEQ(result1.hash(), hash());
1925 MyValue2 result2 = (MyValue2)test69(false);
1926 Asserts.assertEQ(result2.hash(), testValue2.hash());
1927 }
1928 }
|
29 import jdk.experimental.bytecode.MacroCodeBuilder;
30 import jdk.experimental.bytecode.MacroCodeBuilder.CondKind;
31 import jdk.experimental.bytecode.TypeTag;
32 import jdk.test.lib.Asserts;
33
34 /*
35 * @test
36 * @summary Test value types in LWorld.
37 * @modules java.base/jdk.experimental.bytecode
38 * java.base/jdk.experimental.value
39 * @library /testlibrary /test/lib /compiler/whitebox /
40 * @requires os.simpleArch == "x64"
41 * @compile -XDenableValueTypes -XDallowFlattenabilityModifiers TestLWorld.java
42 * @run driver ClassFileInstaller sun.hotspot.WhiteBox jdk.test.lib.Platform
43 * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
44 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:+AlwaysIncrementalInline
45 * -XX:+EnableValhalla -XX:+ValueTypePassFieldsAsArgs -XX:+ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
46 * -XX:ValueFieldMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatOops=-1
47 * compiler.valhalla.valuetypes.TestLWorld
48 * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
49 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:-UseCompressedOops -XX:-UseOptoBiasInlining
50 * -XX:+EnableValhalla -XX:-ValueTypePassFieldsAsArgs -XX:-ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
51 * -XX:ValueFieldMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatOops=-1
52 * compiler.valhalla.valuetypes.TestLWorld
53 * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
54 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:-UseCompressedOops -XX:-UseBiasedLocking
55 * -XX:+EnableValhalla -XX:+ValueTypePassFieldsAsArgs -XX:+ValueTypeReturnedAsFields -XX:-ValueArrayFlatten
56 * -XX:ValueFieldMaxFlatSize=0 -XX:ValueArrayElemMaxFlatSize=0 -XX:ValueArrayElemMaxFlatOops=0
57 * -DVerifyIR=false compiler.valhalla.valuetypes.TestLWorld
58 * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
59 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:+AlwaysIncrementalInline -XX:-UseBiasedLocking
60 * -XX:+EnableValhalla -XX:-ValueTypePassFieldsAsArgs -XX:-ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
61 * -XX:ValueFieldMaxFlatSize=0 -XX:ValueArrayElemMaxFlatSize=0 -XX:ValueArrayElemMaxFlatOops=0
62 * -XX:-MonomorphicArrayCheck
63 * -DVerifyIR=false compiler.valhalla.valuetypes.TestLWorld
64 * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
65 * -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI
66 * -XX:+EnableValhalla -XX:+ValueTypePassFieldsAsArgs -XX:-ValueTypeReturnedAsFields -XX:+ValueArrayFlatten
67 * -XX:ValueFieldMaxFlatSize=0 -XX:ValueArrayElemMaxFlatSize=-1 -XX:ValueArrayElemMaxFlatOops=-1
68 * -XX:-MonomorphicArrayCheck
69 * -DVerifyIR=false compiler.valhalla.valuetypes.TestLWorld
70 */
71 public class TestLWorld extends ValueTypeTest {
72
73 public static void main(String[] args) throws Throwable {
74 TestLWorld test = new TestLWorld();
75 test.run(args, MyValue1.class, MyValue2.class, MyValue2Inline.class, MyValue3.class, MyValue3Inline.class, Test65Value.class);
76 }
77
78 // Helper methods
79
843 public MyInterface test26(int state) {
844 MyInterface res = null;
845 if (state == 0) {
846 res = new MyObject(rI);
847 } else if (state == 1) {
848 res = MyValue1.createWithFieldsInline(rI, rL);
849 } else if (state == 2) {
850 res = MyValue1.createWithFieldsDontInline(rI, rL);
851 } else if (state == 3) {
852 res = (MyValue1)objectField1;
853 } else if (state == 4) {
854 res = valueField1;
855 } else if (state == 5) {
856 res = null;
857 }
858 return res;
859 }
860
861 @DontCompile
862 public void test26_verifier(boolean warmup) {
863 objectField1 = valueField1;
864 MyInterface result = null;
865 result = test26(0);
866 Asserts.assertEQ(((MyObject)result).x, rI);
867 result = test26(1);
868 Asserts.assertEQ(((MyValue1)result).hash(), hash());
869 result = test26(2);
870 Asserts.assertEQ(((MyValue1)result).hash(), hash());
871 result = test26(3);
872 Asserts.assertEQ(((MyValue1)result).hash(), hash());
873 result = test26(4);
874 Asserts.assertEQ(((MyValue1)result).hash(), hash());
875 result = test26(5);
876 Asserts.assertEQ(result, null);
877 }
878
879 // Test merging value types and interfaces in loops
880 @Test()
881 public MyInterface test27(int iters) {
882 MyInterface res = new MyObject(rI);
883 for (int i = 0; i < iters; ++i) {
1907 public void test68_verifier(boolean warmup) {
1908 MyValue1 result1 = (MyValue1)test68(true);
1909 Asserts.assertEQ(result1.hash(), hash());
1910 MyValue2 result2 = (MyValue2)test68(false);
1911 Asserts.assertEQ(result2.hash(), testValue2.hash());
1912 }
1913
1914 @Test()
1915 public Object test69(boolean b) {
1916 MyValue1 vt1 = MyValue1.createWithFieldsInline(rI, rL);
1917 MyValue2 vt2 = MyValue2.createWithFieldsInline(rI, true);
1918 return b ? vt1 : vt2;
1919 }
1920
1921 @DontCompile
1922 public void test69_verifier(boolean warmup) {
1923 MyValue1 result1 = (MyValue1)test69(true);
1924 Asserts.assertEQ(result1.hash(), hash());
1925 MyValue2 result2 = (MyValue2)test69(false);
1926 Asserts.assertEQ(result2.hash(), testValue2.hash());
1927 }
1928
1929 // Test synchronization on value types
1930 @Test()
1931 public void test70(Object vt) {
1932 synchronized (vt) {
1933 throw new RuntimeException("test70 failed: synchronization on value type should not succeed");
1934 }
1935 }
1936
1937 @DontCompile
1938 public void test70_verifier(boolean warmup) {
1939 try {
1940 test70(testValue1);
1941 throw new RuntimeException("test70 failed: no exception thrown");
1942 } catch (IllegalMonitorStateException ex) {
1943 // Expected
1944 }
1945 }
1946
1947 @ForceInline
1948 public void test71_inline(Object vt) {
1949 synchronized (vt) {
1950 throw new RuntimeException("test71 failed: synchronization on value type should not succeed");
1951 }
1952 }
1953
1954 @Test()
1955 public void test71(MyValue1 vt) {
1956 test71_inline(vt);
1957 }
1958
1959 @DontCompile
1960 public void test71_verifier(boolean warmup) {
1961 try {
1962 test71(testValue1);
1963 throw new RuntimeException("test71 failed: no exception thrown");
1964 } catch (IllegalMonitorStateException ex) {
1965 // Expected
1966 }
1967 }
1968
1969 @ForceInline
1970 public void test72_inline(Object vt) {
1971 synchronized (vt) {
1972 throw new RuntimeException("test72 failed: synchronization on value type should not succeed");
1973 }
1974 }
1975
1976 @Test()
1977 public void test72() {
1978 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
1979 test72_inline(vt);
1980 }
1981
1982 @DontCompile
1983 public void test72_verifier(boolean warmup) {
1984 try {
1985 test72();
1986 throw new RuntimeException("test72 failed: no exception thrown");
1987 } catch (IllegalMonitorStateException ex) {
1988 // Expected
1989 }
1990 }
1991
1992 @Test()
1993 public void test73(Object o, boolean b) {
1994 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
1995 Object sync = b ? vt : o;
1996 synchronized (sync) {
1997 if (b) {
1998 throw new RuntimeException("test73 failed: synchronization on value type should not succeed");
1999 }
2000 }
2001 }
2002
2003 @DontCompile
2004 public void test73_verifier(boolean warmup) {
2005 test73(new Object(), false);
2006 try {
2007 test73(new Object(), true);
2008 throw new RuntimeException("test73 failed: no exception thrown");
2009 } catch (IllegalMonitorStateException ex) {
2010 // Expected
2011 }
2012 }
2013
2014 @Test()
2015 public void test74(boolean b) {
2016 MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
2017 Object sync = b ? vt : testValue2;
2018 synchronized (sync) {
2019 throw new RuntimeException("test74 failed: synchronization on value type should not succeed");
2020 }
2021 }
2022
2023 @DontCompile
2024 public void test74_verifier(boolean warmup) {
2025 try {
2026 test74(false);
2027 throw new RuntimeException("test74 failed: no exception thrown");
2028 } catch (IllegalMonitorStateException ex) {
2029 // Expected
2030 }
2031 try {
2032 test74(true);
2033 throw new RuntimeException("test74 failed: no exception thrown");
2034 } catch (IllegalMonitorStateException ex) {
2035 // Expected
2036 }
2037 }
2038
2039 // Test catching the IllegalMonitorStateException in compiled code
2040 @Test()
2041 public void test75(Object vt) {
2042 boolean thrown = false;
2043 try {
2044 synchronized (vt) {
2045 throw new RuntimeException("test75 failed: no exception thrown");
2046 }
2047 } catch (IllegalMonitorStateException ex) {
2048 thrown = true;
2049 }
2050 if (!thrown) {
2051 throw new RuntimeException("test75 failed: no exception thrown");
2052 }
2053 }
2054
2055 @DontCompile
2056 public void test75_verifier(boolean warmup) {
2057 test75(testValue1);
2058 }
2059
2060 @Test()
2061 public void test76(Object o) {
2062 try {
2063 synchronized (o) { }
2064 } catch (IllegalMonitorStateException ex) {
2065 // Expected
2066 return;
2067 }
2068 throw new RuntimeException("test76 failed: no exception thrown");
2069 }
2070
2071 @DontCompile
2072 public void test76_verifier(boolean warmup) {
2073 test76(testValue1);
2074 }
2075
2076 // Test synchronization without any instructions in the synchronized block
2077 @Test()
2078 public void test77(Object o) {
2079 synchronized (o) { }
2080 }
2081
2082 @DontCompile
2083 public void test77_verifier(boolean warmup) {
2084 try {
2085 test77(testValue1);
2086 } catch (IllegalMonitorStateException ex) {
2087 // Expected
2088 return;
2089 }
2090 throw new RuntimeException("test77 failed: no exception thrown");
2091 }
2092 }
|