Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/hotspot/share/runtime/objectMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2439,6 +2439,16 @@ bool ObjectMonitor::try_spin(JavaThread* current) {
if (!has_successor()) {
set_successor(current);
}
// Dekker/Lamport duality with exit(): ST _succ; MEMBAR; LD _owner.
// The exiter's side (release_clear_owner + storeload) is in exit().
// Here on the spinner's side, we need a StoreLoad barrier between
// setting _succ and reading _owner to prevent the CPU from reordering
// the _owner load before the _succ store. On ARM64 with MSVC
// /volatile:iso, Atomic::store/load are plain STR/LDR with no
Copy link
Member

Choose a reason for hiding this comment

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

This comment should probably be reworded to remove the statement that /volatile:iso is in use if we intend to switch to /volatile:ms

// barrier, so without this fence the Dekker protocol is broken and
// the exiter may not see our successor designation while we may not
Copy link
Member

Choose a reason for hiding this comment

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

Is this fence still needed now that Atomic::store/load are no longer plain STR/LDRs?

Copy link
Member

Choose a reason for hiding this comment

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

Is this fence still needed now that Atomic::store/load are no longer plain STR/LDRs?

One reason this might not be needed is the explanation in https://github.com/openjdk/jdk/blob/9d4fbbe36d85d71ce850bb83bbfb1ce1d3e8dd23/src/hotspot/share/runtime/objectMonitor.cpp#L1586 - "the try_set_owner_from() below uses cmpxchg() so we get the fence down there." (this would be line 2492 in the right view of this file)

// see its lock release — leading to missed wakeups and starvation.
OrderAccess::storeload();
int64_t prv = NO_OWNER;

// There are three ways to exit the following loop:
Expand Down Expand Up @@ -2514,6 +2524,8 @@ bool ObjectMonitor::try_spin(JavaThread* current) {

if (!has_successor()) {
set_successor(current);
// See Dekker/storeload comment before the loop.
OrderAccess::storeload();
}
}

Expand Down
Loading