< prev index next >

src/hotspot/share/runtime/orderAccess.hpp

Print this page




  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_ORDERACCESS_HPP
  26 #define SHARE_VM_RUNTIME_ORDERACCESS_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/atomic.hpp"

  30 
  31 //                Memory Access Ordering Model
  32 //
  33 // This interface is based on the JSR-133 Cookbook for Compiler Writers.
  34 //
  35 // In the following, the terms 'previous', 'subsequent', 'before',
  36 // 'after', 'preceding' and 'succeeding' refer to program order.  The
  37 // terms 'down' and 'below' refer to forward load or store motion
  38 // relative to program order, while 'up' and 'above' refer to backward
  39 // motion.
  40 //
  41 // We define four primitive memory barrier operations.
  42 //
  43 // LoadLoad:   Load1(s); LoadLoad; Load2
  44 //
  45 // Ensures that Load1 completes (obtains the value it loads from memory)
  46 // before Load2 and any subsequent load operations.  Loads before Load1
  47 // may *not* float below Load2 and any subsequent load operations.
  48 //
  49 // StoreStore: Store1(s); StoreStore; Store2


 294 // The following methods can be specialized using simple template specialization
 295 // in the platform specific files for optimization purposes. Otherwise the
 296 // generalized variant is used.
 297 
 298 template<size_t byte_size, ScopedFenceType type>
 299 struct OrderAccess::PlatformOrderedStore {
 300   template <typename T>
 301   void operator()(T v, volatile T* p) const {
 302     ordered_store<T, type>(p, v);
 303   }
 304 };
 305 
 306 template<size_t byte_size, ScopedFenceType type>
 307 struct OrderAccess::PlatformOrderedLoad {
 308   template <typename T>
 309   T operator()(const volatile T* p) const {
 310     return ordered_load<T, type>(p);
 311   }
 312 };
 313 


































 314 #endif // SHARE_VM_RUNTIME_ORDERACCESS_HPP


  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #ifndef SHARE_VM_RUNTIME_ORDERACCESS_HPP
  26 #define SHARE_VM_RUNTIME_ORDERACCESS_HPP
  27 
  28 #include "memory/allocation.hpp"
  29 #include "runtime/atomic.hpp"
  30 #include "utilities/macros.hpp"
  31 
  32 //                Memory Access Ordering Model
  33 //
  34 // This interface is based on the JSR-133 Cookbook for Compiler Writers.
  35 //
  36 // In the following, the terms 'previous', 'subsequent', 'before',
  37 // 'after', 'preceding' and 'succeeding' refer to program order.  The
  38 // terms 'down' and 'below' refer to forward load or store motion
  39 // relative to program order, while 'up' and 'above' refer to backward
  40 // motion.
  41 //
  42 // We define four primitive memory barrier operations.
  43 //
  44 // LoadLoad:   Load1(s); LoadLoad; Load2
  45 //
  46 // Ensures that Load1 completes (obtains the value it loads from memory)
  47 // before Load2 and any subsequent load operations.  Loads before Load1
  48 // may *not* float below Load2 and any subsequent load operations.
  49 //
  50 // StoreStore: Store1(s); StoreStore; Store2


 295 // The following methods can be specialized using simple template specialization
 296 // in the platform specific files for optimization purposes. Otherwise the
 297 // generalized variant is used.
 298 
 299 template<size_t byte_size, ScopedFenceType type>
 300 struct OrderAccess::PlatformOrderedStore {
 301   template <typename T>
 302   void operator()(T v, volatile T* p) const {
 303     ordered_store<T, type>(p, v);
 304   }
 305 };
 306 
 307 template<size_t byte_size, ScopedFenceType type>
 308 struct OrderAccess::PlatformOrderedLoad {
 309   template <typename T>
 310   T operator()(const volatile T* p) const {
 311     return ordered_load<T, type>(p);
 312   }
 313 };
 314 
 315 #include OS_CPU_HEADER(orderAccess)
 316 
 317 template<> inline void ScopedFenceGeneral<X_ACQUIRE>::postfix()       { OrderAccess::acquire(); }
 318 template<> inline void ScopedFenceGeneral<RELEASE_X>::prefix()        { OrderAccess::release(); }
 319 template<> inline void ScopedFenceGeneral<RELEASE_X_FENCE>::prefix()  { OrderAccess::release(); }
 320 template<> inline void ScopedFenceGeneral<RELEASE_X_FENCE>::postfix() { OrderAccess::fence();   }
 321 
 322 
 323 template <typename FieldType, ScopedFenceType FenceType>
 324 inline void OrderAccess::ordered_store(volatile FieldType* p, FieldType v) {
 325   ScopedFence<FenceType> f((void*)p);
 326   Atomic::store(v, p);
 327 }
 328 
 329 template <typename FieldType, ScopedFenceType FenceType>
 330 inline FieldType OrderAccess::ordered_load(const volatile FieldType* p) {
 331   ScopedFence<FenceType> f((void*)p);
 332   return Atomic::load(p);
 333 }
 334 
 335 template <typename T>
 336 inline T OrderAccess::load_acquire(const volatile T* p) {
 337   return LoadImpl<T, PlatformOrderedLoad<sizeof(T), X_ACQUIRE> >()(p);
 338 }
 339 
 340 template <typename T, typename D>
 341 inline void OrderAccess::release_store(volatile D* p, T v) {
 342   StoreImpl<T, D, PlatformOrderedStore<sizeof(D), RELEASE_X> >()(v, p);
 343 }
 344 
 345 template <typename T, typename D>
 346 inline void OrderAccess::release_store_fence(volatile D* p, T v) {
 347   StoreImpl<T, D, PlatformOrderedStore<sizeof(D), RELEASE_X_FENCE> >()(v, p);
 348 }
 349 #endif // SHARE_VM_RUNTIME_ORDERACCESS_HPP
< prev index next >