Skip to content

Commit

Permalink
8319897: Move StackWatermark handling out of LockStack::contains
Browse files Browse the repository at this point in the history
Reviewed-by: shade
Backport-of: bbf52e0e4cb76b4c6425e7d1266dcdbb4df556ea
  • Loading branch information
rkennke committed Apr 9, 2024
1 parent 17daee8 commit 6f943a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 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 != NULL) {
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
8 changes: 7 additions & 1 deletion src/hotspot/share/runtime/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
#include "runtime/serviceThread.hpp"
#include "runtime/sharedRuntime.hpp"
#include "runtime/stackFrameStream.inline.hpp"
#include "runtime/stackWatermarkSet.hpp"
#include "runtime/stackWatermarkSet.inline.hpp"
#include "runtime/statSampler.hpp"
#include "runtime/task.hpp"
#include "runtime/thread.inline.hpp"
Expand Down Expand Up @@ -3791,6 +3791,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");
DO_JAVA_THREADS(t_list, q) {
// 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

0 comments on commit 6f943a0

Please sign in to comment.