Path: blob/master/src/hotspot/os_cpu/windows_aarch64/atomic_windows_aarch64.hpp
40930 views
/*1* Copyright (c) 2020, Microsoft Corporation. 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_WINDOWS_AARCH64_ATOMIC_WINDOWS_AARCH64_HPP25#define OS_CPU_WINDOWS_AARCH64_ATOMIC_WINDOWS_AARCH64_HPP2627#include <intrin.h>28#include "runtime/os.hpp"29#include "runtime/vm_version.hpp"303132// As per atomic.hpp all read-modify-write operations have to provide two-way33// barriers semantics. The memory_order parameter is ignored - we always provide34// the strongest/most-conservative ordering35//36// For AARCH64 we add explicit barriers in the stubs.3738template<size_t byte_size>39struct Atomic::PlatformAdd {40template<typename D, typename I>41D add_and_fetch(D volatile* dest, I add_value, atomic_memory_order order) const;4243template<typename D, typename I>44D fetch_and_add(D volatile* dest, I add_value, atomic_memory_order order) const {45return add_and_fetch(dest, add_value, order) - add_value;46}47};4849// The Interlocked* APIs only take long and will not accept __int32. That is50// acceptable on Windows, since long is a 32-bits integer type.5152#define DEFINE_INTRINSIC_ADD(IntrinsicName, IntrinsicType) \53template<> \54template<typename D, typename I> \55inline D Atomic::PlatformAdd<sizeof(IntrinsicType)>::add_and_fetch(D volatile* dest, \56I add_value, \57atomic_memory_order order) const { \58STATIC_ASSERT(sizeof(IntrinsicType) == sizeof(D)); \59return PrimitiveConversions::cast<D>( \60IntrinsicName(reinterpret_cast<IntrinsicType volatile *>(dest), \61PrimitiveConversions::cast<IntrinsicType>(add_value))); \62}6364DEFINE_INTRINSIC_ADD(InterlockedAdd, long)65DEFINE_INTRINSIC_ADD(InterlockedAdd64, __int64)6667#undef DEFINE_INTRINSIC_ADD6869#define DEFINE_INTRINSIC_XCHG(IntrinsicName, IntrinsicType) \70template<> \71template<typename T> \72inline T Atomic::PlatformXchg<sizeof(IntrinsicType)>::operator()(T volatile* dest, \73T exchange_value, \74atomic_memory_order order) const { \75STATIC_ASSERT(sizeof(IntrinsicType) == sizeof(T)); \76return PrimitiveConversions::cast<T>( \77IntrinsicName(reinterpret_cast<IntrinsicType volatile *>(dest), \78PrimitiveConversions::cast<IntrinsicType>(exchange_value))); \79}8081DEFINE_INTRINSIC_XCHG(InterlockedExchange, long)82DEFINE_INTRINSIC_XCHG(InterlockedExchange64, __int64)8384#undef DEFINE_INTRINSIC_XCHG8586// Note: the order of the parameters is different between87// Atomic::PlatformCmpxchg<*>::operator() and the88// InterlockedCompareExchange* API.8990#define DEFINE_INTRINSIC_CMPXCHG(IntrinsicName, IntrinsicType) \91template<> \92template<typename T> \93inline T Atomic::PlatformCmpxchg<sizeof(IntrinsicType)>::operator()(T volatile* dest, \94T compare_value, \95T exchange_value, \96atomic_memory_order order) const { \97STATIC_ASSERT(sizeof(IntrinsicType) == sizeof(T)); \98return PrimitiveConversions::cast<T>( \99IntrinsicName(reinterpret_cast<IntrinsicType volatile *>(dest), \100PrimitiveConversions::cast<IntrinsicType>(exchange_value), \101PrimitiveConversions::cast<IntrinsicType>(compare_value))); \102}103104DEFINE_INTRINSIC_CMPXCHG(_InterlockedCompareExchange8, char) // Use the intrinsic as InterlockedCompareExchange8 does not exist105DEFINE_INTRINSIC_CMPXCHG(InterlockedCompareExchange, long)106DEFINE_INTRINSIC_CMPXCHG(InterlockedCompareExchange64, __int64)107108#undef DEFINE_INTRINSIC_CMPXCHG109110#endif // OS_CPU_WINDOWS_AARCH64_ATOMIC_WINDOWS_AARCH64_HPP111112113