Skip to content

Commit 263983d

Browse files
author
Fredrik Bredberg
committed
8298733: Reconsider monitors_on_stack assert
Reviewed-by: pchilanomate, coleenp
1 parent 27faf45 commit 263983d

File tree

2 files changed

+42
-20
lines changed

2 files changed

+42
-20
lines changed

src/hotspot/share/runtime/continuationFreezeThaw.cpp

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -565,10 +565,50 @@ void FreezeBase::copy_to_chunk(intptr_t* from, intptr_t* to, int size) {
565565
#endif
566566
}
567567

568+
static void assert_frames_in_continuation_are_safe(JavaThread* thread) {
569+
#ifdef ASSERT
570+
StackWatermark* watermark = StackWatermarkSet::get(thread, StackWatermarkKind::gc);
571+
if (watermark == nullptr) {
572+
return;
573+
}
574+
ContinuationEntry* ce = thread->last_continuation();
575+
RegisterMap map(thread,
576+
RegisterMap::UpdateMap::include,
577+
RegisterMap::ProcessFrames::skip,
578+
RegisterMap::WalkContinuation::skip);
579+
map.set_include_argument_oops(false);
580+
for (frame f = thread->last_frame(); Continuation::is_frame_in_continuation(ce, f); f = f.sender(&map)) {
581+
watermark->assert_is_frame_safe(f);
582+
}
583+
#endif // ASSERT
584+
}
585+
586+
#ifdef ASSERT
587+
static bool monitors_on_stack(JavaThread* thread) {
588+
assert_frames_in_continuation_are_safe(thread);
589+
ContinuationEntry* ce = thread->last_continuation();
590+
RegisterMap map(thread,
591+
RegisterMap::UpdateMap::include,
592+
RegisterMap::ProcessFrames::skip,
593+
RegisterMap::WalkContinuation::skip);
594+
map.set_include_argument_oops(false);
595+
for (frame f = thread->last_frame(); Continuation::is_frame_in_continuation(ce, f); f = f.sender(&map)) {
596+
if ((f.is_interpreted_frame() && ContinuationHelper::InterpretedFrame::is_owning_locks(f)) ||
597+
(f.is_compiled_frame() && ContinuationHelper::CompiledFrame::is_owning_locks(map.thread(), &map, f)) ||
598+
(f.is_native_frame() && ContinuationHelper::NativeFrame::is_owning_locks(map.thread(), f))) {
599+
return true;
600+
}
601+
}
602+
return false;
603+
}
604+
#endif // ASSERT
605+
568606
// Called _after_ the last possible safepoint during the freeze operation (chunk allocation)
569607
void FreezeBase::unwind_frames() {
570608
ContinuationEntry* entry = _cont.entry();
571609
entry->flush_stack_processing(_thread);
610+
assert_frames_in_continuation_are_safe(_thread);
611+
assert(LockingMode != LM_LEGACY || !monitors_on_stack(_thread), "unexpected monitors on stack");
572612
set_anchor_to_entry(_thread, entry);
573613
}
574614

@@ -1621,23 +1661,6 @@ static void jvmti_mount_end(JavaThread* current, ContinuationWrapper& cont, fram
16211661
#endif // INCLUDE_JVMTI
16221662

16231663
#ifdef ASSERT
1624-
static bool monitors_on_stack(JavaThread* thread) {
1625-
ContinuationEntry* ce = thread->last_continuation();
1626-
RegisterMap map(thread,
1627-
RegisterMap::UpdateMap::include,
1628-
RegisterMap::ProcessFrames::include,
1629-
RegisterMap::WalkContinuation::skip);
1630-
map.set_include_argument_oops(false);
1631-
for (frame f = thread->last_frame(); Continuation::is_frame_in_continuation(ce, f); f = f.sender(&map)) {
1632-
if ((f.is_interpreted_frame() && ContinuationHelper::InterpretedFrame::is_owning_locks(f)) ||
1633-
(f.is_compiled_frame() && ContinuationHelper::CompiledFrame::is_owning_locks(map.thread(), &map, f)) ||
1634-
(f.is_native_frame() && ContinuationHelper::NativeFrame::is_owning_locks(map.thread(), f))) {
1635-
return true;
1636-
}
1637-
}
1638-
return false;
1639-
}
1640-
16411664
// There are no interpreted frames if we're not called from the interpreter and we haven't ancountered an i2c
16421665
// adapter or called Deoptimization::unpack_frames. As for native frames, upcalls from JNI also go through the
16431666
// interpreter (see JavaCalls::call_helper), while the UpcallLinker explicitly sets cont_fastpath.
@@ -1714,8 +1737,6 @@ static inline freeze_result freeze_internal(JavaThread* current, intptr_t* const
17141737

17151738
assert(entry->is_virtual_thread() == (entry->scope(current) == java_lang_VirtualThread::vthread_scope()), "");
17161739

1717-
assert(LockingMode != LM_LEGACY || (monitors_on_stack(current) == ((current->held_monitor_count() - current->jni_monitor_count()) > 0)),
1718-
"Held monitor count and locks on stack invariant: " INT64_FORMAT " JNI: " INT64_FORMAT, (int64_t)current->held_monitor_count(), (int64_t)current->jni_monitor_count());
17191740
assert(LockingMode == LM_LEGACY || (current->held_monitor_count() == 0 && current->jni_monitor_count() == 0),
17201741
"Held monitor count should only be used for LM_LEGACY: " INT64_FORMAT " JNI: " INT64_FORMAT, (int64_t)current->held_monitor_count(), (int64_t)current->jni_monitor_count());
17211742

src/hotspot/share/runtime/stackWatermark.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ class StackWatermark : public CHeapObj<mtThread> {
102102
void yield_processing();
103103
static bool has_barrier(const frame& f);
104104
void ensure_safe(const frame& f);
105-
void assert_is_frame_safe(const frame& f) NOT_DEBUG_RETURN;
106105
bool is_frame_safe(const frame& f);
107106

108107
// API for consumers of the stack watermark barrier.
@@ -151,6 +150,8 @@ class StackWatermark : public CHeapObj<mtThread> {
151150
void on_safepoint();
152151
void start_processing();
153152
void finish_processing(void* context);
153+
154+
void assert_is_frame_safe(const frame& f) NOT_DEBUG_RETURN;
154155
};
155156

156157
#endif // SHARE_RUNTIME_STACKWATERMARK_HPP

0 commit comments

Comments
 (0)