changeset 59357:725478d023c4

8245236: Remove MO_VOLATILE Access decorator Summary: Use MO_RELAXED instead of MO_VOLATILE and removed MO_VOLATILE. Reviewed-by: stefank, tschatzl
author kbarrett
date Wed, 20 May 2020 02:02:48 -0400
parents 4cd328cdd20f
children 5bc71b982f41
files src/hotspot/share/gc/g1/g1BarrierSet.inline.hpp src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp src/hotspot/share/gc/g1/g1OopClosures.inline.hpp src/hotspot/share/oops/access.hpp src/hotspot/share/oops/accessBackend.hpp src/hotspot/share/oops/accessDecorators.hpp src/hotspot/share/oops/oop.hpp src/hotspot/share/oops/oop.inline.hpp
diffstat 8 files changed, 56 insertions(+), 73 deletions(-) [+]
line wrap: on
line diff
--- a/src/hotspot/share/gc/g1/g1BarrierSet.inline.hpp	Mon May 11 12:05:55 2020 +0800
+++ b/src/hotspot/share/gc/g1/g1BarrierSet.inline.hpp	Wed May 20 02:02:48 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2016, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -39,7 +39,7 @@
     return;
   }
 
-  T heap_oop = RawAccess<MO_VOLATILE>::oop_load(field);
+  T heap_oop = RawAccess<MO_RELAXED>::oop_load(field);
   if (!CompressedOops::is_null(heap_oop)) {
     enqueue(CompressedOops::decode_not_null(heap_oop));
   }
