11/*
2- * Copyright (c) 2008, 2019 , Oracle and/or its affiliates. All rights reserved.
2+ * Copyright (c) 2008, 2022 , Oracle and/or its affiliates. All rights reserved.
33 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44 *
55 * This code is free software; you can redistribute it and/or modify it
2525#ifndef OS_CPU_LINUX_ARM_ATOMIC_LINUX_ARM_HPP
2626#define OS_CPU_LINUX_ARM_ATOMIC_LINUX_ARM_HPP
2727
28+ #include " memory/allStatic.hpp"
2829#include " runtime/os.hpp"
2930#include " runtime/vm_version.hpp"
3031
3132// Implementation of class atomic
3233
34+ class ARMAtomicFuncs : AllStatic {
35+ public:
36+ typedef int64_t (*cmpxchg_long_func_t )(int64_t , int64_t , volatile int64_t *);
37+ typedef int64_t (*load_long_func_t )(const volatile int64_t *);
38+ typedef void (*store_long_func_t )(int64_t , volatile int64_t *);
39+ typedef int32_t (*atomic_add_func_t )(int32_t add_value, volatile int32_t *dest);
40+ typedef int32_t (*atomic_xchg_func_t )(int32_t exchange_value, volatile int32_t *dest);
41+ typedef int32_t (*cmpxchg_func_t )(int32_t , int32_t , volatile int32_t *);
42+
43+ static cmpxchg_long_func_t _cmpxchg_long_func;
44+ static load_long_func_t _load_long_func;
45+ static store_long_func_t _store_long_func;
46+ static atomic_add_func_t _add_func;
47+ static atomic_xchg_func_t _xchg_func;
48+ static cmpxchg_func_t _cmpxchg_func;
49+
50+ static int64_t cmpxchg_long_bootstrap (int64_t , int64_t , volatile int64_t *);
51+
52+ static int64_t load_long_bootstrap (const volatile int64_t *);
53+
54+ static void store_long_bootstrap (int64_t , volatile int64_t *);
55+
56+ static int32_t add_bootstrap (int32_t add_value, volatile int32_t *dest);
57+
58+ static int32_t xchg_bootstrap (int32_t exchange_value, volatile int32_t *dest);
59+
60+ static int32_t cmpxchg_bootstrap (int32_t compare_value,
61+ int32_t exchange_value,
62+ volatile int32_t *dest);
63+ };
64+
3365/*
3466 * Atomic long operations on 32-bit ARM
3567 * ARM v7 supports LDREXD/STREXD synchronization instructions so no problem.
@@ -49,15 +81,15 @@ template<typename T>
4981inline T Atomic::PlatformLoad<8 >::operator ()(T const volatile * src) const {
5082 STATIC_ASSERT (8 == sizeof (T));
5183 return PrimitiveConversions::cast<T>(
52- (*os::atomic_load_long_func )(reinterpret_cast <const volatile int64_t *>(src)));
84+ (*ARMAtomicFuncs::_load_long_func )(reinterpret_cast <const volatile int64_t *>(src)));
5385}
5486
5587template <>
5688template <typename T>
5789inline void Atomic::PlatformStore<8 >::operator ()(T volatile * dest,
5890 T store_value) const {
5991 STATIC_ASSERT (8 == sizeof (T));
60- (*os::atomic_store_long_func )(
92+ (*ARMAtomicFuncs::_store_long_func )(
6193 PrimitiveConversions::cast<int64_t >(store_value), reinterpret_cast <volatile int64_t *>(dest));
6294}
6395
@@ -83,7 +115,7 @@ inline D Atomic::PlatformAdd<4>::add_and_fetch(D volatile* dest, I add_value,
83115 atomic_memory_order order) const {
84116 STATIC_ASSERT (4 == sizeof (I));
85117 STATIC_ASSERT (4 == sizeof (D));
86- return add_using_helper<int32_t >(os::atomic_add_func , dest, add_value);
118+ return add_using_helper<int32_t >(ARMAtomicFuncs::_add_func , dest, add_value);
87119}
88120
89121
@@ -93,7 +125,7 @@ inline T Atomic::PlatformXchg<4>::operator()(T volatile* dest,
93125 T exchange_value,
94126 atomic_memory_order order) const {
95127 STATIC_ASSERT (4 == sizeof (T));
96- return xchg_using_helper<int32_t >(os::atomic_xchg_func , dest, exchange_value);
128+ return xchg_using_helper<int32_t >(ARMAtomicFuncs::_xchg_func , dest, exchange_value);
97129}
98130
99131
@@ -108,15 +140,15 @@ inline int32_t reorder_cmpxchg_func(int32_t exchange_value,
108140 int32_t volatile * dest,
109141 int32_t compare_value) {
110142 // Warning: Arguments are swapped to avoid moving them for kernel call
111- return (*os::atomic_cmpxchg_func )(compare_value, exchange_value, dest);
143+ return (*ARMAtomicFuncs::_cmpxchg_func )(compare_value, exchange_value, dest);
112144}
113145
114146inline int64_t reorder_cmpxchg_long_func (int64_t exchange_value,
115147 int64_t volatile * dest,
116148 int64_t compare_value) {
117149 assert (VM_Version::supports_cx8 (), " Atomic compare and exchange int64_t not supported on this architecture!" );
118150 // Warning: Arguments are swapped to avoid moving them for kernel call
119- return (*os::atomic_cmpxchg_long_func )(compare_value, exchange_value, dest);
151+ return (*ARMAtomicFuncs::_cmpxchg_long_func )(compare_value, exchange_value, dest);
120152}
121153
122154
0 commit comments