Skip to content

Commit

Permalink
8319897: Move StackWatermark handling out of LockStack::contains
Browse files Browse the repository at this point in the history
Backport-of: bbf52e0e4cb76b4c6425e7d1266dcdbb4df556ea
  • Loading branch information
shipilev committed Dec 19, 2023
1 parent b8a0d9f commit f55a91a
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 {
verify("pre-contains");
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) {
watermark->start_processing();
}
}

// 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 @@ -80,6 +80,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 @@ -1229,6 +1230,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) {
watermark->start_processing();
}

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

1 comment on commit f55a91a

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