< prev index next >

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

Print this page

@@ -36,10 +36,11 @@
  * @summary Test value types in LWorld.
  * @modules java.base/jdk.experimental.bytecode
  *          java.base/jdk.experimental.value
  * @library /testlibrary /test/lib /compiler/whitebox /
  * @requires os.simpleArch == "x64"
+ * @build GetNullAsm RarelyUsedValueUserAsm
  * @compile -XDenableValueTypes -XDallowFlattenabilityModifiers TestLWorld.java
  * @run driver ClassFileInstaller sun.hotspot.WhiteBox jdk.test.lib.Platform
  * @run main/othervm/timeout=120 -Xbootclasspath/a:. -ea -XX:+IgnoreUnrecognizedVMOptions -XX:+UnlockDiagnosticVMOptions
  *                   -XX:+UnlockExperimentalVMOptions -XX:+WhiteBoxAPI -XX:+AlwaysIncrementalInline
  *                   -XX:+EnableValhalla -XX:+ValueTypePassFieldsAsArgs -XX:+ValueTypeReturnedAsFields -XX:+ValueArrayFlatten

@@ -444,11 +445,20 @@
             valueField1 = (MyValue1)getNull.invoke();
             throw new RuntimeException("NullPointerException expected");
         } catch (NullPointerException e) {
             // Expected
         }
+
+        try {
+            valueField1 = (MyValue1)GetNullAsm.invoke();
+            throw new RuntimeException("NullPointerException expected");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+
         nullField = (MyValue1)getNull.invoke(); // Should not throw
+        nullField = (MyValue1)GetNullAsm.invoke(); // Should not throw
     }
 
     @DontCompile
     public void test13_verifier(boolean warmup) throws Throwable {
         test13();

@@ -2087,6 +2097,69 @@
             // Expected
             return;
         }
         throw new RuntimeException("test77 failed: no exception thrown");
     }
+    
+    // Test the null check of VT return values in callee.
+    @Test()
+    @Warmup(1)
+    public void test78() {
+       int n = RarelyUsedValueUser.doit();
+        if (n != 1234) {
+            throw new RuntimeException("Should be 1234 but got " + n);
+        }
+    }
+
+    @DontCompile
+    public void test78_verifier(boolean warmup) {
+        if (warmup) {
+            // Invoke RarelyUsedValueUserAsm.invoke() before RarelyUsedValue
+            // has been loaded. This means Method::check_returning_vt() cannot
+            // decide whether RarelyUsedValueUserAsm.legacy_areturn_null()
+            // is returning a VT or not.
+            RarelyUsedValueUserAsm.legacy_areturn_null();
+
+            // Make sure all constants RarelyUsedValueUser.doit in are resolved
+            // so we won't get uncommon traps.
+            RarelyUsedValueUser.warmup();
+        } else {
+            test78();
+        }
+    }
+}
+
+// Don't use this class in any test cases except for TestLWorld.test78. We want to make sure this
+// class is NOT loaded during other test cases.
+final __ByValue class RarelyUsedValue {
+    public final int v;
+    RarelyUsedValue () {
+        v = 0;
+    }
+    public static RarelyUsedValue makeRarelyUsedValue(int v) {
+        RarelyUsedValue p = __MakeDefault RarelyUsedValue();
+        p = __WithField(p.v, v);
+        return p;
+    }
+}
+
+class RarelyUsedValueUser {
+    static {
+        TestLWorld.setup(RarelyUsedValueUser.class);
+        TestLWorld.setup(RarelyUsedValueUserAsm.class);
+    }
+
+    @DontCompile
+    static void warmup() {
+        doit();
+    }
+
+    @ForceInline
+    static int doit() {
+        try {
+            RarelyUsedValue x = RarelyUsedValueUserAsm.legacy_areturn_null();
+            return x.v;
+        } catch (Throwable t) {
+            return 1234;
+        }
+    }
 }
< prev index next >