src/share/vm/runtime/atomic.hpp

Print this page

        

*** 74,83 **** --- 74,84 ---- // See comment above about using jlong atomics on 32-bit platforms inline static jlong load(volatile jlong* src); // Atomically add to a location. Returns updated value. add*() provide: // <fence> add-value-to-dest <membar StoreLoad|StoreStore> + inline static jshort add (jshort add_value, volatile jshort* dest); inline static jint add (jint add_value, volatile jint* dest); inline static size_t add (size_t add_value, volatile size_t* dest); inline static intptr_t add_ptr(intptr_t add_value, volatile intptr_t* dest); inline static void* add_ptr(intptr_t add_value, volatile void* dest); // See comment above about using jlong atomics on 32-bit platforms
*** 193,226 **** new_value = old + add_value; } return old; } ! inline void Atomic::inc(volatile short* dest) { ! // Most platforms do not support atomic increment on a 2-byte value. However, // if the value occupies the most significant 16 bits of an aligned 32-bit ! // word, then we can do this with an atomic add of 0x10000 to the 32-bit word. // // The least significant parts of this 32-bit word will never be affected, even // in case of overflow/underflow. // // Use the ATOMIC_SHORT_PAIR macro (see macros.hpp) to get the desired alignment. #ifdef VM_LITTLE_ENDIAN assert((intx(dest) & 0x03) == 0x02, "wrong alignment"); ! (void)Atomic::add(0x10000, (volatile int*)(dest-1)); #else assert((intx(dest) & 0x03) == 0x00, "wrong alignment"); ! (void)Atomic::add(0x10000, (volatile int*)(dest)); #endif } ! inline void Atomic::dec(volatile short* dest) { ! #ifdef VM_LITTLE_ENDIAN ! assert((intx(dest) & 0x03) == 0x02, "wrong alignment"); ! (void)Atomic::add(-0x10000, (volatile int*)(dest-1)); ! #else ! assert((intx(dest) & 0x03) == 0x00, "wrong alignment"); ! (void)Atomic::add(-0x10000, (volatile int*)(dest)); ! #endif } #endif // SHARE_VM_RUNTIME_ATOMIC_HPP --- 194,227 ---- new_value = old + add_value; } return old; } ! inline jshort Atomic::add(jshort add_value, volatile jshort* dest) { ! // Most platforms do not support atomic add on a 2-byte value. However, // if the value occupies the most significant 16 bits of an aligned 32-bit ! // word, then we can do this with an atomic add of (add_value << 16) ! // to the 32-bit word. // // The least significant parts of this 32-bit word will never be affected, even // in case of overflow/underflow. // // Use the ATOMIC_SHORT_PAIR macro (see macros.hpp) to get the desired alignment. #ifdef VM_LITTLE_ENDIAN assert((intx(dest) & 0x03) == 0x02, "wrong alignment"); ! jint new_value = Atomic::add(add_value << 16, (volatile jint*)(dest-1)); #else assert((intx(dest) & 0x03) == 0x00, "wrong alignment"); ! jint new_value = Atomic::add(add_value << 16, (volatile jint*)(dest)); #endif + return (jshort)(new_value >> 16); // preserves sign } ! inline void Atomic::inc(volatile jshort* dest) { ! (void)add(1, dest); ! } ! ! inline void Atomic::dec(volatile jshort* dest) { ! (void)add(-1, dest); } #endif // SHARE_VM_RUNTIME_ATOMIC_HPP