--- old/src/share/vm/runtime/atomic.hpp 2017-08-22 15:27:22.757186699 +0200 +++ new/src/share/vm/runtime/atomic.hpp 2017-08-22 15:27:22.593186704 +0200 @@ -219,6 +219,7 @@ public: // Temporary, can't be private: C++03 11.4/2. Fixed by C++11. template struct FetchAndAdd; template struct AddAndFetch; + struct AddShortUsingInt; private: // Support for platforms that implement some variants of add using a @@ -312,6 +313,20 @@ D operator()(I add_value, D volatile* dest) const; }; +// 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. +struct Atomic::AddShortUsingInt VALUE_OBJ_CLASS_SPEC { + template + T operator()(T add_value, T volatile* dest) const; +}; + // Define the class before including platform file, which may specialize // the operator definition. No generic definition of specializations // of the operator template are provided, nor are there any generic @@ -385,27 +400,16 @@ } }; -// 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. -template<> -struct Atomic::AddImpl VALUE_OBJ_CLASS_SPEC { - jshort operator()(jshort add_value, jshort volatile* dest) const { +template +T Atomic::AddShortUsingInt::operator()(T add_value, T volatile* dest) const { #ifdef VM_LITTLE_ENDIAN - assert((intx(dest) & 0x03) == 0x02, "wrong alignment"); - jint new_value = Atomic::add(add_value << 16, (volatile jint*)(dest-1)); + assert((intx(dest) & 0x03) == 0x02, "wrong alignment"); + uint32_t new_value = Atomic::add(uint32_t(add_value) << 16, (volatile uint32_t*)(dest-1)); #else - assert((intx(dest) & 0x03) == 0x00, "wrong alignment"); - jint new_value = Atomic::add(add_value << 16, (volatile jint*)(dest)); + assert((intx(dest) & 0x03) == 0x00, "wrong alignment"); + uint32_t new_value = Atomic::add(uint32_t(add_value) << 16, (volatile uint32_t*)(dest)); #endif - return (jshort)(new_value >> 16); // preserves sign - } + return T(new_value >> 16); // preserves sign }; template