Skip to content

Commit dc3a0f5

Browse files
committedSep 30, 2020
8253183: Fragile memory barrier selection for some weak memory model platforms
Reviewed-by: dholmes, eosterlund, dcubed
1 parent 8331e63 commit dc3a0f5

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed
 

‎src/hotspot/share/gc/shared/taskqueue.inline.hpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ bool OverflowTaskQueue<E, F, N>::pop_overflow(E& t)
205205
template<class E, MEMFLAGS F, unsigned int N>
206206
bool GenericTaskQueue<E, F, N>::pop_global(E& t) {
207207
Age oldAge = age_relaxed();
208-
#ifndef CPU_MULTI_COPY_ATOMIC
208+
209209
// Architectures with non-multi-copy-atomic memory model require a
210210
// full fence here to guarantee that bottom is not older than age,
211211
// which is crucial for the correctness of the algorithm.
@@ -219,12 +219,8 @@ bool GenericTaskQueue<E, F, N>::pop_global(E& t) {
219219
// The requirement is that Thread3 must never read an older bottom
220220
// value than Thread2 after Thread3 has seen the age value from
221221
// Thread2.
222-
OrderAccess::fence();
223-
#else
224-
// Everyone else can make do with a LoadLoad barrier to keep reads
225-
// from age and bottom in order.
226-
OrderAccess::loadload();
227-
#endif
222+
OrderAccess::loadload_for_IRIW();
223+
228224
uint localBot = bottom_acquire();
229225
uint n_elems = clean_size(localBot, oldAge.top());
230226
if (n_elems == 0) {

‎src/hotspot/share/runtime/objectMonitor.cpp

+4-7
Original file line numberDiff line numberDiff line change
@@ -489,13 +489,10 @@ void ObjectMonitor::install_displaced_markword_in_object(const oop obj) {
489489

490490
// Separate loads in is_being_async_deflated(), which is almost always
491491
// called before this function, from the load of dmw/header below.
492-
if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
493-
// A non-multiple copy atomic (nMCA) machine needs a bigger
494-
// hammer to separate the loads before and the load below.
495-
OrderAccess::fence();
496-
} else {
497-
OrderAccess::loadload();
498-
}
492+
493+
// _contentions and dmw/header may get written by different threads.
494+
// Make sure to observe them in the same order when having several observers.
495+
OrderAccess::loadload_for_IRIW();
499496

500497
const oop l_object = object_peek();
501498
if (l_object == NULL) {

‎src/hotspot/share/runtime/orderAccess.hpp

+11
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,17 @@ class OrderAccess : public AllStatic {
243243
static void fence();
244244

245245
static void cross_modify_fence();
246+
247+
// Processors which are not multi-copy-atomic require a full fence
248+
// to enforce a globally consistent order of Independent Reads of
249+
// Independent Writes. Please use only for such patterns!
250+
static void loadload_for_IRIW() {
251+
#ifndef CPU_MULTI_COPY_ATOMIC
252+
fence();
253+
#else
254+
loadload();
255+
#endif
256+
}
246257
private:
247258
// This is a helper that invokes the StubRoutines::fence_entry()
248259
// routine if it exists, It should only be used by platforms that

‎src/hotspot/share/runtime/synchronizer.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -1105,13 +1105,11 @@ intptr_t ObjectSynchronizer::FastHashCode(Thread* self, oop obj) {
11051105

11061106
// Separate load of dmw/header above from the loads in
11071107
// is_being_async_deflated().
1108-
if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
1109-
// A non-multiple copy atomic (nMCA) machine needs a bigger
1110-
// hammer to separate the load above and the loads below.
1111-
OrderAccess::fence();
1112-
} else {
1113-
OrderAccess::loadload();
1114-
}
1108+
1109+
// dmw/header and _contentions may get written by different threads.
1110+
// Make sure to observe them in the same order when having several observers.
1111+
OrderAccess::loadload_for_IRIW();
1112+
11151113
if (monitor->is_being_async_deflated()) {
11161114
// But we can't safely use the hash if we detect that async
11171115
// deflation has occurred. So we attempt to restore the

0 commit comments

Comments
 (0)
Please sign in to comment.