Path: blob/master/src/hotspot/os_cpu/linux_arm/atomic_linux_arm.hpp
40931 views
/*1* Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef OS_CPU_LINUX_ARM_ATOMIC_LINUX_ARM_HPP25#define OS_CPU_LINUX_ARM_ATOMIC_LINUX_ARM_HPP2627#include "runtime/os.hpp"28#include "runtime/vm_version.hpp"2930// Implementation of class atomic3132/*33* Atomic long operations on 32-bit ARM34* ARM v7 supports LDREXD/STREXD synchronization instructions so no problem.35* ARM < v7 does not have explicit 64 atomic load/store capability.36* However, gcc emits LDRD/STRD instructions on v5te and LDM/STM on v5t37* when loading/storing 64 bits.38* For non-MP machines (which is all we support for ARM < v7)39* under current Linux distros these instructions appear atomic.40* See section A3.5.3 of ARM Architecture Reference Manual for ARM v7.41* Also, for cmpxchg64, if ARM < v7 we check for cmpxchg64 support in the42* Linux kernel using _kuser_helper_version. See entry-armv.S in the Linux43* kernel source or kernel_user_helpers.txt in Linux Doc.44*/4546template<>47template<typename T>48inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const {49STATIC_ASSERT(8 == sizeof(T));50return PrimitiveConversions::cast<T>(51(*os::atomic_load_long_func)(reinterpret_cast<const volatile int64_t*>(src)));52}5354template<>55template<typename T>56inline void Atomic::PlatformStore<8>::operator()(T volatile* dest,57T store_value) const {58STATIC_ASSERT(8 == sizeof(T));59(*os::atomic_store_long_func)(60PrimitiveConversions::cast<int64_t>(store_value), reinterpret_cast<volatile int64_t*>(dest));61}6263// As per atomic.hpp all read-modify-write operations have to provide two-way64// barriers semantics.65//66// For ARMv7 we add explicit barriers in the stubs.6768template<size_t byte_size>69struct Atomic::PlatformAdd {70template<typename D, typename I>71D add_and_fetch(D volatile* dest, I add_value, atomic_memory_order order) const;7273template<typename D, typename I>74D fetch_and_add(D volatile* dest, I add_value, atomic_memory_order order) const {75return add_and_fetch(dest, add_value, order) - add_value;76}77};7879template<>80template<typename D, typename I>81inline D Atomic::PlatformAdd<4>::add_and_fetch(D volatile* dest, I add_value,82atomic_memory_order order) const {83STATIC_ASSERT(4 == sizeof(I));84STATIC_ASSERT(4 == sizeof(D));85return add_using_helper<int32_t>(os::atomic_add_func, dest, add_value);86}878889template<>90template<typename T>91inline T Atomic::PlatformXchg<4>::operator()(T volatile* dest,92T exchange_value,93atomic_memory_order order) const {94STATIC_ASSERT(4 == sizeof(T));95return xchg_using_helper<int32_t>(os::atomic_xchg_func, dest, exchange_value);96}979899// The memory_order parameter is ignored - we always provide the strongest/most-conservative ordering100101// No direct support for cmpxchg of bytes; emulate using int.102template<>103struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};104105106inline int32_t reorder_cmpxchg_func(int32_t exchange_value,107int32_t volatile* dest,108int32_t compare_value) {109// Warning: Arguments are swapped to avoid moving them for kernel call110return (*os::atomic_cmpxchg_func)(compare_value, exchange_value, dest);111}112113inline int64_t reorder_cmpxchg_long_func(int64_t exchange_value,114int64_t volatile* dest,115int64_t compare_value) {116assert(VM_Version::supports_cx8(), "Atomic compare and exchange int64_t not supported on this architecture!");117// Warning: Arguments are swapped to avoid moving them for kernel call118return (*os::atomic_cmpxchg_long_func)(compare_value, exchange_value, dest);119}120121122template<>123template<typename T>124inline T Atomic::PlatformCmpxchg<4>::operator()(T volatile* dest,125T compare_value,126T exchange_value,127atomic_memory_order order) const {128STATIC_ASSERT(4 == sizeof(T));129return cmpxchg_using_helper<int32_t>(reorder_cmpxchg_func, dest, compare_value, exchange_value);130}131132template<>133template<typename T>134inline T Atomic::PlatformCmpxchg<8>::operator()(T volatile* dest,135T compare_value,136T exchange_value,137atomic_memory_order order) const {138STATIC_ASSERT(8 == sizeof(T));139return cmpxchg_using_helper<int64_t>(reorder_cmpxchg_long_func, dest, compare_value, exchange_value);140}141142#endif // OS_CPU_LINUX_ARM_ATOMIC_LINUX_ARM_HPP143144145