Blame SOURCES/8175887-pr3415.patch

a0b309
# HG changeset patch
a0b309
# User shade
a0b309
# Date 1488979372 -3600
a0b309
#      Wed Mar 08 14:22:52 2017 +0100
a0b309
# Node ID 654b7fcb4932d48063f5f1fba0c8994db5e02976
a0b309
# Parent  1faf7c17089922f6f72b580253725f2ecb6ba2f8
a0b309
8175887, PR3415: C1 value numbering handling of Unsafe.get*Volatile is incorrect
a0b309
Reviewed-by: vlivanov
a0b309
a0b309
diff --git a/src/share/vm/c1/c1_ValueMap.hpp b/src/share/vm/c1/c1_ValueMap.hpp
a0b309
--- openjdk/hotspot/src/share/vm/c1/c1_ValueMap.hpp
a0b309
+++ openjdk/hotspot/src/share/vm/c1/c1_ValueMap.hpp
a0b309
@@ -158,6 +158,12 @@
a0b309
   void do_UnsafePutRaw   (UnsafePutRaw*    x) { kill_memory(); }
a0b309
   void do_UnsafePutObject(UnsafePutObject* x) { kill_memory(); }
a0b309
   void do_UnsafeGetAndSetObject(UnsafeGetAndSetObject* x) { kill_memory(); }
a0b309
+  void do_UnsafeGetRaw   (UnsafeGetRaw*    x) { /* nothing to do */ }
a0b309
+  void do_UnsafeGetObject(UnsafeGetObject* x) {
a0b309
+    if (x->is_volatile()) { // the JMM requires this
a0b309
+      kill_memory();
a0b309
+    }
a0b309
+  }
a0b309
   void do_Intrinsic      (Intrinsic*       x) { if (!x->preserves_state()) kill_memory(); }
a0b309
 
a0b309
   void do_Phi            (Phi*             x) { /* nothing to do */ }
a0b309
@@ -198,8 +204,6 @@
a0b309
   void do_OsrEntry       (OsrEntry*        x) { /* nothing to do */ }
a0b309
   void do_ExceptionObject(ExceptionObject* x) { /* nothing to do */ }
a0b309
   void do_RoundFP        (RoundFP*         x) { /* nothing to do */ }
a0b309
-  void do_UnsafeGetRaw   (UnsafeGetRaw*    x) { /* nothing to do */ }
a0b309
-  void do_UnsafeGetObject(UnsafeGetObject* x) { /* nothing to do */ }
a0b309
   void do_UnsafePrefetchRead (UnsafePrefetchRead*  x) { /* nothing to do */ }
a0b309
   void do_UnsafePrefetchWrite(UnsafePrefetchWrite* x) { /* nothing to do */ }
a0b309
   void do_ProfileCall    (ProfileCall*     x) { /* nothing to do */ }
