< prev index next >

src/hotspot/os_cpu/solaris_sparc/atomic_solaris_sparc.hpp

Print this page




  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_ATOMIC_SOLARIS_SPARC_HPP
  26 #define OS_CPU_SOLARIS_SPARC_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 D, typename I>
  34   inline D operator()(D volatile* dest, I add_value, 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 volatile* dest,
  49                                              T exchange_value,
  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 volatile* dest,
  62                                              T exchange_value,
  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_ATOMIC_SOLARIS_SPARC_HPP


  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_ATOMIC_SOLARIS_SPARC_HPP
  26 #define OS_CPU_SOLARIS_SPARC_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 D, typename I>
  34   inline D operator()(D volatile* dest, I add_value, 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(dest, old_value, new_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 volatile* dest,
  49                                              T exchange_value,
  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 volatile* dest,
  62                                              T exchange_value,
  63                                              atomic_memory_order order) const {
  64   STATIC_ASSERT(8 == sizeof(T));
  65   T old_value = *dest;
  66   while (true) {
  67     T result = cmpxchg(dest, old_value, exchange_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 volatile* dest,

  81                                                 T compare_value,
  82                                                 T exchange_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 volatile* dest,

  97                                                 T compare_value,
  98                                                 T exchange_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_ATOMIC_SOLARIS_SPARC_HPP
< prev index next >