--- old/src/hotspot/os_cpu/aix_ppc/atomic_aix_ppc.hpp 2017-10-03 14:31:22.354897924 +0200 +++ new/src/hotspot/os_cpu/aix_ppc/atomic_aix_ppc.hpp 2017-10-03 14:31:22.126897932 +0200 @@ -34,22 +34,6 @@ // Implementation of class atomic -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - -inline jlong Atomic::load(const volatile jlong* src) { return *src; } - // // machine barrier instructions: // --- old/src/hotspot/os_cpu/bsd_x86/atomic_bsd_x86.hpp 2017-10-03 14:31:23.194897895 +0200 +++ new/src/hotspot/os_cpu/bsd_x86/atomic_bsd_x86.hpp 2017-10-03 14:31:22.966897903 +0200 @@ -27,19 +27,6 @@ // Implementation of class atomic -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - - template struct Atomic::PlatformAdd : Atomic::FetchAndAdd > @@ -102,9 +89,6 @@ } #ifdef AMD64 -inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } - template<> template inline D Atomic::PlatformAdd<8>::fetch_and_add(I add_value, D volatile* dest) const { @@ -144,8 +128,6 @@ return exchange_value; } -inline jlong Atomic::load(const volatile jlong* src) { return *src; } - #else // !AMD64 extern "C" { @@ -164,18 +146,21 @@ return cmpxchg_using_helper(_Atomic_cmpxchg_long, exchange_value, dest, compare_value); } -inline jlong Atomic::load(const volatile jlong* src) { +template<> +template +inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const { + STATIC_ASSERT(8 == sizeof(T)); volatile jlong dest; - _Atomic_move_long(src, &dest); - return dest; -} - -inline void Atomic::store(jlong store_value, jlong* dest) { - _Atomic_move_long((volatile jlong*)&store_value, (volatile jlong*)dest); + _Atomic_move_long(reinterpret_cast(src), reinterpret_cast(&dest)); + return PrimitiveConversions::cast(dest); } -inline void Atomic::store(jlong store_value, volatile jlong* dest) { - _Atomic_move_long((volatile jlong*)&store_value, dest); +template<> +template +inline void Atomic::PlatformStore<8>::operator()(T store_value, + T volatile* dest) const { + STATIC_ASSERT(8 == sizeof(T)); + _Atomic_move_long(reinterpret_cast(&store_value), reinterpret_cast(dest)); } #endif // AMD64 --- old/src/hotspot/os_cpu/bsd_zero/atomic_bsd_zero.hpp 2017-10-03 14:31:24.030897866 +0200 +++ new/src/hotspot/os_cpu/bsd_zero/atomic_bsd_zero.hpp 2017-10-03 14:31:23.766897875 +0200 @@ -159,20 +159,6 @@ } #endif // ARM -inline void Atomic::store(jint store_value, volatile jint* dest) { -#if !defined(ARM) && !defined(M68K) - __sync_synchronize(); -#endif - *dest = store_value; -} - -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { -#if !defined(ARM) && !defined(M68K) - __sync_synchronize(); -#endif - *dest = store_value; -} - template struct Atomic::PlatformAdd : Atomic::AddAndFetch > @@ -275,18 +261,21 @@ return __sync_val_compare_and_swap(dest, compare_value, exchange_value); } -inline jlong Atomic::load(const volatile jlong* src) { +template<> +template +inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const { + STATIC_ASSERT(8 == sizeof(T)); volatile jlong dest; - os::atomic_copy64(src, &dest); - return dest; -} - -inline void Atomic::store(jlong store_value, jlong* dest) { - os::atomic_copy64((volatile jlong*)&store_value, (volatile jlong*)dest); + os::atomic_copy64(reinterpret_cast(src), reinterpret_cast(&dest)); + return PrimitiveConversions::cast(dest); } -inline void Atomic::store(jlong store_value, volatile jlong* dest) { - os::atomic_copy64((volatile jlong*)&store_value, dest); +template<> +template +inline void Atomic::PlatformStore<8>::operator()(T store_value, + T volatile* dest) const { + STATIC_ASSERT(8 == sizeof(T)); + os::atomic_copy64(reinterpret_cast(&store_value), reinterpret_cast(dest)); } #endif // OS_CPU_BSD_ZERO_VM_ATOMIC_BSD_ZERO_HPP --- old/src/hotspot/os_cpu/linux_aarch64/atomic_linux_aarch64.hpp 2017-10-03 14:31:24.954897834 +0200 +++ new/src/hotspot/os_cpu/linux_aarch64/atomic_linux_aarch64.hpp 2017-10-03 14:31:24.686897843 +0200 @@ -34,19 +34,6 @@ #define READ_MEM_BARRIER __atomic_thread_fence(__ATOMIC_ACQUIRE); #define WRITE_MEM_BARRIER __atomic_thread_fence(__ATOMIC_RELEASE); -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - - template struct Atomic::PlatformAdd : Atomic::AddAndFetch > @@ -84,9 +71,4 @@ } } -inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } - -inline jlong Atomic::load(const volatile jlong* src) { return *src; } - #endif // OS_CPU_LINUX_AARCH64_VM_ATOMIC_LINUX_AARCH64_HPP --- old/src/hotspot/os_cpu/linux_arm/atomic_linux_arm.hpp 2017-10-03 14:31:25.686897808 +0200 +++ new/src/hotspot/os_cpu/linux_arm/atomic_linux_arm.hpp 2017-10-03 14:31:25.438897817 +0200 @@ -44,39 +44,24 @@ * kernel source or kernel_user_helpers.txt in Linux Doc. */ -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - -inline jlong Atomic::load (const volatile jlong* src) { - assert(((intx)src & (sizeof(jlong)-1)) == 0, "Atomic load jlong mis-aligned"); -#ifdef AARCH64 - return *src; -#else - return (*os::atomic_load_long_func)(src); -#endif +#ifndef AARCH64 +template<> +template +inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const { + STATIC_ASSERT(8 == sizeof(T)); + return PrimitiveConversions::cast( + (*os::atomic_load_long_func)(reinterpret_cast(src))); } -inline void Atomic::store (jlong value, volatile jlong* dest) { - assert(((intx)dest & (sizeof(jlong)-1)) == 0, "Atomic store jlong mis-aligned"); -#ifdef AARCH64 - *dest = value; -#else - (*os::atomic_store_long_func)(value, dest); -#endif -} - -inline void Atomic::store (jlong value, jlong* dest) { - store(value, (volatile jlong*)dest); +template<> +template +inline void Atomic::PlatformStore<8>::operator()(T store_value, + T volatile* dest) const { + STATIC_ASSERT(8 == sizeof(T)); + (*os::atomic_store_long_func)( + PrimitiveConversions::cast(store_value), reinterpret_cast(dest)); } +#endif // As per atomic.hpp all read-modify-write operations have to provide two-way // barriers semantics. For AARCH64 we are using load-acquire-with-reservation and --- old/src/hotspot/os_cpu/linux_ppc/atomic_linux_ppc.hpp 2017-10-03 14:31:26.582897777 +0200 +++ new/src/hotspot/os_cpu/linux_ppc/atomic_linux_ppc.hpp 2017-10-03 14:31:26.322897786 +0200 @@ -32,22 +32,6 @@ // Implementation of class atomic -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - -inline jlong Atomic::load(const volatile jlong* src) { return *src; } - // // machine barrier instructions: // --- old/src/hotspot/os_cpu/linux_s390/atomic_linux_s390.hpp 2017-10-03 14:31:27.370897750 +0200 +++ new/src/hotspot/os_cpu/linux_s390/atomic_linux_s390.hpp 2017-10-03 14:31:27.142897758 +0200 @@ -53,20 +53,6 @@ // is an integer multiple of the data length. Furthermore, all stores are ordered: // a store which occurs conceptually before another store becomes visible to other CPUs // before the other store becomes visible. -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - //------------ // Atomic::add @@ -335,6 +321,4 @@ return old; } -inline jlong Atomic::load(const volatile jlong* src) { return *src; } - #endif // OS_CPU_LINUX_S390_VM_ATOMIC_LINUX_S390_INLINE_HPP --- old/src/hotspot/os_cpu/linux_sparc/atomic_linux_sparc.hpp 2017-10-03 14:31:28.154897722 +0200 +++ new/src/hotspot/os_cpu/linux_sparc/atomic_linux_sparc.hpp 2017-10-03 14:31:27.906897731 +0200 @@ -27,22 +27,6 @@ // Implementation of class atomic -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - -inline jlong Atomic::load(const volatile jlong* src) { return *src; } - template struct Atomic::PlatformAdd : Atomic::AddAndFetch > --- old/src/hotspot/os_cpu/linux_x86/atomic_linux_x86.hpp 2017-10-03 14:31:29.030897692 +0200 +++ new/src/hotspot/os_cpu/linux_x86/atomic_linux_x86.hpp 2017-10-03 14:31:28.762897701 +0200 @@ -27,19 +27,6 @@ // Implementation of class atomic -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - - template struct Atomic::PlatformAdd : Atomic::FetchAndAdd > @@ -102,8 +89,6 @@ } #ifdef AMD64 -inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } template<> template @@ -144,8 +129,6 @@ return exchange_value; } -inline jlong Atomic::load(const volatile jlong* src) { return *src; } - #else // !AMD64 extern "C" { @@ -164,18 +147,21 @@ return cmpxchg_using_helper(_Atomic_cmpxchg_long, exchange_value, dest, compare_value); } -inline jlong Atomic::load(const volatile jlong* src) { +template<> +template +inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const { + STATIC_ASSERT(8 == sizeof(T)); volatile jlong dest; - _Atomic_move_long(src, &dest); - return dest; + _Atomic_move_long(reinterpret_cast(src), reinterpret_cast(&dest)); + return PrimitiveConversions::cast(dest); } -inline void Atomic::store(jlong store_value, jlong* dest) { - _Atomic_move_long((volatile jlong*)&store_value, (volatile jlong*)dest); -} - -inline void Atomic::store(jlong store_value, volatile jlong* dest) { - _Atomic_move_long((volatile jlong*)&store_value, dest); +template<> +template +inline void Atomic::PlatformStore<8>::operator()(T store_value, + T volatile* dest) const { + STATIC_ASSERT(8 == sizeof(T)); + _Atomic_move_long(reinterpret_cast(&store_value), reinterpret_cast(dest)); } #endif // AMD64 --- old/src/hotspot/os_cpu/linux_zero/atomic_linux_zero.hpp 2017-10-03 14:31:29.822897664 +0200 +++ new/src/hotspot/os_cpu/linux_zero/atomic_linux_zero.hpp 2017-10-03 14:31:29.570897673 +0200 @@ -159,14 +159,6 @@ } #endif // ARM -inline void Atomic::store(jint store_value, volatile jint* dest) { - *dest = store_value; -} - -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { - *dest = store_value; -} - template struct Atomic::PlatformAdd : Atomic::AddAndFetch > @@ -269,18 +261,21 @@ return __sync_val_compare_and_swap(dest, compare_value, exchange_value); } -inline jlong Atomic::load(const volatile jlong* src) { +template<> +template +inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const { + STATIC_ASSERT(8 == sizeof(T)); volatile jlong dest; - os::atomic_copy64(src, &dest); - return dest; -} - -inline void Atomic::store(jlong store_value, jlong* dest) { - os::atomic_copy64((volatile jlong*)&store_value, (volatile jlong*)dest); + os::atomic_copy64(reinterpret_cast(src), reinterpret_cast(&dest)); + return PrimitiveConversions::cast(dest); } -inline void Atomic::store(jlong store_value, volatile jlong* dest) { - os::atomic_copy64((volatile jlong*)&store_value, dest); +template<> +template +inline void Atomic::PlatformStore<8>::operator()(T store_value, + T volatile* dest) const { + STATIC_ASSERT(8 == sizeof(T)); + os::atomic_copy64(reinterpret_cast(&store_value), reinterpret_cast(dest)); } #endif // OS_CPU_LINUX_ZERO_VM_ATOMIC_LINUX_ZERO_HPP --- old/src/hotspot/os_cpu/solaris_sparc/atomic_solaris_sparc.hpp 2017-10-03 14:31:30.726897633 +0200 +++ new/src/hotspot/os_cpu/solaris_sparc/atomic_solaris_sparc.hpp 2017-10-03 14:31:30.466897642 +0200 @@ -27,22 +27,6 @@ // Implementation of class atomic -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - -inline void Atomic::store(jlong store_value, jlong* dest) { *dest = store_value; } -inline void Atomic::store(jlong store_value, volatile jlong* dest) { *dest = store_value; } -inline jlong Atomic::load(const volatile jlong* src) { return *src; } - // Implement ADD using a CAS loop. template struct Atomic::PlatformAdd VALUE_OBJ_CLASS_SPEC { --- old/src/hotspot/os_cpu/solaris_x86/atomic_solaris_x86.hpp 2017-10-03 14:31:31.442897608 +0200 +++ new/src/hotspot/os_cpu/solaris_x86/atomic_solaris_x86.hpp 2017-10-03 14:31:31.246897615 +0200 @@ -25,20 +25,6 @@ #ifndef OS_CPU_SOLARIS_X86_VM_ATOMIC_SOLARIS_X86_HPP #define OS_CPU_SOLARIS_X86_VM_ATOMIC_SOLARIS_X86_HPP -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } - - -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - // For Sun Studio - implementation is in solaris_x86_64.il. extern "C" { @@ -151,8 +137,4 @@ PrimitiveConversions::cast(compare_value))); } -inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } -inline jlong Atomic::load(const volatile jlong* src) { return *src; } - #endif // OS_CPU_SOLARIS_X86_VM_ATOMIC_SOLARIS_X86_HPP --- old/src/hotspot/os_cpu/windows_x86/atomic_windows_x86.hpp 2017-10-03 14:31:32.306897578 +0200 +++ new/src/hotspot/os_cpu/windows_x86/atomic_windows_x86.hpp 2017-10-03 14:31:32.070897586 +0200 @@ -42,21 +42,6 @@ #pragma warning(disable: 4035) // Disables warnings reporting missing return statement -inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } - -inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } - -inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } -inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } -inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } - - -inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } -inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } - template struct Atomic::PlatformAdd : Atomic::AddAndFetch > @@ -66,9 +51,6 @@ }; #ifdef AMD64 -inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } -inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } - template<> template inline D Atomic::PlatformAdd<4>::add_and_fetch(I add_value, D volatile* dest) const { @@ -112,8 +94,6 @@ #undef DEFINE_STUB_CMPXCHG -inline jlong Atomic::load(const volatile jlong* src) { return *src; } - #else // !AMD64 template<> @@ -200,9 +180,12 @@ } } -inline jlong Atomic::load(const volatile jlong* src) { - volatile jlong dest; - volatile jlong* pdest = &dest; +template<> +template +inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const { + STATIC_ASSERT(8 == sizeof(T)); + volatile T dest; + volatile T* pdest = &dest; __asm { mov eax, src fild qword ptr [eax] @@ -212,8 +195,12 @@ return dest; } -inline void Atomic::store(jlong store_value, volatile jlong* dest) { - volatile jlong* src = &store_value; +template<> +template +inline void Atomic::PlatformStore<8>::operator()(T store_value, + T volatile* dest) const { + STATIC_ASSERT(8 == sizeof(T)); + volatile T* src = &store_value; __asm { mov eax, src fild qword ptr [eax] @@ -222,10 +209,6 @@ } } -inline void Atomic::store(jlong store_value, jlong* dest) { - Atomic::store(store_value, (volatile jlong*)dest); -} - #endif // AMD64 #pragma warning(default: 4035) // Enables warnings reporting missing return statement --- old/src/hotspot/share/runtime/atomic.hpp 2017-10-03 14:31:33.158897548 +0200 +++ new/src/hotspot/share/runtime/atomic.hpp 2017-10-03 14:31:32.926897556 +0200 @@ -64,24 +64,25 @@ // we can prove that a weaker form is sufficiently safe. // Atomically store to a location - inline static void store (jbyte store_value, jbyte* dest); - inline static void store (jshort store_value, jshort* dest); - inline static void store (jint store_value, jint* dest); - // See comment above about using jlong atomics on 32-bit platforms - inline static void store (jlong store_value, jlong* dest); - inline static void store_ptr(intptr_t store_value, intptr_t* dest); - inline static void store_ptr(void* store_value, void* dest); - - inline static void store (jbyte store_value, volatile jbyte* dest); - inline static void store (jshort store_value, volatile jshort* dest); - inline static void store (jint store_value, volatile jint* dest); - // See comment above about using jlong atomics on 32-bit platforms - inline static void store (jlong store_value, volatile jlong* dest); - inline static void store_ptr(intptr_t store_value, volatile intptr_t* dest); - inline static void store_ptr(void* store_value, volatile void* dest); + // The type T must be either a pointer type convertible to or equal + // to D, an integral/enum type equal to D, or a type equal to D that + // is primitive convertible using PrimitiveConversions. + template + inline static void store(T store_value, volatile D* dest); + + inline static void store_ptr(intptr_t store_value, volatile intptr_t* dest) { + Atomic::store(store_value, dest); + } - // See comment above about using jlong atomics on 32-bit platforms - inline static jlong load(const volatile jlong* src); + inline static void store_ptr(void* store_value, volatile void* dest) { + Atomic::store(store_value, reinterpret_cast(dest)); + } + + // Atomically load from a location + // The type T must be either a pointer type, an integral/enum type, + // or a type that is primitive convertible using PrimitiveConversions. + template + inline static T load(const volatile T* dest); // Atomically add to a location. Returns updated value. add*() provide: // add-value-to-dest @@ -174,6 +175,57 @@ // that is needed here. template struct IsPointerConvertible; + // Dispatch handler for store. Provides type-based validity + // checking and limited conversions around calls to the platform- + // specific implementation layer provided by PlatformOp. + template + struct StoreImpl; + + // Platform-specific implementation of store. Support for sizes + // of 1, 2, 4, and (if different) pointer size bytes are required. + // The class is a function object that must be default constructable, + // with these requirements: + // + // either: + // - dest is of type D*, an integral, enum or pointer type. + // - new_value are of type T, an integral, enum or pointer type D or + // pointer type convertible to D. + // or: + // - T and D are the same and are primitive convertible using PrimitiveConversions + // and either way: + // - platform_store is an object of type PlatformStore. + // + // Then + // platform_store(new_value, dest) + // must be a valid expression. + // + // The default implementation is a volatile store. If a platform + // requires more for e.g. 64 bit stores, a specialization is required + template struct PlatformStore; + + // Dispatch handler for load. Provides type-based validity + // checking and limited conversions around calls to the platform- + // specific implementation layer provided by PlatformOp. + template + struct LoadImpl; + + // Platform-specific implementation of load. Support for sizes of + // 1, 2, 4 bytes and (if different) pointer size bytes are required. + // The class is a function object that must be default + // constructable, with these requirements: + // + // - dest is of type T*, an integral, enum or pointer type, or + // T is convertible to a primitive type using PrimitiveConversions + // - platform_load is an object of type PlatformLoad. + // + // Then + // platform_load(src) + // must be a valid expression, returning a result convertible to T. + // + // The default implementation is a volatile load. If a platform + // requires more for e.g. 64 bit loads, a specialization is required + template struct PlatformLoad; + // Dispatch handler for add. Provides type-based validity checking // and limited conversions around calls to the platform-specific // implementation layer provided by PlatformAdd. @@ -344,6 +396,131 @@ static const bool value = (sizeof(yes) == sizeof(test(test_value))); }; +// Handle load for pointer, integral and enum types. +template +struct Atomic::LoadImpl< + T, + PlatformOp, + typename EnableIf::value || IsRegisteredEnum::value || IsPointer::value>::type> + VALUE_OBJ_CLASS_SPEC +{ + T operator()(T const volatile* dest) const { + // Forward to the platform handler for the size of T. + return PlatformOp()(dest); + } +}; + +// Handle load for types that have a translator. +// +// All the involved types must be identical. +// +// This translates the original call into a call on the decayed +// arguments, and returns the recovered result of that translated +// call. +template +struct Atomic::LoadImpl< + T, + PlatformOp, + typename EnableIf::value>::type> + VALUE_OBJ_CLASS_SPEC +{ + T operator()(T const volatile* dest) const { + typedef PrimitiveConversions::Translate Translator; + typedef typename Translator::Decayed Decayed; + STATIC_ASSERT(sizeof(T) == sizeof(Decayed)); + Decayed result = PlatformOp()(reinterpret_cast(dest)); + return Translator::recover(result); + } +}; + +// Default implementation of atomic load if a specific platform +// does not provide a specialization for a certain size class. +// For increased safety, the default implementation only allows +// load types that are pointer sized or smaller. If a platform still +// supports wide atomics, then it has to use specialization +// of Atomic::PlatformLoad for that wider size class. +template +struct Atomic::PlatformLoad VALUE_OBJ_CLASS_SPEC { + template + T operator()(T const volatile* dest) const { + STATIC_ASSERT(sizeof(T) <= sizeof(void*)); // wide atomics need specialization + return *dest; + } +}; + +// Handle store for integral and enum types. +// +// All the involved types must be identical. +template +struct Atomic::StoreImpl< + T, T, + PlatformOp, + typename EnableIf::value || IsRegisteredEnum::value>::type> + VALUE_OBJ_CLASS_SPEC +{ + void operator()(T new_value, T volatile* dest) const { + // Forward to the platform handler for the size of T. + PlatformOp()(new_value, dest); + } +}; + +// Handle store for pointer types. +// +// The new_value must be implicitly convertible to the +// destination's type; it must be type-correct to store the +// new_value in the destination. +template +struct Atomic::StoreImpl< + T*, D*, + PlatformOp, + typename EnableIf::value>::type> + VALUE_OBJ_CLASS_SPEC +{ + void operator()(T* new_value, D* volatile* dest) const { + // Allow derived to base conversion, and adding cv-qualifiers. + D* value = new_value; + PlatformOp()(value, dest); + } +}; + +// Handle store for types that have a translator. +// +// All the involved types must be identical. +// +// This translates the original call into a call on the decayed +// arguments. +template +struct Atomic::StoreImpl< + T, T, + PlatformOp, + typename EnableIf::value>::type> + VALUE_OBJ_CLASS_SPEC +{ + void operator()(T new_value, T volatile* dest) const { + typedef PrimitiveConversions::Translate Translator; + typedef typename Translator::Decayed Decayed; + STATIC_ASSERT(sizeof(T) == sizeof(Decayed)); + PlatformOp()(Translator::decay(new_value), + reinterpret_cast(dest)); + } +}; + +// Default implementation of atomic store if a specific platform +// does not provide a specialization for a certain size class. +// For increased safety, the default implementation only allows +// storing types that are pointer sized or smaller. If a platform still +// supports wide atomics, then it has to use specialization +// of Atomic::PlatformStore for that wider size class. +template +struct Atomic::PlatformStore VALUE_OBJ_CLASS_SPEC { + template + void operator()(T new_value, + T volatile* dest) const { + STATIC_ASSERT(sizeof(T) <= sizeof(void*)); // wide atomics need specialization + (void)const_cast(*dest = new_value); + } +}; + // Define FetchAndAdd and AddAndFetch helper classes before including // platform file, which may use these as base classes, requiring they // be complete. @@ -424,6 +601,16 @@ #error size_t is not WORD_SIZE, interesting platform, but missing implementation here #endif +template +inline T Atomic::load(const volatile T* dest) { + return LoadImpl >()(dest); +} + +template +inline void Atomic::store(T store_value, volatile D* dest) { + StoreImpl >()(store_value, dest); +} + template inline D Atomic::add(I add_value, D volatile* dest) { return AddImpl()(add_value, dest);