author | coleenp |
Thu, 10 Jan 2019 15:13:51 -0500 (2019-01-10) | |
changeset 53244 | 9807daeb47c4 |
parent 50029 | ea0a16ba6ac0 |
child 59248 | e92153ed8bdc |
permissions | -rw-r--r-- |
4013 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, Oracle and/or its affiliates. All rights reserved. |
28468
b8e9517bf6b9
8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents:
25715
diff
changeset
|
3 |
* Copyright 2007, 2008, 2011, 2015, Red Hat, Inc. |
4013 | 4 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
5 |
* |
|
6 |
* This code is free software; you can redistribute it and/or modify it |
|
7 |
* under the terms of the GNU General Public License version 2 only, as |
|
8 |
* published by the Free Software Foundation. |
|
9 |
* |
|
10 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
11 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
12 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
13 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
14 |
* accompanied this code). |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License version |
|
17 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
18 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
19 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4013
diff
changeset
|
20 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4013
diff
changeset
|
21 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
4013
diff
changeset
|
22 |
* questions. |
4013 | 23 |
* |
24 |
*/ |
|
25 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
26 |
#ifndef OS_CPU_LINUX_ZERO_ATOMIC_LINUX_ZERO_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
27 |
#define OS_CPU_LINUX_ZERO_ATOMIC_LINUX_ZERO_HPP |
7397 | 28 |
|
29 |
#include "runtime/os.hpp" |
|
30 |
||
4013 | 31 |
// Implementation of class atomic |
32 |
||
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
33 |
template<size_t byte_size> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
34 |
struct Atomic::PlatformAdd |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
35 |
: Atomic::AddAndFetch<Atomic::PlatformAdd<byte_size> > |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
36 |
{ |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
37 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48479
diff
changeset
|
38 |
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
|
39 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
40 |
|
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
41 |
template<> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
42 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48479
diff
changeset
|
43 |
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:
48479
diff
changeset
|
44 |
atomic_memory_order order) const { |
47091
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
45 |
STATIC_ASSERT(4 == sizeof(I)); |
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
46 |
STATIC_ASSERT(4 == sizeof(D)); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
47 |
|
4013 | 48 |
return __sync_add_and_fetch(dest, add_value); |
49 |
} |
|
50 |
||
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
51 |
template<> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
52 |
template<typename I, typename D> |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48479
diff
changeset
|
53 |
inline D Atomic::PlatformAdd<8>::add_and_fetch(I add_value, D volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48479
diff
changeset
|
54 |
atomic_memory_order order) const { |
47091
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
55 |
STATIC_ASSERT(8 == sizeof(I)); |
4cc46bb5057b
8186855: Multiple platforms broken after 8186476: Generalize Atomic::add with templates
glaubitz
parents:
46993
diff
changeset
|
56 |
STATIC_ASSERT(8 == sizeof(D)); |
4013 | 57 |
return __sync_add_and_fetch(dest, add_value); |
58 |
} |
|
59 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
60 |
template<> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
61 |
template<typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
62 |
inline T Atomic::PlatformXchg<4>::operator()(T exchange_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48479
diff
changeset
|
63 |
T volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48479
diff
changeset
|
64 |
atomic_memory_order order) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
65 |
STATIC_ASSERT(4 == sizeof(T)); |
4013 | 66 |
// __sync_lock_test_and_set is a bizarrely named atomic exchange |
67 |
// operation. Note that some platforms only support this with the |
|
68 |
// limitation that the only valid value to store is the immediate |
|
69 |
// constant 1. There is a test for this in JNI_CreateJavaVM(). |
|
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
70 |
T result = __sync_lock_test_and_set (dest, exchange_value); |
28468
b8e9517bf6b9
8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents:
25715
diff
changeset
|
71 |
// All atomic operations are expected to be full memory barriers |
b8e9517bf6b9
8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents:
25715
diff
changeset
|
72 |
// (see atomic.hpp). However, __sync_lock_test_and_set is not |
b8e9517bf6b9
8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents:
25715
diff
changeset
|
73 |
// a full memory barrier, but an acquire barrier. Hence, this added |
b8e9517bf6b9
8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents:
25715
diff
changeset
|
74 |
// barrier. |
b8e9517bf6b9
8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents:
25715
diff
changeset
|
75 |
__sync_synchronize(); |
b8e9517bf6b9
8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents:
25715
diff
changeset
|
76 |
return result; |
4013 | 77 |
} |
78 |
||
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
79 |
template<> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
80 |
template<typename T> |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
81 |
inline T Atomic::PlatformXchg<8>::operator()(T exchange_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48479
diff
changeset
|
82 |
T volatile* dest, |
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48479
diff
changeset
|
83 |
atomic_memory_order order) const { |
47578
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
84 |
STATIC_ASSERT(8 == sizeof(T)); |
09c41c4913d9
8187977: Generalize Atomic::xchg to use templates
eosterlund
parents:
47552
diff
changeset
|
85 |
T result = __sync_lock_test_and_set (dest, exchange_value); |
28468
b8e9517bf6b9
8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents:
25715
diff
changeset
|
86 |
__sync_synchronize(); |
b8e9517bf6b9
8067331: Zero: Atomic::xchg and Atomic::xchg_ptr need full memory barrier
sgehwolf
parents:
25715
diff
changeset
|
87 |
return result; |
4013 | 88 |
} |
89 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
90 |
// No direct support for cmpxchg of bytes; emulate using int. |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
91 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
92 |
struct Atomic::PlatformCmpxchg<1> : Atomic::CmpxchgByteUsingInt {}; |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
93 |
|
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
94 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
95 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
96 |
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
97 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
98 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48479
diff
changeset
|
99 |
atomic_memory_order order) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
100 |
STATIC_ASSERT(4 == sizeof(T)); |
4013 | 101 |
return __sync_val_compare_and_swap(dest, compare_value, exchange_value); |
102 |
} |
|
103 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
104 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
105 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
106 |
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
107 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
108 |
T compare_value, |
50029
ea0a16ba6ac0
8202080: Introduce ordering semantics for Atomic::add and other RMW atomics
mdoerr
parents:
48479
diff
changeset
|
109 |
atomic_memory_order order) const { |
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
110 |
STATIC_ASSERT(8 == sizeof(T)); |
4013 | 111 |
return __sync_val_compare_and_swap(dest, compare_value, exchange_value); |
112 |
} |
|
113 |
||
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
114 |
template<> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
115 |
template<typename T> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
116 |
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
|
117 |
STATIC_ASSERT(8 == sizeof(T)); |
48468 | 118 |
volatile int64_t dest; |
119 |
os::atomic_copy64(reinterpret_cast<const volatile int64_t*>(src), reinterpret_cast<volatile int64_t*>(&dest)); |
|
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
120 |
return PrimitiveConversions::cast<T>(dest); |
8326
752682831ac6
7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents:
7397
diff
changeset
|
121 |
} |
752682831ac6
7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents:
7397
diff
changeset
|
122 |
|
47593
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
123 |
template<> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
124 |
template<typename T> |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
125 |
inline void Atomic::PlatformStore<8>::operator()(T store_value, |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
126 |
T volatile* dest) const { |
2d56326b98f0
8188224: Generalize Atomic::load/store to use templates
eosterlund
parents:
47578
diff
changeset
|
127 |
STATIC_ASSERT(8 == sizeof(T)); |
48468 | 128 |
os::atomic_copy64(reinterpret_cast<const volatile int64_t*>(&store_value), reinterpret_cast<volatile int64_t*>(dest)); |
8326
752682831ac6
7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents:
7397
diff
changeset
|
129 |
} |
752682831ac6
7018673: Zero: 6953144, 6990754 and 7009756 made some changes which broke Zero
twisti
parents:
7397
diff
changeset
|
130 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50029
diff
changeset
|
131 |
#endif // OS_CPU_LINUX_ZERO_ATOMIC_LINUX_ZERO_HPP |