author | pliden |
Thu, 07 Nov 2019 15:48:43 +0100 | |
changeset 58965 | 86c8b22945a1 |
parent 54323 | 846bc643f4ef |
child 59247 | 56bf71d64d51 |
permissions | -rw-r--r-- |
10565 | 1 |
/* |
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50429
diff
changeset
|
2 |
* Copyright (c) 2003, 2019, 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 |
||
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50429
diff
changeset
|
25 |
#ifndef OS_CPU_BSD_X86_ORDERACCESS_BSD_X86_HPP |
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50429
diff
changeset
|
26 |
#define OS_CPU_BSD_X86_ORDERACCESS_BSD_X86_HPP |
10565 | 27 |
|
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
49364
diff
changeset
|
28 |
// Included in orderAccess.hpp header file. |
10565 | 29 |
|
29456
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
30 |
// Compiler version last used for testing: clang 5.1 |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
31 |
// Please update this information when this file changes |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
32 |
|
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
33 |
// A compiler barrier, forcing the C++ compiler to invalidate all memory assumptions |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
34 |
static inline void compiler_barrier() { |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
35 |
__asm__ volatile ("" : : : "memory"); |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
36 |
} |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
37 |
|
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
38 |
// x86 is TSO and hence only needs a fence for storeload |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
39 |
// However, a compiler barrier is still needed to prevent reordering |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
40 |
// between volatile and non-volatile memory accesses. |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
41 |
|
10565 | 42 |
// Implementation of class OrderAccess. |
43 |
||
29456
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
44 |
inline void OrderAccess::loadload() { compiler_barrier(); } |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
45 |
inline void OrderAccess::storestore() { compiler_barrier(); } |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
46 |
inline void OrderAccess::loadstore() { compiler_barrier(); } |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
47 |
inline void OrderAccess::storeload() { fence(); } |
10565 | 48 |
|
29456
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
49 |
inline void OrderAccess::acquire() { compiler_barrier(); } |
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
50 |
inline void OrderAccess::release() { compiler_barrier(); } |
10565 | 51 |
|
52 |
inline void OrderAccess::fence() { |
|
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
49364
diff
changeset
|
53 |
// always use locked addl since mfence is sometimes expensive |
10565 | 54 |
#ifdef AMD64 |
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
49364
diff
changeset
|
55 |
__asm__ volatile ("lock; addl $0,0(%%rsp)" : : : "cc", "memory"); |
10565 | 56 |
#else |
50429
83aec1d357d4
8204301: Make OrderAccess functions available to hpp rather than inline.hpp files
coleenp
parents:
49364
diff
changeset
|
57 |
__asm__ volatile ("lock; addl $0,0(%%esp)" : : : "cc", "memory"); |
10565 | 58 |
#endif |
29456
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
59 |
compiler_barrier(); |
10565 | 60 |
} |
61 |
||
54323 | 62 |
inline void OrderAccess::cross_modify_fence() { |
63 |
int idx = 0; |
|
64 |
__asm__ volatile ("cpuid " : "+a" (idx) : : "ebx", "ecx", "edx", "memory"); |
|
65 |
} |
|
66 |
||
29456
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
67 |
template<> |
47609
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
68 |
struct OrderAccess::PlatformOrderedStore<1, RELEASE_X_FENCE> |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
69 |
{ |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
70 |
template <typename T> |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
71 |
void operator()(T v, volatile T* p) const { |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
72 |
__asm__ volatile ( "xchgb (%2),%0" |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
73 |
: "=q" (v) |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
74 |
: "0" (v), "r" (p) |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
75 |
: "memory"); |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
76 |
} |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
77 |
}; |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
78 |
|
29456
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
79 |
template<> |
47609
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
80 |
struct OrderAccess::PlatformOrderedStore<2, RELEASE_X_FENCE> |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
81 |
{ |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
82 |
template <typename T> |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
83 |
void operator()(T v, volatile T* p) const { |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
84 |
__asm__ volatile ( "xchgw (%2),%0" |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
85 |
: "=r" (v) |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
86 |
: "0" (v), "r" (p) |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
87 |
: "memory"); |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
88 |
} |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
89 |
}; |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
90 |
|
29456
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
91 |
template<> |
47609
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
92 |
struct OrderAccess::PlatformOrderedStore<4, RELEASE_X_FENCE> |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
93 |
{ |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
94 |
template <typename T> |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
95 |
void operator()(T v, volatile T* p) const { |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
96 |
__asm__ volatile ( "xchgl (%2),%0" |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
97 |
: "=r" (v) |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
98 |
: "0" (v), "r" (p) |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
99 |
: "memory"); |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
100 |
} |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
101 |
}; |
10565 | 102 |
|
103 |
#ifdef AMD64 |
|
29456
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
104 |
template<> |
47609
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
105 |
struct OrderAccess::PlatformOrderedStore<8, RELEASE_X_FENCE> |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
106 |
{ |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
107 |
template <typename T> |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
108 |
void operator()(T v, volatile T* p) const { |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
109 |
__asm__ volatile ( "xchgq (%2), %0" |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
110 |
: "=r" (v) |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
111 |
: "0" (v), "r" (p) |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
112 |
: "memory"); |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
113 |
} |
a1f68e415b48
8188813: Generalize OrderAccess to use templates
eosterlund
parents:
47216
diff
changeset
|
114 |
}; |
29456
cc1c5203e60d
7143664: Clean up OrderAccess implementations and usage
dholmes
parents:
25715
diff
changeset
|
115 |
#endif // AMD64 |
10565 | 116 |
|
53244
9807daeb47c4
8216167: Update include guards to reflect correct directories
coleenp
parents:
50429
diff
changeset
|
117 |
#endif // OS_CPU_BSD_X86_ORDERACCESS_BSD_X86_HPP |