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