< prev index next >

src/hotspot/os_cpu/solaris_sparc/atomic_solaris_sparc.hpp

Print this page
rev 49898 : 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
Reviewed-by:


  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 OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_HPP
  26 #define OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_HPP
  27 
  28 // Implementation of class atomic
  29 
  30 // Implement ADD using a CAS loop.
  31 template<size_t byte_size>
  32 struct Atomic::PlatformAdd {
  33   template<typename I, typename D>
  34   inline D operator()(I add_value, D volatile* dest) const {
  35     D old_value = *dest;
  36     while (true) {
  37       D new_value = old_value + add_value;
  38       D result = cmpxchg(new_value, dest, old_value);
  39       if (result == old_value) break;
  40       old_value = result;
  41     }
  42     return old_value + add_value;
  43   }
  44 };
  45 
  46 template<>
  47 template<typename T>
  48 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
  49                                              T volatile* dest) const {

  50   STATIC_ASSERT(4 == sizeof(T));
  51   __asm__ volatile (  "swap [%2],%0"
  52                     : "=r" (exchange_value)
  53                     : "0" (exchange_value), "r" (dest)
  54                     : "memory");
  55   return exchange_value;
  56 }
  57 
  58 template<>
  59 template<typename T>
  60 inline T Atomic::PlatformXchg<8>::operator()(T exchange_value,
  61                                              T volatile* dest) const {

  62   STATIC_ASSERT(8 == sizeof(T));
  63   T old_value = *dest;
  64   while (true) {
  65     T result = cmpxchg(exchange_value, dest, old_value);
  66     if (result == old_value) break;
  67     old_value = result;
  68   }
  69   return old_value;
  70 }
  71 
  72 // No direct support for cmpxchg of bytes; emulate using int.
  73 template<>
  74 struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};
  75 
  76 template<>
  77 template<typename T>
  78 inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value,
  79                                                 T volatile* dest,
  80                                                 T compare_value,
  81                                                 cmpxchg_memory_order order) const {
  82   STATIC_ASSERT(4 == sizeof(T));
  83   T rv;
  84   __asm__ volatile(
  85     " cas    [%2], %3, %0"
  86     : "=r" (rv)
  87     : "0" (exchange_value), "r" (dest), "r" (compare_value)
  88     : "memory");
  89   return rv;
  90 }
  91 
  92 template<>
  93 template<typename T>
  94 inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value,
  95                                                 T volatile* dest,
  96                                                 T compare_value,
  97                                                 cmpxchg_memory_order order) const {
  98   STATIC_ASSERT(8 == sizeof(T));
  99   T rv;
 100   __asm__ volatile(
 101     " casx   [%2], %3, %0"
 102     : "=r" (rv)
 103     : "0" (exchange_value), "r" (dest), "r" (compare_value)
 104     : "memory");
 105   return rv;
 106 }
 107 
 108 #endif // OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_HPP


  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 OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_HPP
  26 #define OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_HPP
  27 
  28 // Implementation of class atomic
  29 
  30 // Implement ADD using a CAS loop.
  31 template<size_t byte_size>
  32 struct Atomic::PlatformAdd {
  33   template<typename I, typename D>
  34   inline D operator()(I add_value, D volatile* dest, atomic_memory_order order) const {
  35     D old_value = *dest;
  36     while (true) {
  37       D new_value = old_value + add_value;
  38       D result = cmpxchg(new_value, dest, old_value);
  39       if (result == old_value) break;
  40       old_value = result;
  41     }
  42     return old_value + add_value;
  43   }
  44 };
  45 
  46 template<>
  47 template<typename T>
  48 inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
  49                                              T volatile* dest,
  50                                              atomic_memory_order order) const {
  51   STATIC_ASSERT(4 == sizeof(T));
  52   __asm__ volatile (  "swap [%2],%0"
  53                     : "=r" (exchange_value)
  54                     : "0" (exchange_value), "r" (dest)
  55                     : "memory");
  56   return exchange_value;
  57 }
  58 
  59 template<>
  60 template<typename T>
  61 inline T Atomic::PlatformXchg<8>::operator()(T exchange_value,
  62                                              T volatile* dest,
  63                                              atomic_memory_order order) const {
  64   STATIC_ASSERT(8 == sizeof(T));
  65   T old_value = *dest;
  66   while (true) {
  67     T result = cmpxchg(exchange_value, dest, old_value);
  68     if (result == old_value) break;
  69     old_value = result;
  70   }
  71   return old_value;
  72 }
  73 
  74 // No direct support for cmpxchg of bytes; emulate using int.
  75 template<>
  76 struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};
  77 
  78 template<>
  79 template<typename T>
  80 inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value,
  81                                                 T volatile* dest,
  82                                                 T compare_value,
  83                                                 atomic_memory_order order) const {
  84   STATIC_ASSERT(4 == sizeof(T));
  85   T rv;
  86   __asm__ volatile(
  87     " cas    [%2], %3, %0"
  88     : "=r" (rv)
  89     : "0" (exchange_value), "r" (dest), "r" (compare_value)
  90     : "memory");
  91   return rv;
  92 }
  93 
  94 template<>
  95 template<typename T>
  96 inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value,
  97                                                 T volatile* dest,
  98                                                 T compare_value,
  99                                                 atomic_memory_order order) const {
 100   STATIC_ASSERT(8 == sizeof(T));
 101   T rv;
 102   __asm__ volatile(
 103     " casx   [%2], %3, %0"
 104     : "=r" (rv)
 105     : "0" (exchange_value), "r" (dest), "r" (compare_value)
 106     : "memory");
 107   return rv;
 108 }
 109 
 110 #endif // OS_CPU_SOLARIS_SPARC_VM_ATOMIC_SOLARIS_SPARC_HPP
< prev index next >