From bbf52e0e4cb76b4c6425e7d1266dcdbb4df556ea Mon Sep 17 00:00:00 2001 From: Stefan Karlsson Date: Fri, 17 Nov 2023 08:38:21 +0000 Subject: [PATCH] 8319897: Move StackWatermark handling out of LockStack::contains Reviewed-by: eosterlund, dholmes, dcubed --- src/hotspot/share/runtime/lockStack.inline.hpp | 14 ++++---------- src/hotspot/share/runtime/threads.cpp | 7 +++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/hotspot/share/runtime/lockStack.inline.hpp b/src/hotspot/share/runtime/lockStack.inline.hpp index 9dd04d8f7fe..b36be2f72de 100644 --- a/src/hotspot/share/runtime/lockStack.inline.hpp +++ b/src/hotspot/share/runtime/lockStack.inline.hpp @@ -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) { diff --git a/src/hotspot/share/runtime/threads.cpp b/src/hotspot/share/runtime/threads.cpp index b07f6e21d20..b6ef42cd1d2 100644 --- a/src/hotspot/share/runtime/threads.cpp +++ b/src/hotspot/share/runtime/threads.cpp @@ -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" @@ -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) { + watermark->start_processing(); + } + if (q->lock_stack().contains(obj)) { return q; }