src/hotspot/os_cpu/linux_arm/atomic_linux_arm.hpp
author stefank
Mon, 25 Nov 2019 12:30:24 +0100
changeset 59248 e92153ed8bdc
parent 59122 5d73255c2d52
child 59249 29b0d0b61615
permissions -rw-r--r--
8234736: Harmonize parameter order in Atomic - store Reviewed-by: rehn, dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
     1
/*
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52351
diff changeset
     2
 * Copyright (c) 2008, 2019, Oracle and/or its affiliates. All rights reserved.
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
     4
 *
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
     7
 * published by the Free Software Foundation.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
     8
 *
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    13
 * accompanied this code).
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    14
 *
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    18
 *
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    21
 * questions.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    22
 *
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    23
 */
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    24
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52351
diff changeset
    25
#ifndef OS_CPU_LINUX_ARM_ATOMIC_LINUX_ARM_HPP
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52351
diff changeset
    26
#define OS_CPU_LINUX_ARM_ATOMIC_LINUX_ARM_HPP
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    27
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    28
#include "runtime/os.hpp"
59122
5d73255c2d52 8233787: Break cycle in vm_version* includes
lucy
parents: 53244
diff changeset
    29
#include "runtime/vm_version.hpp"
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    30
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    31
// Implementation of class atomic
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    32
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    33
/*
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    34
 * Atomic long operations on 32-bit ARM
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    35
 * ARM v7 supports LDREXD/STREXD synchronization instructions so no problem.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    36
 * ARM < v7 does not have explicit 64 atomic load/store capability.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    37
 * However, gcc emits LDRD/STRD instructions on v5te and LDM/STM on v5t
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    38
 * when loading/storing 64 bits.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    39
 * For non-MP machines (which is all we support for ARM < v7)
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    40
 * under current Linux distros these instructions appear atomic.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    41
 * See section A3.5.3 of ARM Architecture Reference Manual for ARM v7.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    42
 * Also, for cmpxchg64, if ARM < v7 we check for cmpxchg64 support in the
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    43
 * Linux kernel using _kuser_helper_version. See entry-armv.S in the Linux
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    44
 * kernel source or kernel_user_helpers.txt in Linux Doc.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    45
 */
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    46
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    47
template<>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    48
template<typename T>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    49
inline T Atomic::PlatformLoad<8>::operator()(T const volatile* src) const {
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    50
  STATIC_ASSERT(8 == sizeof(T));
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    51
  return PrimitiveConversions::cast<T>(
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
    52
    (*os::atomic_load_long_func)(reinterpret_cast<const volatile int64_t*>(src)));
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    53
}
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    54
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    55
template<>
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    56
template<typename T>
59248
e92153ed8bdc 8234736: Harmonize parameter order in Atomic - store
stefank
parents: 59122
diff changeset
    57
inline void Atomic::PlatformStore<8>::operator()(T volatile* dest,
e92153ed8bdc 8234736: Harmonize parameter order in Atomic - store
stefank
parents: 59122
diff changeset
    58
                                                 T store_value) const {
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    59
  STATIC_ASSERT(8 == sizeof(T));
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    60
  (*os::atomic_store_long_func)(
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
    61
    PrimitiveConversions::cast<int64_t>(store_value), reinterpret_cast<volatile int64_t*>(dest));
47593
2d56326b98f0 8188224: Generalize Atomic::load/store to use templates
eosterlund
parents: 47578
diff changeset
    62
}
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    63
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    64
// As per atomic.hpp all read-modify-write operations have to provide two-way
52351
0ecb4e520110 8209093: JEP 340: One AArch64 Port, Not Two
bobv
parents: 50029
diff changeset
    65
// barriers semantics.
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    66
//
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    67
// For ARMv7 we add explicit barriers in the stubs.
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    68
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    69
template<size_t byte_size>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    70
struct Atomic::PlatformAdd
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    71
  : Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> >
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    72
{
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    73
  template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    74
  D add_and_fetch(I add_value, D volatile* dest, atomic_memory_order order) const;
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    75
};
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    76
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    77
template<>
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    78
template<typename I, typename D>
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    79
inline D Atomic::PlatformAdd<4>::add_and_fetch(I add_value, D volatile* dest,
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    80
                                               atomic_memory_order order) const {
46993
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    81
  STATIC_ASSERT(4 == sizeof(I));
dd0f91c85ffc 8186476: Generalize Atomic::add with templates
eosterlund
parents: 46958
diff changeset
    82
  STATIC_ASSERT(4 == sizeof(D));
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
    83
  return add_using_helper<int32_t>(os::atomic_add_func, add_value, dest);
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    84
}
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    85
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    86
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    87
template<>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    88
template<typename T>
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    89
inline T Atomic::PlatformXchg<4>::operator()(T exchange_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    90
                                             T volatile* dest,
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
    91
                                             atomic_memory_order order) const {
47578
09c41c4913d9 8187977: Generalize Atomic::xchg to use templates
eosterlund
parents: 47552
diff changeset
    92
  STATIC_ASSERT(4 == sizeof(T));
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
    93
  return xchg_using_helper<int32_t>(os::atomic_xchg_func, exchange_value, dest);
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    94
}
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    95
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    96
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    97
// The memory_order parameter is ignored - we always provide the strongest/most-conservative ordering
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
    98
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
    99
// No direct support for cmpxchg of bytes; emulate using int.
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   100
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   101
struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {};
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   102
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   103
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   104
inline int32_t reorder_cmpxchg_func(int32_t exchange_value,
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   105
                                    int32_t volatile* dest,
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   106
                                    int32_t compare_value) {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   107
  // Warning:  Arguments are swapped to avoid moving them for kernel call
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   108
  return (*os::atomic_cmpxchg_func)(compare_value, exchange_value, dest);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   109
}
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   110
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   111
inline int64_t reorder_cmpxchg_long_func(int64_t exchange_value,
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   112
                                         int64_t volatile* dest,
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   113
                                         int64_t compare_value) {
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   114
  assert(VM_Version::supports_cx8(), "Atomic compare and exchange int64_t not supported on this architecture!");
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   115
  // Warning:  Arguments are swapped to avoid moving them for kernel call
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   116
  return (*os::atomic_cmpxchg_long_func)(compare_value, exchange_value, dest);
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   117
}
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   118
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   119
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   120
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   121
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   122
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   123
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   124
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   125
                                                atomic_memory_order order) const {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   126
  STATIC_ASSERT(4 == sizeof(T));
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   127
  return cmpxchg_using_helper<int32_t>(reorder_cmpxchg_func, exchange_value, dest, compare_value);
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
   128
}
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
   129
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   130
template<>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   131
template<typename T>
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   132
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   133
                                                T volatile* dest,
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   134
                                                T compare_value,
50029
ea0a16ba6ac0 8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents: 48468
diff changeset
   135
                                                atomic_memory_order order) const {
46958
a13bd8c6b7a2 8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents: 46523
diff changeset
   136
  STATIC_ASSERT(8 == sizeof(T));
48468
7cc7de9bf4a4 8186903: Remove j-types from Atomic
coleenp
parents: 47593
diff changeset
   137
  return cmpxchg_using_helper<int64_t>(reorder_cmpxchg_long_func, exchange_value, dest, compare_value);
42664
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
   138
}
29142a56c193 8168503: JEP 297: Unified arm32/arm64 Port
bobv
parents:
diff changeset
   139
53244
9807daeb47c4 8216167: Update include guards to reflect correct directories
coleenp
parents: 52351
diff changeset
   140
#endif // OS_CPU_LINUX_ARM_ATOMIC_LINUX_ARM_HPP