Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
8253183: Fragile memory barrier selection for some weak memory model …
…platforms

Reviewed-by: dholmes, eosterlund, dcubed
  • Loading branch information
TheRealMDoerr committed Sep 30, 2020
1 parent 8331e63 commit dc3a0f5
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 21 deletions.
10 changes: 3 additions & 7 deletions src/hotspot/share/gc/shared/taskqueue.inline.hpp
Expand Up @@ -205,7 +205,7 @@ bool OverflowTaskQueue<E, F, N>::pop_overflow(E& t)
template<class E, MEMFLAGS F, unsigned int N>
bool GenericTaskQueue<E, F, N>::pop_global(E& t) {
Age oldAge = age_relaxed();
#ifndef CPU_MULTI_COPY_ATOMIC

// Architectures with non-multi-copy-atomic memory model require a
// full fence here to guarantee that bottom is not older than age,
// which is crucial for the correctness of the algorithm.
Expand All @@ -219,12 +219,8 @@ bool GenericTaskQueue<E, F, N>::pop_global(E& t) {
// The requirement is that Thread3 must never read an older bottom
// value than Thread2 after Thread3 has seen the age value from
// Thread2.
OrderAccess::fence();
#else
// Everyone else can make do with a LoadLoad barrier to keep reads
// from age and bottom in order.
OrderAccess::loadload();
#endif
OrderAccess::loadload_for_IRIW();

uint localBot = bottom_acquire();
uint n_elems = clean_size(localBot, oldAge.top());
if (n_elems == 0) {
Expand Down
11 changes: 4 additions & 7 deletions src/hotspot/share/runtime/objectMonitor.cpp
Expand Up @@ -489,13 +489,10 @@ void ObjectMonitor::install_displaced_markword_in_object(const oop obj) {

// Separate loads in is_being_async_deflated(), which is almost always
// called before this function, from the load of dmw/header below.
if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
// A non-multiple copy atomic (nMCA) machine needs a bigger
// hammer to separate the loads before and the load below.
OrderAccess::fence();
} else {
OrderAccess::loadload();
}

// _contentions and dmw/header may get written by different threads.
// Make sure to observe them in the same order when having several observers.
OrderAccess::loadload_for_IRIW();

const oop l_object = object_peek();
if (l_object == NULL) {
Expand Down
11 changes: 11 additions & 0 deletions src/hotspot/share/runtime/orderAccess.hpp
Expand Up @@ -243,6 +243,17 @@ class OrderAccess : public AllStatic {
static void fence();

static void cross_modify_fence();

// Processors which are not multi-copy-atomic require a full fence
// to enforce a globally consistent order of Independent Reads of
// Independent Writes. Please use only for such patterns!
static void loadload_for_IRIW() {
#ifndef CPU_MULTI_COPY_ATOMIC
fence();
#else
loadload();
#endif
}
private:
// This is a helper that invokes the StubRoutines::fence_entry()
// routine if it exists, It should only be used by platforms that
Expand Down
12 changes: 5 additions & 7 deletions src/hotspot/share/runtime/synchronizer.cpp
Expand Up @@ -1105,13 +1105,11 @@ intptr_t ObjectSynchronizer::FastHashCode(Thread* self, oop obj) {

// Separate load of dmw/header above from the loads in
// is_being_async_deflated().
if (support_IRIW_for_not_multiple_copy_atomic_cpu) {
// A non-multiple copy atomic (nMCA) machine needs a bigger
// hammer to separate the load above and the loads below.
OrderAccess::fence();
} else {
OrderAccess::loadload();
}

// dmw/header and _contentions may get written by different threads.
// Make sure to observe them in the same order when having several observers.
OrderAccess::loadload_for_IRIW();

if (monitor->is_being_async_deflated()) {
// But we can't safely use the hash if we detect that async
// deflation has occurred. So we attempt to restore the
Expand Down

1 comment on commit dc3a0f5

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented on dc3a0f5 Sep 30, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.