@@ -565,10 +565,50 @@ void FreezeBase::copy_to_chunk(intptr_t* from, intptr_t* to, int size) {
565
565
#endif
566
566
}
567
567
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
+
568
606
// Called _after_ the last possible safepoint during the freeze operation (chunk allocation)
569
607
void FreezeBase::unwind_frames () {
570
608
ContinuationEntry* entry = _cont.entry ();
571
609
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" );
572
612
set_anchor_to_entry (_thread, entry);
573
613
}
574
614
@@ -1621,23 +1661,6 @@ static void jvmti_mount_end(JavaThread* current, ContinuationWrapper& cont, fram
1621
1661
#endif // INCLUDE_JVMTI
1622
1662
1623
1663
#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
-
1641
1664
// There are no interpreted frames if we're not called from the interpreter and we haven't ancountered an i2c
1642
1665
// adapter or called Deoptimization::unpack_frames. As for native frames, upcalls from JNI also go through the
1643
1666
// 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
1714
1737
1715
1738
assert (entry->is_virtual_thread () == (entry->scope (current) == java_lang_VirtualThread::vthread_scope ()), " " );
1716
1739
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 ());
1719
1740
assert (LockingMode == LM_LEGACY || (current->held_monitor_count () == 0 && current->jni_monitor_count () == 0 ),
1720
1741
" 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 ());
1721
1742
0 commit comments