Blame SOURCES/8175887-pr3415.patch

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