Skip to content

Commit

Permalink
Skip copying displaced header.
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRealMDoerr committed Oct 13, 2023
1 parent 089a082 commit fb11241
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
30 changes: 16 additions & 14 deletions src/hotspot/share/runtime/basicLock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,19 +66,21 @@ void BasicLock::move_to(oop obj, BasicLock* dest) {
// is small (given the support for inflated fast-path locking in the fast_lock, etc)
// we'll leave that optimization for another time.

if (LockingMode == LM_LEGACY && displaced_header().is_neutral()) {
// The object is locked and the resulting ObjectMonitor* will also be
// locked so it can't be async deflated until ownership is dropped.
ObjectSynchronizer::inflate_helper(obj);
// WARNING: We cannot put a check here, because the inflation
// will not update the displaced header. Once BasicLock is inflated,
// no one should ever look at its content.
} else {
// Typically the displaced header will be 0 (recursive stack lock) or
// unused_mark. Naively we'd like to assert that the displaced mark
// value is either 0, neutral, or 3. But with the advent of the
// store-before-CAS avoidance in fast_lock/compiler_lock_object
// we can find any flavor mark in the displaced mark.
if (LockingMode == LM_LEGACY) {
if (displaced_header().is_neutral()) {
// The object is locked and the resulting ObjectMonitor* will also be
// locked so it can't be async deflated until ownership is dropped.
ObjectSynchronizer::inflate_helper(obj);
// WARNING: We cannot put a check here, because the inflation
// will not update the displaced header. Once BasicLock is inflated,
// no one should ever look at its content.
} else {
// Typically the displaced header will be 0 (recursive stack lock) or
// unused_mark. Naively we'd like to assert that the displaced mark
// value is either 0, neutral, or 3. But with the advent of the
// store-before-CAS avoidance in fast_lock/compiler_lock_object
// we can find any flavor mark in the displaced mark.
}
dest->set_displaced_header(displaced_header());
}
dest->set_displaced_header(displaced_header());
}
21 changes: 12 additions & 9 deletions src/hotspot/share/runtime/sharedRuntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3257,16 +3257,19 @@ JRT_LEAF(intptr_t*, SharedRuntime::OSR_migration_begin( JavaThread *current) )
kptr2 = fr.next_monitor_in_interpreter_frame(kptr2) ) {
if (kptr2->obj() != nullptr) { // Avoid 'holes' in the monitor array
BasicLock *lock = kptr2->lock();
// Inflate so the object's header no longer refers to the BasicLock.
if (LockingMode == LM_LEGACY && lock->displaced_header().is_unlocked()) {
// The object is locked and the resulting ObjectMonitor* will also be
// locked so it can't be async deflated until ownership is dropped.
// See the big comment in basicLock.cpp: BasicLock::move_to().
ObjectSynchronizer::inflate_helper(kptr2->obj());
if (LockingMode == LM_LEGACY) {
// Inflate so the object's header no longer refers to the BasicLock.
if (lock->displaced_header().is_unlocked()) {
// The object is locked and the resulting ObjectMonitor* will also be
// locked so it can't be async deflated until ownership is dropped.
// See the big comment in basicLock.cpp: BasicLock::move_to().
ObjectSynchronizer::inflate_helper(kptr2->obj());
}
// Now the displaced header is free to move because the
// object's header no longer refers to it.
buf[i] = (intptr_t)lock->displaced_header().value();
}
// Now the displaced header is free to move because the
// object's header no longer refers to it.
buf[i++] = (intptr_t)lock->displaced_header().value();
i++;
buf[i++] = cast_from_oop<intptr_t>(kptr2->obj());
}
}
Expand Down

0 comments on commit fb11241

Please sign in to comment.