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: phh, rkennke
Backport-of: f22619032df2cf45664f110c71ddf509a5128900
  • Loading branch information
shipilev committed Jul 4, 2023
1 parent 00c6470 commit 8d6c17d
Show file tree
Hide file tree
Showing 3 changed files with 10 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
4 changes: 4 additions & 0 deletions src/hotspot/share/oops/oop.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ markWord oopDesc::mark() const {
return Atomic::load(&_mark);
}

markWord oopDesc::mark_acquire() const {
return Atomic::load_acquire(&_mark);
}

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 @@ -733,14 +733,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 @@ -774,7 +774,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 @@ -1232,7 +1232,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 @@ -1247,7 +1247,7 @@ ObjectMonitor* ObjectSynchronizer::inflate(Thread* current, oop object,
EventJavaMonitorInflate event;

for (;;) {
const markWord mark = object->mark();
const markWord mark = object->mark_acquire();
assert(!mark.has_bias_pattern(), "invariant");

// The mark can be in one of the following states:
Expand Down

1 comment on commit 8d6c17d

@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.