< prev index next >

test/hotspot/jtreg/compiler/valhalla/valuetypes/TestLWorld.java

Print this page




   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 package compiler.valhalla.valuetypes;
  25 
  26 import java.lang.invoke.*;

  27 
  28 import jdk.experimental.value.MethodHandleBuilder;
  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  * @build TestLWorld_mismatched
  42  * @compile -XDenableValueTypes -XDallowWithFieldOperator -XDallowFlattenabilityModifiers TestLWorld.java
  43  * @run driver ClassFileInstaller sun.hotspot.WhiteBox jdk.test.lib.Platform
  44  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  45  *                               -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:+EnableValhalla
  46  *                               compiler.valhalla.valuetypes.ValueTypeTest


2295         Asserts.assertEquals(va[0].hash(), testValue1.hash());
2296     }
2297 
2298     // Verify that mixing instances and arrays with the clone api
2299     // doesn't break anything
2300     @Test
2301     public Object test91(Object o) {
2302         MyValue1[] va = new MyValue1[1];
2303         Object[] next = va;
2304         Object[] arr = va;
2305         for (int i = 0; i < 10; i++) {
2306             arr = next;
2307             next = new Integer[1];
2308         }
2309         return arr[0];
2310     }
2311 
2312     @DontCompile
2313     public void test91_verifier(boolean warmup) {
2314         test91(42);
















































2315     }
2316 }


   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 package compiler.valhalla.valuetypes;
  25 
  26 import java.lang.invoke.*;
  27 import java.lang.reflect.Method;
  28 
  29 import jdk.experimental.value.MethodHandleBuilder;
  30 import jdk.experimental.bytecode.MacroCodeBuilder;
  31 import jdk.experimental.bytecode.MacroCodeBuilder.CondKind;
  32 import jdk.experimental.bytecode.TypeTag;
  33 import jdk.test.lib.Asserts;
  34 
  35 /*
  36  * @test
  37  * @summary Test value types in LWorld.
  38  * @modules java.base/jdk.experimental.bytecode
  39  *          java.base/jdk.experimental.value
  40  * @library /testlibrary /test/lib /compiler/whitebox /
  41  * @requires os.simpleArch == "x64"
  42  * @build TestLWorld_mismatched
  43  * @compile -XDenableValueTypes -XDallowWithFieldOperator -XDallowFlattenabilityModifiers TestLWorld.java
  44  * @run driver ClassFileInstaller sun.hotspot.WhiteBox jdk.test.lib.Platform
  45  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  46  *                               -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:+EnableValhalla
  47  *                               compiler.valhalla.valuetypes.ValueTypeTest


2296         Asserts.assertEquals(va[0].hash(), testValue1.hash());
2297     }
2298 
2299     // Verify that mixing instances and arrays with the clone api
2300     // doesn't break anything
2301     @Test
2302     public Object test91(Object o) {
2303         MyValue1[] va = new MyValue1[1];
2304         Object[] next = va;
2305         Object[] arr = va;
2306         for (int i = 0; i < 10; i++) {
2307             arr = next;
2308             next = new Integer[1];
2309         }
2310         return arr[0];
2311     }
2312 
2313     @DontCompile
2314     public void test91_verifier(boolean warmup) {
2315         test91(42);
2316     }
2317 
2318     @DontInline
2319     public boolean test92_dontinline(MyValue1 vt) {
2320         return (Object)vt == null;
2321     }
2322 
2323     // Test c2c call passing null for a value type
2324     @Test
2325     @Warmup(10000) // Warmup to make sure 'test92_dontinline' is compiled
2326     public boolean test92(Object arg) throws Exception {
2327         Method test92method = getClass().getMethod("test92_dontinline", MyValue1.class);
2328         return (boolean)test92method.invoke(this, arg);
2329     }
2330 
2331     @DontCompile
2332     public void test92_verifier(boolean warmup) throws Exception {
2333         boolean res = test92(null);
2334         Asserts.assertTrue(res);
2335     }
2336 
2337     // Cast an Integer to a value type
2338     private static final MethodHandle castIntegerToValue = MethodHandleBuilder.loadCode(MethodHandles.lookup(),
2339         "castIntegerToValue",
2340         MethodType.methodType(void.class, TestLWorld.class, Integer.class),
2341         CODE -> {
2342             CODE.
2343             aload_1().
2344             checkcast(MyValue1.class).
2345             return_();
2346         },
2347         MyValue1.class);
2348 
2349     // Casting a null Integer to a value type should throw an exception
2350     @Test
2351     public void test93(Integer i) throws Throwable {
2352         castIntegerToValue.invoke(this, i);
2353     }
2354 
2355     @DontCompile
2356     public void test93_verifier(boolean warmup) throws Throwable {
2357         try {
2358             test93(null);
2359 // TODO enable this once we've fixed the interpreter to throw a NPE
2360 //            throw new RuntimeException("ClassCastException expected");
2361         } catch (ClassCastException e) {
2362             // Expected
2363         }
2364     }
2365 }
< prev index next >