author | erikj |
Tue, 12 Sep 2017 19:03:39 +0200 | |
changeset 47216 | 71c04702a3d5 |
parent 46993 | hotspot/src/os_cpu/bsd_x86/vm/atomic_bsd_x86.hpp@dd0f91c85ffc |
child 47552 | 8a3599d60996 |
permissions | -rw-r--r-- |
10565 | 1 |
/* |
46414 | 2 |
* Copyright (c) 1999, 2017, Oracle and/or its affiliates. All rights reserved. |
10565 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
25 |
#ifndef OS_CPU_BSD_X86_VM_ATOMIC_BSD_X86_HPP |
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
26 |
#define OS_CPU_BSD_X86_VM_ATOMIC_BSD_X86_HPP |
10565 | 27 |
|
28 |
// Implementation of class atomic |
|
29 |
||
30 |
inline void Atomic::store (jbyte store_value, jbyte* dest) { *dest = store_value; } |
|
31 |
inline void Atomic::store (jshort store_value, jshort* dest) { *dest = store_value; } |
|
32 |
inline void Atomic::store (jint store_value, jint* dest) { *dest = store_value; } |
|
33 |
inline void Atomic::store_ptr(intptr_t store_value, intptr_t* dest) { *dest = store_value; } |
|
34 |
inline void Atomic::store_ptr(void* store_value, void* dest) { *(void**)dest = store_value; } |
|
35 |
||
36 |
inline void Atomic::store (jbyte store_value, volatile jbyte* dest) { *dest = store_value; } |
|
37 |
inline void Atomic::store (jshort store_value, volatile jshort* dest) { *dest = store_value; } |
|
38 |
inline void Atomic::store (jint store_value, volatile jint* dest) { *dest = store_value; } |
|
39 |
inline void Atomic::store_ptr(intptr_t store_value, volatile intptr_t* dest) { *dest = store_value; } |
|
40 |
inline void Atomic::store_ptr(void* store_value, volatile void* dest) { *(void* volatile *)dest = store_value; } |
|
41 |
||
42 |
||
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
43 |
template<size_t byte_size> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
44 |
struct Atomic::PlatformAdd |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
45 |
: Atomic::FetchAndAdd<Atomic::PlatformAdd<byte_size> > |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
46 |
{ |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
47 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
48 |
D fetch_and_add(I add_value, D volatile* dest) const; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
49 |
}; |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
50 |
|
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> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
53 |
inline D Atomic::PlatformAdd<4>::fetch_and_add(I add_value, D volatile* dest) const { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
54 |
STATIC_ASSERT(4 == sizeof(I)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
55 |
STATIC_ASSERT(4 == sizeof(D)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
56 |
D old_value; |
46414 | 57 |
__asm__ volatile ( "lock xaddl %0,(%2)" |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
58 |
: "=r" (old_value) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
59 |
: "0" (add_value), "r" (dest) |
10565 | 60 |
: "cc", "memory"); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
61 |
return old_value; |
10565 | 62 |
} |
63 |
||
64 |
inline void Atomic::inc (volatile jint* dest) { |
|
46414 | 65 |
__asm__ volatile ( "lock addl $1,(%0)" : |
66 |
: "r" (dest) : "cc", "memory"); |
|
10565 | 67 |
} |
68 |
||
69 |
inline void Atomic::inc_ptr(volatile void* dest) { |
|
70 |
inc_ptr((volatile intptr_t*)dest); |
|
71 |
} |
|
72 |
||
73 |
inline void Atomic::dec (volatile jint* dest) { |
|
46414 | 74 |
__asm__ volatile ( "lock subl $1,(%0)" : |
75 |
: "r" (dest) : "cc", "memory"); |
|
10565 | 76 |
} |
77 |
||
78 |
inline void Atomic::dec_ptr(volatile void* dest) { |
|
79 |
dec_ptr((volatile intptr_t*)dest); |
|
80 |
} |
|
81 |
||
82 |
inline jint Atomic::xchg (jint exchange_value, volatile jint* dest) { |
|
83 |
__asm__ volatile ( "xchgl (%2),%0" |
|
84 |
: "=r" (exchange_value) |
|
85 |
: "0" (exchange_value), "r" (dest) |
|
86 |
: "memory"); |
|
87 |
return exchange_value; |
|
88 |
} |
|
89 |
||
90 |
inline void* Atomic::xchg_ptr(void* exchange_value, volatile void* dest) { |
|
91 |
return (void*)xchg_ptr((intptr_t)exchange_value, (volatile intptr_t*)dest); |
|
92 |
} |
|
93 |
||
46958
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<1>::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, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
99 |
cmpxchg_memory_order /* order */) const { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
100 |
STATIC_ASSERT(1 == sizeof(T)); |
46414 | 101 |
__asm__ volatile ( "lock cmpxchgb %1,(%3)" |
27691
733f189ad1f7
8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents:
25715
diff
changeset
|
102 |
: "=a" (exchange_value) |
46414 | 103 |
: "q" (exchange_value), "a" (compare_value), "r" (dest) |
27691
733f189ad1f7
8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents:
25715
diff
changeset
|
104 |
: "cc", "memory"); |
733f189ad1f7
8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents:
25715
diff
changeset
|
105 |
return exchange_value; |
733f189ad1f7
8058255: Native jbyte Atomic::cmpxchg for supported x86 platforms
jwilhelm
parents:
25715
diff
changeset
|
106 |
} |
10565 | 107 |
|
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
108 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
109 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
110 |
inline T Atomic::PlatformCmpxchg<4>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
111 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
112 |
T compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
113 |
cmpxchg_memory_order /* order */) const { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
114 |
STATIC_ASSERT(4 == sizeof(T)); |
46414 | 115 |
__asm__ volatile ( "lock cmpxchgl %1,(%3)" |
10565 | 116 |
: "=a" (exchange_value) |
46414 | 117 |
: "r" (exchange_value), "a" (compare_value), "r" (dest) |
10565 | 118 |
: "cc", "memory"); |
119 |
return exchange_value; |
|
120 |
} |
|
121 |
||
122 |
#ifdef AMD64 |
|
123 |
inline void Atomic::store (jlong store_value, jlong* dest) { *dest = store_value; } |
|
124 |
inline void Atomic::store (jlong store_value, volatile jlong* dest) { *dest = store_value; } |
|
125 |
||
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
126 |
template<> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
127 |
template<typename I, typename D> |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
128 |
inline D Atomic::PlatformAdd<8>::fetch_and_add(I add_value, D volatile* dest) const { |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
129 |
STATIC_ASSERT(8 == sizeof(I)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
130 |
STATIC_ASSERT(8 == sizeof(D)); |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
131 |
D old_value; |
46414 | 132 |
__asm__ __volatile__ ( "lock xaddq %0,(%2)" |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
133 |
: "=r" (old_value) |
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
134 |
: "0" (add_value), "r" (dest) |
10565 | 135 |
: "cc", "memory"); |
46993
dd0f91c85ffc
8186476: Generalize Atomic::add with templates
eosterlund
parents:
46958
diff
changeset
|
136 |
return old_value; |
10565 | 137 |
} |
138 |
||
139 |
inline void Atomic::inc_ptr(volatile intptr_t* dest) { |
|
46414 | 140 |
__asm__ __volatile__ ( "lock addq $1,(%0)" |
10565 | 141 |
: |
46414 | 142 |
: "r" (dest) |
10565 | 143 |
: "cc", "memory"); |
144 |
} |
|
145 |
||
146 |
inline void Atomic::dec_ptr(volatile intptr_t* dest) { |
|
46414 | 147 |
__asm__ __volatile__ ( "lock subq $1,(%0)" |
10565 | 148 |
: |
46414 | 149 |
: "r" (dest) |
10565 | 150 |
: "cc", "memory"); |
151 |
} |
|
152 |
||
153 |
inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) { |
|
154 |
__asm__ __volatile__ ("xchgq (%2),%0" |
|
155 |
: "=r" (exchange_value) |
|
156 |
: "0" (exchange_value), "r" (dest) |
|
157 |
: "memory"); |
|
158 |
return exchange_value; |
|
159 |
} |
|
160 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
161 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
162 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
163 |
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
164 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
165 |
T compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
166 |
cmpxchg_memory_order /* order */) const { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
167 |
STATIC_ASSERT(8 == sizeof(T)); |
46414 | 168 |
__asm__ __volatile__ ( "lock cmpxchgq %1,(%3)" |
10565 | 169 |
: "=a" (exchange_value) |
46414 | 170 |
: "r" (exchange_value), "a" (compare_value), "r" (dest) |
10565 | 171 |
: "cc", "memory"); |
172 |
return exchange_value; |
|
173 |
} |
|
174 |
||
46523
cbcc0ebaa044
8166651: OrderAccess::load_acquire &etc should have const parameters
kbarrett
parents:
46414
diff
changeset
|
175 |
inline jlong Atomic::load(const volatile jlong* src) { return *src; } |
10565 | 176 |
|
177 |
#else // !AMD64 |
|
178 |
||
179 |
inline void Atomic::inc_ptr(volatile intptr_t* dest) { |
|
180 |
inc((volatile jint*)dest); |
|
181 |
} |
|
182 |
||
183 |
inline void Atomic::dec_ptr(volatile intptr_t* dest) { |
|
184 |
dec((volatile jint*)dest); |
|
185 |
} |
|
186 |
||
187 |
inline intptr_t Atomic::xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest) { |
|
188 |
return (intptr_t)xchg((jint)exchange_value, (volatile jint*)dest); |
|
189 |
} |
|
190 |
||
191 |
extern "C" { |
|
192 |
// defined in bsd_x86.s |
|
193 |
jlong _Atomic_cmpxchg_long(jlong, volatile jlong*, jlong, bool); |
|
46523
cbcc0ebaa044
8166651: OrderAccess::load_acquire &etc should have const parameters
kbarrett
parents:
46414
diff
changeset
|
194 |
void _Atomic_move_long(const volatile jlong* src, volatile jlong* dst); |
10565 | 195 |
} |
196 |
||
46958
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
197 |
template<> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
198 |
template<typename T> |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
199 |
inline T Atomic::PlatformCmpxchg<8>::operator()(T exchange_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
200 |
T volatile* dest, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
201 |
T compare_value, |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
202 |
cmpxchg_memory_order order) const { |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
203 |
STATIC_ASSERT(8 == sizeof(T)); |
a13bd8c6b7a2
8186166: Generalize Atomic::cmpxchg with templates
eosterlund
parents:
46523
diff
changeset
|
204 |
return cmpxchg_using_helper<jlong>(_Atomic_cmpxchg_long, exchange_value, dest, compare_value); |
10565 | 205 |
} |
206 |
||
46523
cbcc0ebaa044
8166651: OrderAccess::load_acquire &etc should have const parameters
kbarrett
parents:
46414
diff
changeset
|
207 |
inline jlong Atomic::load(const volatile jlong* src) { |
10565 | 208 |
volatile jlong dest; |
209 |
_Atomic_move_long(src, &dest); |
|
210 |
return dest; |
|
211 |
} |
|
212 |
||
213 |
inline void Atomic::store(jlong store_value, jlong* dest) { |
|
214 |
_Atomic_move_long((volatile jlong*)&store_value, (volatile jlong*)dest); |
|
215 |
} |
|
216 |
||
217 |
inline void Atomic::store(jlong store_value, volatile jlong* dest) { |
|
218 |
_Atomic_move_long((volatile jlong*)&store_value, dest); |
|
219 |
} |
|
220 |
||
221 |
#endif // AMD64 |
|
222 |
||
40655
9f644073d3a0
8157907: Incorrect inclusion of atomic.hpp instead of atomic.inline.hpp
dholmes
parents:
39404
diff
changeset
|
223 |
#endif // OS_CPU_BSD_X86_VM_ATOMIC_BSD_X86_HPP |