--- a/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp	Mon May 11 12:05:55 2020 +0800
+++ b/src/hotspot/share/gc/g1/g1ConcurrentMark.inline.hpp	Wed May 20 02:02:48 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2001, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -260,7 +260,7 @@
 template <class T>
 inline bool G1CMTask::deal_with_reference(T* p) {
   increment_refs_reached();
-  oop const obj = RawAccess<MO_VOLATILE>::oop_load(p);
+  oop const obj = RawAccess<MO_RELAXED>::oop_load(p);
   if (obj == NULL) {
     return false;
   }
--- a/src/hotspot/share/gc/g1/g1OopClosures.inline.hpp	Mon May 11 12:05:55 2020 +0800
+++ b/src/hotspot/share/gc/g1/g1OopClosures.inline.hpp	Wed May 20 02:02:48 2020 -0400
@@ -102,7 +102,7 @@
 
 template <class T>
 inline void G1RootRegionScanClosure::do_oop_work(T* p) {
-  T heap_oop = RawAccess<MO_VOLATILE>::oop_load(p);
+  T heap_oop = RawAccess<MO_RELAXED>::oop_load(p);
   if (CompressedOops::is_null(heap_oop)) {
     return;
   }
@@ -133,7 +133,7 @@
 
 template <class T>
 inline void G1ConcurrentRefineOopClosure::do_oop_work(T* p) {
-  T o = RawAccess<MO_VOLATILE>::oop_load(p);
+  T o = RawAccess<MO_RELAXED>::oop_load(p);
   if (CompressedOops::is_null(o)) {
     return;
   }
@@ -260,7 +260,7 @@
 }
 
 template <class T> void G1RebuildRemSetClosure::do_oop_work(T* p) {
-  oop const obj = RawAccess<MO_VOLATILE>::oop_load(p);
+  oop const obj = RawAccess<MO_RELAXED>::oop_load(p);
   if (obj == NULL) {
     return;
   }
--- a/src/hotspot/share/oops/access.hpp	Mon May 11 12:05:55 2020 +0800
+++ b/src/hotspot/share/oops/access.hpp	Wed May 20 02:02:48 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -123,8 +123,8 @@
     verify_decorators<expected_mo_decorators | heap_oop_decorators>();
   }
 
-  static const DecoratorSet load_mo_decorators = MO_UNORDERED | MO_VOLATILE | MO_RELAXED | MO_ACQUIRE | MO_SEQ_CST;
-  static const DecoratorSet store_mo_decorators = MO_UNORDERED | MO_VOLATILE | MO_RELAXED | MO_RELEASE | MO_SEQ_CST;
+  static const DecoratorSet load_mo_decorators = MO_UNORDERED | MO_RELAXED | MO_ACQUIRE | MO_SEQ_CST;
+  static const DecoratorSet store_mo_decorators = MO_UNORDERED | MO_RELAXED | MO_RELEASE | MO_SEQ_CST;
   static const DecoratorSet atomic_xchg_mo_decorators = MO_SEQ_CST;
   static const DecoratorSet atomic_cmpxchg_mo_decorators = MO_RELAXED | MO_SEQ_CST;
 
@@ -360,7 +360,6 @@
   const DecoratorSet memory_ordering_decorators = decorators & MO_DECORATOR_MASK;
   STATIC_ASSERT(memory_ordering_decorators == 0 || ( // make sure memory ordering decorators are disjoint if set
     (memory_ordering_decorators ^ MO_UNORDERED) == 0 ||
-    (memory_ordering_decorators ^ MO_VOLATILE) == 0 ||
     (memory_ordering_decorators ^ MO_RELAXED) == 0 ||
     (memory_ordering_decorators ^ MO_ACQUIRE) == 0 ||
     (memory_ordering_decorators ^ MO_RELEASE) == 0 ||
--- a/src/hotspot/share/oops/accessBackend.hpp	Mon May 11 12:05:55 2020 +0800
+++ b/src/hotspot/share/oops/accessBackend.hpp	Wed May 20 02:02:48 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2017, 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -249,13 +249,6 @@
 
   template <DecoratorSet ds, typename T>
   static inline typename EnableIf<
-    HasDecorator<ds, MO_VOLATILE>::value, T>::type
-  load_internal(void* addr) {
-    return *reinterpret_cast<const volatile T*>(addr);
-  }
-
-  template <DecoratorSet ds, typename T>
-  static inline typename EnableIf<
     HasDecorator<ds, MO_UNORDERED>::value, T>::type
   load_internal(void* addr) {
     return *reinterpret_cast<T*>(addr);
@@ -278,13 +271,6 @@
 
   template <DecoratorSet ds, typename T>
   static inline typename EnableIf<
-    HasDecorator<ds, MO_VOLATILE>::value>::type
-  store_internal(void* addr, T value) {
-    (void)const_cast<T&>(*reinterpret_cast<volatile T*>(addr) = value);
-  }
-
-  template <DecoratorSet ds, typename T>
-  static inline typename EnableIf<
     HasDecorator<ds, MO_UNORDERED>::value>::type
   store_internal(void* addr, T value) {
     *reinterpret_cast<T*>(addr) = value;
@@ -1119,7 +1105,7 @@
   }
 
   // Step 1: Set default decorators. This step remembers if a type was volatile
-  // and then sets the MO_VOLATILE decorator by default. Otherwise, a default
+  // and then sets the MO_RELAXED decorator by default. Otherwise, a default
   // memory ordering is set for the access, and the implied decorator rules
   // are applied to select sensible defaults for decorators that have not been
   // explicitly set. For example, default object referent strength is set to strong.
@@ -1143,10 +1129,10 @@
     typedef typename Decay<T>::type DecayedT;
     DecayedT decayed_value = value;
     // If a volatile address is passed in but no memory ordering decorator,
-    // set the memory ordering to MO_VOLATILE by default.
+    // set the memory ordering to MO_RELAXED by default.
     const DecoratorSet expanded_decorators = DecoratorFixup<
       (IsVolatile<P>::value && !HasDecorator<decorators, MO_DECORATOR_MASK>::value) ?
-      (MO_VOLATILE | decorators) : decorators>::value;
+      (MO_RELAXED | decorators) : decorators>::value;
     store_reduce_types<expanded_decorators>(const_cast<DecayedP*>(addr), decayed_value);
   }
 
@@ -1169,10 +1155,10 @@
                                  typename OopOrNarrowOop<T>::type,
                                  typename Decay<T>::type>::type DecayedT;
     // If a volatile address is passed in but no memory ordering decorator,
-    // set the memory ordering to MO_VOLATILE by default.
+    // set the memory ordering to MO_RELAXED by default.
     const DecoratorSet expanded_decorators = DecoratorFixup<
       (IsVolatile<P>::value && !HasDecorator<decorators, MO_DECORATOR_MASK>::value) ?
-      (MO_VOLATILE | decorators) : decorators>::value;
+      (MO_RELAXED | decorators) : decorators>::value;
     return load_reduce_types<expanded_decorators, DecayedT>(const_cast<DecayedP*>(addr));
   }
 
--- a/src/hotspot/share/oops/accessDecorators.hpp	Mon May 11 12:05:55 2020 +0800
+++ b/src/hotspot/share/oops/accessDecorators.hpp	Wed May 20 02:02:48 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -78,7 +78,6 @@
 // have a JMM equivalent property.
 // The equivalence may be viewed like this:
 // MO_UNORDERED is equivalent to JMM plain.
-// MO_VOLATILE has no equivalence in JMM, because it's a C++ thing.
 // MO_RELAXED is equivalent to JMM opaque.
 // MO_ACQUIRE is equivalent to JMM acquire.
 // MO_RELEASE is equivalent to JMM release.
@@ -87,12 +86,12 @@
 // === Stores ===
 //  * MO_UNORDERED (Default): No guarantees.
 //    - The compiler and hardware are free to reorder aggressively. And they will.
-//  * MO_VOLATILE: Volatile stores (in the C++ sense).
-//    - The stores are not reordered by the compiler (but possibly the HW) w.r.t. other
-//      volatile accesses in program order (but possibly non-volatile accesses).
 //  * MO_RELAXED: Relaxed atomic stores.
 //    - The stores are atomic.
-//    - Guarantees from volatile stores hold.
+//    - The stores are not reordered by the compiler (but possibly the HW) w.r.t
+//      other ordered accesses in program order.
+//    - Also used for C++ volatile stores, since actual usage of volatile
+//      requires no word tearing.
 //  * MO_RELEASE: Releasing stores.
 //    - The releasing store will make its preceding memory accesses observable to memory accesses
 //      subsequent to an acquiring load observing this releasing store.
@@ -104,12 +103,12 @@
 // === Loads ===
 //  * MO_UNORDERED (Default): No guarantees
 //    - The compiler and hardware are free to reorder aggressively. And they will.
-//  * MO_VOLATILE: Volatile loads (in the C++ sense).
-//    - The loads are not reordered by the compiler (but possibly the HW) w.r.t. other
-//      volatile accesses in program order (but possibly non-volatile accesses).
 //  * MO_RELAXED: Relaxed atomic loads.
 //    - The loads are atomic.
-//    - Guarantees from volatile loads hold.
+//    - The loads are not reordered by the compiler (but possibly the HW) w.r.t.
+//      other ordered accesses in program order.
+//    - Also used for C++ volatile loads, since actual usage of volatile
+//      requires no word tearing.
 //  * MO_ACQUIRE: Acquiring loads.
 //    - An acquiring load will make subsequent memory accesses observe the memory accesses
 //      preceding the releasing store that the acquiring load observed.
@@ -129,12 +128,11 @@
 //  * MO_SEQ_CST: Sequentially consistent xchg.
 //    - Guarantees from MO_SEQ_CST loads and MO_SEQ_CST stores hold.
 const DecoratorSet MO_UNORDERED      = UCONST64(1) << 6;
-const DecoratorSet MO_VOLATILE       = UCONST64(1) << 7;
-const DecoratorSet MO_RELAXED        = UCONST64(1) << 8;
-const DecoratorSet MO_ACQUIRE        = UCONST64(1) << 9;
-const DecoratorSet MO_RELEASE        = UCONST64(1) << 10;
-const DecoratorSet MO_SEQ_CST        = UCONST64(1) << 11;
-const DecoratorSet MO_DECORATOR_MASK = MO_UNORDERED | MO_VOLATILE | MO_RELAXED |
+const DecoratorSet MO_RELAXED        = UCONST64(1) << 7;
+const DecoratorSet MO_ACQUIRE        = UCONST64(1) << 8;
+const DecoratorSet MO_RELEASE        = UCONST64(1) << 9;
+const DecoratorSet MO_SEQ_CST        = UCONST64(1) << 10;
+const DecoratorSet MO_DECORATOR_MASK = MO_UNORDERED | MO_RELAXED |
                                        MO_ACQUIRE | MO_RELEASE | MO_SEQ_CST;
 
 // === Barrier Strength Decorators ===
@@ -154,9 +152,9 @@
 //   responsibility of performing the access and what barriers to be performed to the GC. This is the default.
 //   Note that primitive accesses will only be resolved on the barrier set if the appropriate build-time
 //   decorator for enabling primitive barriers is enabled for the build.
-const DecoratorSet AS_RAW                  = UCONST64(1) << 12;
-const DecoratorSet AS_NO_KEEPALIVE         = UCONST64(1) << 13;
-const DecoratorSet AS_NORMAL               = UCONST64(1) << 14;
+const DecoratorSet AS_RAW                  = UCONST64(1) << 11;
+const DecoratorSet AS_NO_KEEPALIVE         = UCONST64(1) << 12;
+const DecoratorSet AS_NORMAL               = UCONST64(1) << 13;
 const DecoratorSet AS_DECORATOR_MASK       = AS_RAW | AS_NO_KEEPALIVE | AS_NORMAL;
 
 // === Reference Strength Decorators ===
@@ -168,10 +166,10 @@
 // * ON_UNKNOWN_OOP_REF: The memory access is performed on a reference of unknown strength.
 //   This could for example come from the unsafe API.
 // * Default (no explicit reference strength specified): ON_STRONG_OOP_REF
-const DecoratorSet ON_STRONG_OOP_REF  = UCONST64(1) << 15;
-const DecoratorSet ON_WEAK_OOP_REF    = UCONST64(1) << 16;
-const DecoratorSet ON_PHANTOM_OOP_REF = UCONST64(1) << 17;
-const DecoratorSet ON_UNKNOWN_OOP_REF = UCONST64(1) << 18;
+const DecoratorSet ON_STRONG_OOP_REF  = UCONST64(1) << 14;
+const DecoratorSet ON_WEAK_OOP_REF    = UCONST64(1) << 15;
+const DecoratorSet ON_PHANTOM_OOP_REF = UCONST64(1) << 16;
+const DecoratorSet ON_UNKNOWN_OOP_REF = UCONST64(1) << 17;
 const DecoratorSet ON_DECORATOR_MASK  = ON_STRONG_OOP_REF | ON_WEAK_OOP_REF |
                                         ON_PHANTOM_OOP_REF | ON_UNKNOWN_OOP_REF;
 
@@ -181,8 +179,8 @@
 // * IN_HEAP: The access is performed in the heap. Many barriers such as card marking will
 //   be omitted if this decorator is not set.
 // * IN_NATIVE: The access is performed in an off-heap data structure.
-const DecoratorSet IN_HEAP            = UCONST64(1) << 19;
-const DecoratorSet IN_NATIVE          = UCONST64(1) << 20;
+const DecoratorSet IN_HEAP            = UCONST64(1) << 18;
+const DecoratorSet IN_NATIVE          = UCONST64(1) << 19;
 const DecoratorSet IN_DECORATOR_MASK  = IN_HEAP | IN_NATIVE;
 
 // == Boolean Flag Decorators ==
@@ -191,9 +189,9 @@
 // * IS_DEST_UNINITIALIZED: This property can be important to e.g. SATB barriers by
 //   marking that the previous value is uninitialized nonsense rather than a real value.
 // * IS_NOT_NULL: This property can make certain barriers faster such as compressing oops.
-const DecoratorSet IS_ARRAY              = UCONST64(1) << 21;
-const DecoratorSet IS_DEST_UNINITIALIZED = UCONST64(1) << 22;
-const DecoratorSet IS_NOT_NULL           = UCONST64(1) << 23;
+const DecoratorSet IS_ARRAY              = UCONST64(1) << 20;
+const DecoratorSet IS_DEST_UNINITIALIZED = UCONST64(1) << 21;
+const DecoratorSet IS_NOT_NULL           = UCONST64(1) << 22;
 
 // == Arraycopy Decorators ==
 // * ARRAYCOPY_CHECKCAST: This property means that the class of the objects in source
@@ -205,11 +203,11 @@
 // * ARRAYCOPY_ARRAYOF: The copy is in the arrayof form.
 // * ARRAYCOPY_ATOMIC: The accesses have to be atomic over the size of its elements.
 // * ARRAYCOPY_ALIGNED: The accesses have to be aligned on a HeapWord.
-const DecoratorSet ARRAYCOPY_CHECKCAST            = UCONST64(1) << 24;
-const DecoratorSet ARRAYCOPY_DISJOINT             = UCONST64(1) << 25;
-const DecoratorSet ARRAYCOPY_ARRAYOF              = UCONST64(1) << 26;
-const DecoratorSet ARRAYCOPY_ATOMIC               = UCONST64(1) << 27;
-const DecoratorSet ARRAYCOPY_ALIGNED              = UCONST64(1) << 28;
+const DecoratorSet ARRAYCOPY_CHECKCAST            = UCONST64(1) << 23;
+const DecoratorSet ARRAYCOPY_DISJOINT             = UCONST64(1) << 24;
+const DecoratorSet ARRAYCOPY_ARRAYOF              = UCONST64(1) << 25;
+const DecoratorSet ARRAYCOPY_ATOMIC               = UCONST64(1) << 26;
+const DecoratorSet ARRAYCOPY_ALIGNED              = UCONST64(1) << 27;
 const DecoratorSet ARRAYCOPY_DECORATOR_MASK       = ARRAYCOPY_CHECKCAST | ARRAYCOPY_DISJOINT |
                                                     ARRAYCOPY_DISJOINT | ARRAYCOPY_ARRAYOF |
                                                     ARRAYCOPY_ATOMIC | ARRAYCOPY_ALIGNED;
@@ -218,11 +216,11 @@
 // * ACCESS_READ: Indicate that the resolved object is accessed read-only. This allows the GC
 //   backend to use weaker and more efficient barriers.
 // * ACCESS_WRITE: Indicate that the resolved object is used for write access.
-const DecoratorSet ACCESS_READ                    = UCONST64(1) << 29;
-const DecoratorSet ACCESS_WRITE                   = UCONST64(1) << 30;
+const DecoratorSet ACCESS_READ                    = UCONST64(1) << 28;
+const DecoratorSet ACCESS_WRITE                   = UCONST64(1) << 29;
 
 // Keep track of the last decorator.
-const DecoratorSet DECORATOR_LAST = UCONST64(1) << 30;
+const DecoratorSet DECORATOR_LAST = UCONST64(1) << 29;
 
 namespace AccessInternal {
   // This class adds implied decorators that follow according to decorator rules.
--- a/src/hotspot/share/oops/oop.hpp	Mon May 11 12:05:55 2020 +0800
+++ b/src/hotspot/share/oops/oop.hpp	Wed May 20 02:02:48 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -64,8 +64,8 @@
   inline markWord  mark_raw()      const;
   inline markWord* mark_addr_raw() const;
 
-  inline void set_mark(volatile markWord m);
-  inline void set_mark_raw(volatile markWord m);
+  inline void set_mark(markWord m);
+  inline void set_mark_raw(markWord m);
   static inline void set_mark_raw(HeapWord* mem, markWord m);
 
   inline void release_set_mark(markWord m);
--- a/src/hotspot/share/oops/oop.inline.hpp	Mon May 11 12:05:55 2020 +0800
+++ b/src/hotspot/share/oops/oop.inline.hpp	Wed May 20 02:02:48 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -43,7 +43,7 @@
 // We need a separate file to avoid circular references
 
 markWord oopDesc::mark() const {
-  uintptr_t v = HeapAccess<MO_VOLATILE>::load_at(as_oop(), mark_offset_in_bytes());
+  uintptr_t v = HeapAccess<MO_RELAXED>::load_at(as_oop(), mark_offset_in_bytes());
   return markWord(v);
 }
 
@@ -56,7 +56,7 @@
 }
 
 void oopDesc::set_mark(markWord m) {
-  HeapAccess<MO_VOLATILE>::store_at(as_oop(), mark_offset_in_bytes(), m.value());
+  HeapAccess<MO_RELAXED>::store_at(as_oop(), mark_offset_in_bytes(), m.value());
 }
 
 void oopDesc::set_mark_raw(markWord m) {