--- old/src/os_cpu/solaris_sparc/vm/atomic_solaris_sparc.hpp 2017-08-22 15:36:23.925167848 +0200 +++ new/src/os_cpu/solaris_sparc/vm/atomic_solaris_sparc.hpp 2017-08-22 15:36:23.757167854 +0200 @@ -62,22 +62,24 @@ extern "C" jint _Atomic_swap32(jint exchange_value, volatile jint* dest); extern "C" intptr_t _Atomic_swap64(intptr_t exchange_value, volatile intptr_t* dest); -extern "C" jint _Atomic_add32(jint inc, volatile jint* dest); -extern "C" intptr_t _Atomic_add64(intptr_t add_value, volatile intptr_t* dest); - - -inline jint Atomic::add (jint add_value, volatile jint* dest) { - return _Atomic_add32(add_value, dest); -} - -inline intptr_t Atomic::add_ptr(intptr_t add_value, volatile intptr_t* dest) { - return _Atomic_add64(add_value, dest); -} - -inline void* Atomic::add_ptr(intptr_t add_value, volatile void* dest) { - return (void*)add_ptr((intptr_t)add_value, (volatile intptr_t*)dest); -} +// Implement ADD using a CAS loop. +template +struct Atomic::PlatformAdd VALUE_OBJ_CLASS_SPEC { + template + inline D operator()(I add_value, D volatile* dest) const { + D old_value = *dest; + while (true) { + D new_value = old_value + add_value; + D result = cmpxchg(new_value, dest, old_value); + if (result == old_value) break; + old_value = result; + } + return old_value + add_value; + } +}; +template<> +struct Atomic::PlatformAdd<2>: Atomic::AddShortUsingInt {}; inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) { return _Atomic_swap32(exchange_value, dest);