< prev index next >

src/hotspot/os_cpu/linux_zero/atomic_linux_zero.hpp

Print this page




  42 template<typename D, typename I>
  43 inline D Atomic::PlatformAdd<4>::add_and_fetch(D volatile* dest, I add_value,
  44                                                atomic_memory_order order) const {
  45   STATIC_ASSERT(4 == sizeof(I));
  46   STATIC_ASSERT(4 == sizeof(D));
  47 
  48   return __sync_add_and_fetch(dest, add_value);
  49 }
  50 
  51 template<>
  52 template<typename D, typename I>
  53 inline D Atomic::PlatformAdd<8>::add_and_fetch(D volatile* dest, I add_value,
  54                                                atomic_memory_order order) const {
  55   STATIC_ASSERT(8 == sizeof(I));
  56   STATIC_ASSERT(8 == sizeof(D));
  57   return __sync_add_and_fetch(dest, add_value);
  58 }
  59 
  60 template<>
  61 template<typename T>
  62 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
  63                                              T volatile* dest,
  64                                              atomic_memory_order order) const {
  65   STATIC_ASSERT(4 == sizeof(T));
  66   // __sync_lock_test_and_set is a bizarrely named atomic exchange
  67   // operation.  Note that some platforms only support this with the
  68   // limitation that the only valid value to store is the immediate
  69   // constant 1.  There is a test for this in JNI_CreateJavaVM().
  70   T result = __sync_lock_test_and_set (dest, exchange_value);
  71   // All atomic operations are expected to be full memory barriers
  72   // (see atomic.hpp). However, __sync_lock_test_and_set is not
  73   // a full memory barrier, but an acquire barrier. Hence, this added
  74   // barrier.
  75   __sync_synchronize();
  76   return result;
  77 }
  78 
  79 template<>
  80 template<typename T>
  81 inline T Atomic::PlatformXchg<8>::operator()(T exchange_value,
  82                                              T volatile* dest,
  83                                              atomic_memory_order order) const {
  84   STATIC_ASSERT(8 == sizeof(T));
  85   T result = __sync_lock_test_and_set (dest, exchange_value);
  86   __sync_synchronize();
  87   return result;
  88 }
  89 
  90 // No direct support for cmpxchg of bytes; emulate using int.
  91 template<>
  92 struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};
  93 
  94 template<>
  95 template<typename T>
  96 inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value,
  97                                                 T volatile* dest,
  98                                                 T compare_value,
  99                                                 atomic_memory_order order) const {
 100   STATIC_ASSERT(4 == sizeof(T));
 101   return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
 102 }




  42 template<typename D, typename I>
  43 inline D Atomic::PlatformAdd<4>::add_and_fetch(D volatile* dest, I add_value,
  44                                                atomic_memory_order order) const {
  45   STATIC_ASSERT(4 == sizeof(I));
  46   STATIC_ASSERT(4 == sizeof(D));
  47 
  48   return __sync_add_and_fetch(dest, add_value);
  49 }
  50 
  51 template<>
  52 template<typename D, typename I>
  53 inline D Atomic::PlatformAdd<8>::add_and_fetch(D volatile* dest, I add_value,
  54                                                atomic_memory_order order) const {
  55   STATIC_ASSERT(8 == sizeof(I));
  56   STATIC_ASSERT(8 == sizeof(D));
  57   return __sync_add_and_fetch(dest, add_value);
  58 }
  59 
  60 template<>
  61 template<typename T>
  62 inline T Atomic::PlatformXchg<4>::operator()(T volatile* dest,
  63                                              T exchange_value,
  64                                              atomic_memory_order order) const {
  65   STATIC_ASSERT(4 == sizeof(T));
  66   // __sync_lock_test_and_set is a bizarrely named atomic exchange
  67   // operation.  Note that some platforms only support this with the
  68   // limitation that the only valid value to store is the immediate
  69   // constant 1.  There is a test for this in JNI_CreateJavaVM().
  70   T result = __sync_lock_test_and_set (dest, exchange_value);
  71   // All atomic operations are expected to be full memory barriers
  72   // (see atomic.hpp). However, __sync_lock_test_and_set is not
  73   // a full memory barrier, but an acquire barrier. Hence, this added
  74   // barrier.
  75   __sync_synchronize();
  76   return result;
  77 }
  78 
  79 template<>
  80 template<typename T>
  81 inline T Atomic::PlatformXchg<8>::operator()(T volatile* dest,
  82                                              T exchange_value,
  83                                              atomic_memory_order order) const {
  84   STATIC_ASSERT(8 == sizeof(T));
  85   T result = __sync_lock_test_and_set (dest, exchange_value);
  86   __sync_synchronize();
  87   return result;
  88 }
  89 
  90 // No direct support for cmpxchg of bytes; emulate using int.
  91 template<>
  92 struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};
  93 
  94 template<>
  95 template<typename T>
  96 inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value,
  97                                                 T volatile* dest,
  98                                                 T compare_value,
  99                                                 atomic_memory_order order) const {
 100   STATIC_ASSERT(4 == sizeof(T));
 101   return __sync_val_compare_and_swap(dest, compare_value, exchange_value);
 102 }


< prev index next >