changeset 55128:ec67666497c5 lworld

8223931: [lworld] C1 ValueTypeReturnedAsFields should check if method return value is never null
author iklam
date Tue, 14 May 2019 21:06:00 -0700
parents a315df71e821
children 784781105f6b
files src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp src/hotspot/share/c1/c1_LIRAssembler.cpp test/hotspot/jtreg/compiler/valhalla/valuetypes/TestCallingConventionC1.java
diffstat 3 files changed, 67 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp	Tue May 14 12:30:15 2019 -0700
+++ b/src/hotspot/cpu/x86/c1_LIRAssembler_x86.cpp	Tue May 14 21:06:00 2019 -0700
@@ -518,8 +518,9 @@
     assert(result->fpu() == 0, "result must already be on TOS");
   }
 
-  if (ValueTypeReturnedAsFields) {
-    ciType* return_type = compilation()->method()->return_type();
+  ciMethod* method = compilation()->method();
+  if (ValueTypeReturnedAsFields && method->signature()->returns_never_null()) {
+    ciType* return_type = method->return_type();
     if (return_type->is_valuetype()) {
       ciValueKlass* vk = return_type->as_value_klass();
       if (vk->can_be_returned_as_fields()) {
--- a/src/hotspot/share/c1/c1_LIRAssembler.cpp	Tue May 14 12:30:15 2019 -0700
+++ b/src/hotspot/share/c1/c1_LIRAssembler.cpp	Tue May 14 21:06:00 2019 -0700
@@ -482,8 +482,9 @@
     compilation()->set_has_method_handle_invokes(true);
   }
 
-  if (ValueTypeReturnedAsFields) {
-    ciType* return_type = op->method()->return_type();
+  ciMethod* method = op->method();
+  if (ValueTypeReturnedAsFields && method->signature()->returns_never_null()) {
+    ciType* return_type = method->return_type();
     if (return_type->is_valuetype()) {
       ciValueKlass* vk = return_type->as_value_klass();
       if (vk->can_be_returned_as_fields()) {
--- a/test/hotspot/jtreg/compiler/valhalla/valuetypes/TestCallingConventionC1.java	Tue May 14 12:30:15 2019 -0700
+++ b/test/hotspot/jtreg/compiler/valhalla/valuetypes/TestCallingConventionC1.java	Tue May 14 21:06:00 2019 -0700
@@ -53,12 +53,12 @@
 
         // Default: both C1 and C2 are enabled, tierd compilation enabled
         case 0: return new String[] {"-XX:+EnableValhallaC1", "-XX:CICompilerCount=2"
-                                     , "-XX:-CheckCompressedOops", "-XX:CompileCommand=print,*::test78*"
+                                   //  , "-XX:-CheckCompressedOops", "-XX:CompileCommand=print,*::test78*"
                                    //, "-XX:CompileCommand=print,*::func_c1"
                                      };
         // Only C1. Tierd compilation disabled.
         case 1: return new String[] {"-XX:+EnableValhallaC1", "-XX:TieredStopAtLevel=1"
-                                     , "-XX:-CheckCompressedOops", "-XX:CompileCommand=print,*::test76*"
+                                   //  , "-XX:-CheckCompressedOops", "-XX:CompileCommand=print,*::test76*"
                                      };
         }
         return null;
@@ -1647,4 +1647,63 @@
         int n = tooBig.a0 + tooBig.a5;
         Asserts.assertEQ(result, n);
     }
+
+    //-------------------------------------------------------------------------------
+    // Tests for how C1 handles ValueTypeReturnedAsFields in both calls and returns (RefPoint?)
+    //-------------------------------------------------------------------------------
+
+    // C2->C1 invokestatic with ValueTypeReturnedAsFields (RefPoint?)
+    @Test(compLevel = C2)
+    public RefPoint? test87(RefPoint? p) {
+        return test87_helper(p);
+    }
+
+    @DontInline
+    @ForceCompile(compLevel = C1)
+    private static RefPoint? test87_helper(RefPoint? p) {
+        return p;
+    }
+
+    @DontCompile
+    public void test87_verifier(boolean warmup) {
+        Object result = test87(null);
+        Asserts.assertEQ(result, null);
+    }
+
+    // C2->C1 invokestatic with ValueTypeReturnedAsFields (RefPoint? with constant null)
+    @Test(compLevel = C2)
+    public RefPoint? test88() {
+        return test88_helper();
+    }
+
+    @DontInline
+    @ForceCompile(compLevel = C1)
+    private static RefPoint? test88_helper() {
+        return null;
+    }
+
+    @DontCompile
+    public void test88_verifier(boolean warmup) {
+        Object result = test88();
+        Asserts.assertEQ(result, null);
+    }
+
+    // C1->C2 invokestatic with ValueTypeReturnedAsFields (RefPoint?)
+    @Test(compLevel = C1)
+    public RefPoint? test89(RefPoint? p) {
+        return test89_helper(p);
+    }
+
+    @DontInline
+    @ForceCompile(compLevel = C2)
+    private static RefPoint? test89_helper(RefPoint? p) {
+        return p;
+    }
+
+    @DontCompile
+    public void test89_verifier(boolean warmup) {
+        Object result = test89(null);
+        Asserts.assertEQ(result, null);
+    }
+
 }