101 return oop_atomic_cmpxchg(new_value, field_addr(base, offset), compare_value); |
101 return oop_atomic_cmpxchg(new_value, field_addr(base, offset), compare_value); |
102 } |
102 } |
103 |
103 |
104 template <DecoratorSet decorators> |
104 template <DecoratorSet decorators> |
105 template <typename T> |
105 template <typename T> |
106 inline T RawAccessBarrier<decorators>::oop_atomic_xchg(T new_value, void* addr) { |
106 inline T RawAccessBarrier<decorators>::oop_atomic_xchg(void* addr, T new_value) { |
107 typedef typename AccessInternal::EncodedType<decorators, T>::type Encoded; |
107 typedef typename AccessInternal::EncodedType<decorators, T>::type Encoded; |
108 Encoded encoded_new = encode(new_value); |
108 Encoded encoded_new = encode(new_value); |
109 Encoded encoded_result = atomic_xchg(encoded_new, reinterpret_cast<Encoded*>(addr)); |
109 Encoded encoded_result = atomic_xchg(reinterpret_cast<Encoded*>(addr), encoded_new); |
110 return decode<T>(encoded_result); |
110 return decode<T>(encoded_result); |
111 } |
111 } |
112 |
112 |
113 template <DecoratorSet decorators> |
113 template <DecoratorSet decorators> |
114 template <typename T> |
114 template <typename T> |
115 inline T RawAccessBarrier<decorators>::oop_atomic_xchg_at(T new_value, oop base, ptrdiff_t offset) { |
115 inline T RawAccessBarrier<decorators>::oop_atomic_xchg_at(oop base, ptrdiff_t offset, T new_value) { |
116 return oop_atomic_xchg(new_value, field_addr(base, offset)); |
116 return oop_atomic_xchg(field_addr(base, offset), new_value); |
117 } |
117 } |
118 |
118 |
119 template <DecoratorSet decorators> |
119 template <DecoratorSet decorators> |
120 template <typename T> |
120 template <typename T> |
121 inline bool RawAccessBarrier<decorators>::oop_arraycopy(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw, |
121 inline bool RawAccessBarrier<decorators>::oop_arraycopy(arrayOop src_obj, size_t src_offset_in_bytes, T* src_raw, |
201 |
201 |
202 template <DecoratorSet decorators> |
202 template <DecoratorSet decorators> |
203 template <DecoratorSet ds, typename T> |
203 template <DecoratorSet ds, typename T> |
204 inline typename EnableIf< |
204 inline typename EnableIf< |
205 HasDecorator<ds, MO_SEQ_CST>::value, T>::type |
205 HasDecorator<ds, MO_SEQ_CST>::value, T>::type |
206 RawAccessBarrier<decorators>::atomic_xchg_internal(T new_value, void* addr) { |
206 RawAccessBarrier<decorators>::atomic_xchg_internal(void* addr, T new_value) { |
207 return Atomic::xchg(new_value, |
207 return Atomic::xchg(reinterpret_cast<volatile T*>(addr), |
208 reinterpret_cast<volatile T*>(addr)); |
208 new_value); |
209 } |
209 } |
210 |
210 |
211 // For platforms that do not have native support for wide atomics, |
211 // For platforms that do not have native support for wide atomics, |
212 // we can emulate the atomicity using a lock. So here we check |
212 // we can emulate the atomicity using a lock. So here we check |
213 // whether that is necessary or not. |
213 // whether that is necessary or not. |
214 |
214 |
215 template <DecoratorSet ds> |
215 template <DecoratorSet ds> |
216 template <DecoratorSet decorators, typename T> |
216 template <DecoratorSet decorators, typename T> |
217 inline typename EnableIf< |
217 inline typename EnableIf< |
218 AccessInternal::PossiblyLockedAccess<T>::value, T>::type |
218 AccessInternal::PossiblyLockedAccess<T>::value, T>::type |
219 RawAccessBarrier<ds>::atomic_xchg_maybe_locked(T new_value, void* addr) { |
219 RawAccessBarrier<ds>::atomic_xchg_maybe_locked(void* addr, T new_value) { |
220 if (!AccessInternal::wide_atomic_needs_locking()) { |
220 if (!AccessInternal::wide_atomic_needs_locking()) { |
221 return atomic_xchg_internal<ds>(new_value, addr); |
221 return atomic_xchg_internal<ds>(addr, new_value); |
222 } else { |
222 } else { |
223 AccessInternal::AccessLocker access_lock; |
223 AccessInternal::AccessLocker access_lock; |
224 volatile T* p = reinterpret_cast<volatile T*>(addr); |
224 volatile T* p = reinterpret_cast<volatile T*>(addr); |
225 T old_val = RawAccess<>::load(p); |
225 T old_val = RawAccess<>::load(p); |
226 RawAccess<>::store(p, new_value); |
226 RawAccess<>::store(p, new_value); |