a0b309
diff --git a/test/compiler/c1/UnsafeVolatileGuardTest.java b/test/compiler/c1/UnsafeVolatileGuardTest.java
a0b309
new file mode 100644
a0b309
--- /dev/null
a0b309
+++ openjdk/hotspot/test/compiler/c1/UnsafeVolatileGuardTest.java
a0b309
@@ -0,0 +1,72 @@
a0b309
+/*
a0b309
+ * Copyright (c) 2017, Red Hat Inc. All rights reserved.
a0b309
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a0b309
+ *
a0b309
+ * This code is free software; you can redistribute it and/or modify it
a0b309
+ * under the terms of the GNU General Public License version 2 only, as
a0b309
+ * published by the Free Software Foundation.
a0b309
+ *
a0b309
+ * This code is distributed in the hope that it will be useful, but WITHOUT
a0b309
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a0b309
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a0b309
+ * version 2 for more details (a copy is included in the LICENSE file that
a0b309
+ * accompanied this code).
a0b309
+ *
a0b309
+ * You should have received a copy of the GNU General Public License version
a0b309
+ * 2 along with this work; if not, write to the Free Software Foundation,
a0b309
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a0b309
+ *
a0b309
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a0b309
+ * or visit www.oracle.com if you need additional information or have any
a0b309
+ * questions.
a0b309
+ */
a0b309
+
a0b309
+import java.lang.reflect.Field;
a0b309
+
a0b309
+/**
a0b309
+ * @test
a0b309
+ * @bug 8175887
a0b309
+ * @summary C1 value numbering handling of Unsafe.get*Volatile is incorrect
a0b309
+ * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:TieredStopAtLevel=1 UnsafeVolatileGuardTest
a0b309
+ */
a0b309
+public class UnsafeVolatileGuardTest {
a0b309
+    volatile static private int a;
a0b309
+    static private int b;
a0b309
+
a0b309
+    static final sun.misc.Unsafe UNSAFE;
a0b309
+
a0b309
+    static final Object BASE;
a0b309
+    static final long OFFSET;
a0b309
+
a0b309
+    static {
a0b309
+        try {
a0b309
+            Field uf = sun.misc.Unsafe.class.getDeclaredField("theUnsafe");
a0b309
+            uf.setAccessible(true);
a0b309
+            UNSAFE = (sun.misc.Unsafe)uf.get(null);
a0b309
+
a0b309
+            Field f = UnsafeVolatileGuardTest.class.getDeclaredField("a");
a0b309
+            BASE = UNSAFE.staticFieldBase(f);
a0b309
+            OFFSET = UNSAFE.staticFieldOffset(f);
a0b309
+        } catch (Exception e) {
a0b309
+            throw new RuntimeException(e);
a0b309
+        }
a0b309
+    }
a0b309
+
a0b309
+    static void test() {
a0b309
+        int tt = b; // makes the JVM CSE the value of b
a0b309
+
a0b309
+        while (UNSAFE.getIntVolatile(BASE, OFFSET) == 0) {} // burn
a0b309
+        if (b == 0) {
a0b309
+            System.err.println("wrong value of b");
a0b309
+            System.exit(1); // fail hard to report the error
a0b309
+        }
a0b309
+    }
a0b309
+
a0b309
+    public static void main(String [] args) throws Exception {
a0b309
+        for (int i = 0; i < 10; i++) {
a0b309
+            new Thread(UnsafeVolatileGuardTest::test).start();
a0b309
+        }
a0b309
+        b = 1;
a0b309
+        a = 1;
a0b309
+    }
a0b309
+}
a0b309
diff --git a/test/compiler/c1/VolatileGuardTest.java b/test/compiler/c1/VolatileGuardTest.java
a0b309
new file mode 100644
a0b309
--- /dev/null
a0b309
+++ openjdk/hotspot/test/compiler/c1/VolatileGuardTest.java
a0b309
@@ -0,0 +1,52 @@
a0b309
+/*
a0b309
+ * Copyright (c) 2017, Red Hat Inc. All rights reserved.
a0b309
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a0b309
+ *
a0b309
+ * This code is free software; you can redistribute it and/or modify it
a0b309
+ * under the terms of the GNU General Public License version 2 only, as
a0b309
+ * published by the Free Software Foundation.
a0b309
+ *
a0b309
+ * This code is distributed in the hope that it will be useful, but WITHOUT
a0b309
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a0b309
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
a0b309
+ * version 2 for more details (a copy is included in the LICENSE file that
a0b309
+ * accompanied this code).
a0b309
+ *
a0b309
+ * You should have received a copy of the GNU General Public License version
a0b309
+ * 2 along with this work; if not, write to the Free Software Foundation,
a0b309
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a0b309
+ *
a0b309
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
a0b309
+ * or visit www.oracle.com if you need additional information or have any
a0b309
+ * questions.
a0b309
+ */
a0b309
+
a0b309
+/**
a0b309
+ * @test
a0b309
+ * @bug 8175887
a0b309
+ * @summary C1 doesn't respect the JMM with volatile field loads
a0b309
+ *
a0b309
+ * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:TieredStopAtLevel=1 VolatileGuardTest
a0b309
+ */
a0b309
+public class VolatileGuardTest {
a0b309
+    volatile static private int a;
a0b309
+    static private int b;
a0b309
+
a0b309
+    static void test() {
a0b309
+        int tt = b; // makes the JVM CSE the value of b
a0b309
+
a0b309
+        while (a == 0) {} // burn
a0b309
+        if (b == 0) {
a0b309
+            System.err.println("wrong value of b");
a0b309
+            System.exit(1); // fail hard to report the error
a0b309
+        }
a0b309
+    }
a0b309
+
a0b309
+    public static void main(String [] args) throws Exception {
a0b309
+        for (int i = 0; i < 10; i++) {
a0b309
+            new Thread(VolatileGuardTest::test).start();
a0b309
+        }
a0b309
+        b = 1;
a0b309
+        a = 1;
a0b309
+    }
a0b309
+}