changeset 57336:6eaf377afed9 lworld

8231961: [lworld] C1 compiled code returns incorrect value for flattened array access Reviewed-by: iklam
author thartmann
date Thu, 10 Oct 2019 14:11:18 +0200
parents 8e23ef61c421
children 114caf2fa7b9
files src/hotspot/share/c1/c1_Instruction.hpp test/hotspot/jtreg/compiler/valhalla/valuetypes/TestC1.java
diffstat 2 files changed, 25 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/c1/c1_Instruction.hpp	Wed Oct 09 10:24:01 2019 -0400
+++ b/src/hotspot/share/c1/c1_Instruction.hpp	Thu Oct 10 14:11:18 2019 +0200
@@ -990,11 +990,11 @@
   ciType* exact_type() const;
   ciType* declared_type() const;
 
-  NewValueTypeInstance* vt() { return _vt; }
+  NewValueTypeInstance* vt() const { return _vt; }
   void set_vt(NewValueTypeInstance* vt) { _vt = vt; }
 
   // generic
-  HASHING2(LoadIndexed, true, array()->subst(), index()->subst())
+  HASHING3(LoadIndexed, true, array()->subst(), index()->subst(), vt())
 };
 
 
--- a/test/hotspot/jtreg/compiler/valhalla/valuetypes/TestC1.java	Wed Oct 09 10:24:01 2019 -0400
+++ b/test/hotspot/jtreg/compiler/valhalla/valuetypes/TestC1.java	Thu Oct 10 14:11:18 2019 +0200
@@ -106,4 +106,27 @@
         Asserts.assertEQ(r1, 0x5678123456781234L);
         Asserts.assertEQ(r2, 0x1234567812345678L);
     }
+
+    static inline class SimpleValue2 {
+        final int value;
+        SimpleValue2(int value) {
+            this.value = value;
+        }
+    }
+
+    // JDK-8231961
+    // Test that the value numbering optimization does not remove
+    // the second load from the buffered array element.
+    @Test(compLevel=C1)
+    public int test2(SimpleValue2[] array) {
+        return array[0].value + array[0].value;
+    }
+
+    @DontCompile
+    public void test2_verifier(boolean warmup) {
+        SimpleValue2[] array = new SimpleValue2[1];
+        array[0] = new SimpleValue2(rI);
+        int result = test2(array);
+        Asserts.assertEQ(result, 2*rI);
+    }
 }