8319897: Move StackWatermark handling out of LockStack::contains

Reviewed-by: eosterlund, dholmes, dcubed
This commit is contained in:
Stefan Karlsson 2023-11-17 08:38:21 +00:00
parent 129c4708b4
commit bbf52e0e4c
2 changed files with 11 additions and 10 deletions

View File

@ -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) {

View File

@ -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;
}