Skip to content


8319897: Move StackWatermark handling out of LockStack::contains
Browse files Browse the repository at this point in the history
Reviewed-by: eosterlund, dholmes, dcubed
  • Loading branch information
stefank committed Nov 17, 2023
1 parent 129c470 commit bbf52e0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/hotspot/share/runtime/lockStack.inline.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,10 @@ inline void LockStack::remove(oop o) {

inline bool LockStack::contains(oop o) const {
if (!SafepointSynchronize::is_at_safepoint() && !is_owning_thread()) {
// When a foreign thread inspects this thread's lock-stack, it may see
// bad references here when a concurrent collector has not gotten
// to processing the lock-stack, yet. Call StackWaterMark::start_processing()
// to ensure that all references are valid.
StackWatermark* watermark = StackWatermarkSet::get(get_thread(), StackWatermarkKind::gc);
if (watermark != nullptr) {

// Can't poke around in thread oops without having started stack watermark processing.
assert(StackWatermarkSet::processing_started(get_thread()), "Processing must have started!");

int end = to_index(_top);
for (int i = end - 1; i >= 0; i--) {
if (_base[i] == o) {
Expand Down
7 changes: 7 additions & 0 deletions src/hotspot/share/runtime/threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
#include "runtime/safepointVerifiers.hpp"
#include "runtime/serviceThread.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stackWatermarkSet.inline.hpp"
#include "runtime/statSampler.hpp"
#include "runtime/stubCodeGenerator.hpp"
#include "runtime/thread.inline.hpp"
Expand Down Expand Up @@ -1230,6 +1231,12 @@ JavaThread *Threads::owning_thread_from_monitor_owner(ThreadsList * t_list,
JavaThread* Threads::owning_thread_from_object(ThreadsList * t_list, oop obj) {
assert(LockingMode == LM_LIGHTWEIGHT, "Only with new lightweight locking");
for (JavaThread* q : *t_list) {
// Need to start processing before accessing oops in the thread.
StackWatermark* watermark = StackWatermarkSet::get(q, StackWatermarkKind::gc);
if (watermark != nullptr) {

if (q->lock_stack().contains(obj)) {
return q;
Expand Down

1 comment on commit bbf52e0

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.