Skip to content

Commit

Permalink
8270894: Use acquire semantics in ObjectSynchronizer::read_stable_mark()
Browse files Browse the repository at this point in the history
Reviewed-by: dholmes
  • Loading branch information
rkennke committed Jul 23, 2021
1 parent ea182b5 commit f226190
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/hotspot/share/oops/oop.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class oopDesc {

public:
inline markWord mark() const;
inline markWord mark_acquire() const;
inline markWord* mark_addr() const;

inline void set_mark(markWord m);
Expand Down
5 changes: 5 additions & 0 deletions src/hotspot/share/oops/oop.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ markWord oopDesc::mark() const {
return markWord(v);
}

markWord oopDesc::mark_acquire() const {
uintptr_t v = HeapAccess<MO_ACQUIRE>::load_at(as_oop(), mark_offset_in_bytes());
return markWord(v);
}

markWord* oopDesc::mark_addr() const {
return (markWord*) &_mark;
}
Expand Down
10 changes: 5 additions & 5 deletions src/hotspot/share/runtime/synchronizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -681,14 +681,14 @@ struct SharedGlobals {
static SharedGlobals GVars;

static markWord read_stable_mark(oop obj) {
markWord mark = obj->mark();
markWord mark = obj->mark_acquire();
if (!mark.is_being_inflated()) {
return mark; // normal fast-path return
}

int its = 0;
for (;;) {
markWord mark = obj->mark();
markWord mark = obj->mark_acquire();
if (!mark.is_being_inflated()) {
return mark; // normal fast-path return
}
Expand Down Expand Up @@ -722,7 +722,7 @@ static markWord read_stable_mark(oop obj) {
int YieldThenBlock = 0;
assert(ix >= 0 && ix < NINFLATIONLOCKS, "invariant");
gInflationLocks[ix]->lock();
while (obj->mark() == markWord::INFLATING()) {
while (obj->mark_acquire() == markWord::INFLATING()) {
// Beware: naked_yield() is advisory and has almost no effect on some platforms
// so we periodically call current->_ParkEvent->park(1).
// We use a mixed spin/yield/block mechanism.
Expand Down Expand Up @@ -1102,7 +1102,7 @@ static void post_monitor_inflate_event(EventJavaMonitorInflate* event,

// Fast path code shared by multiple functions
void ObjectSynchronizer::inflate_helper(oop obj) {
markWord mark = obj->mark();
markWord mark = obj->mark_acquire();
if (mark.has_monitor()) {
ObjectMonitor* monitor = mark.monitor();
markWord dmw = monitor->header();
Expand All @@ -1117,7 +1117,7 @@ ObjectMonitor* ObjectSynchronizer::inflate(Thread* current, oop object,
EventJavaMonitorInflate event;

for (;;) {
const markWord mark = object->mark();
const markWord mark = object->mark_acquire();

// The mark can be in one of the following states:
// * Inflated - just return
Expand Down

1 comment on commit f226190

@openjdk-notifier
Copy link

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.