@@ -649,10 +649,9 @@ JvmtiEnvBase::count_locked_objects(JavaThread *java_thread, Handle hobj) {
649649
650650jvmtiError
651651JvmtiEnvBase::get_current_contended_monitor (JavaThread *calling_thread, JavaThread *java_thread, jobject *monitor_ptr) {
652- JavaThread *current_jt = JavaThread::current ();
653- assert (current_jt == java_thread ||
654- current_jt == java_thread->active_handshaker (),
655- " call by myself or at direct handshake" );
652+ Thread *current_thread = Thread::current ();
653+ assert (java_thread->is_handshake_safe_for (current_thread),
654+ " call by myself or at handshake" );
656655 oop obj = NULL ;
657656 // The ObjectMonitor* can't be async deflated since we are either
658657 // at a safepoint or the calling thread is operating on itself so
@@ -676,8 +675,8 @@ JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThre
676675 if (obj == NULL ) {
677676 *monitor_ptr = NULL ;
678677 } else {
679- HandleMark hm (current_jt );
680- Handle hobj (current_jt , obj);
678+ HandleMark hm (current_thread );
679+ Handle hobj (current_thread , obj);
681680 *monitor_ptr = jni_reference (calling_thread, hobj);
682681 }
683682 return JVMTI_ERROR_NONE;
@@ -687,15 +686,19 @@ JvmtiEnvBase::get_current_contended_monitor(JavaThread *calling_thread, JavaThre
687686jvmtiError
688687JvmtiEnvBase::get_owned_monitors (JavaThread *calling_thread, JavaThread* java_thread,
689688 GrowableArray<jvmtiMonitorStackDepthInfo*> *owned_monitors_list) {
689+ // Note:
690+ // calling_thread is the thread that requested the list of monitors for java_thread.
691+ // java_thread is the thread owning the monitors.
692+ // current_thread is the thread executing this code, can be a non-JavaThread (e.g. VM Thread).
693+ // And they all may be different threads.
690694 jvmtiError err = JVMTI_ERROR_NONE;
691- JavaThread *current_jt = JavaThread::current ();
692- assert (current_jt == java_thread ||
693- current_jt == java_thread->active_handshaker (),
694- " call by myself or at direct handshake" );
695+ Thread *current_thread = Thread::current ();
696+ assert (java_thread->is_handshake_safe_for (current_thread),
697+ " call by myself or at handshake" );
695698
696699 if (java_thread->has_last_Java_frame ()) {
697- ResourceMark rm (current_jt );
698- HandleMark hm (current_jt );
700+ ResourceMark rm (current_thread );
701+ HandleMark hm (current_thread );
699702 RegisterMap reg_map (java_thread);
700703
701704 int depth = 0 ;
@@ -819,9 +822,8 @@ JvmtiEnvBase::get_stack_trace(JavaThread *java_thread,
819822 uint32_t debug_bits = 0 ;
820823#endif
821824 Thread *current_thread = Thread::current ();
822- assert (current_thread == java_thread ||
823- SafepointSynchronize::is_at_safepoint () ||
824- current_thread == java_thread->active_handshaker (),
825+ assert (SafepointSynchronize::is_at_safepoint () ||
826+ java_thread->is_handshake_safe_for (current_thread),
825827 " call by myself / at safepoint / at handshake" );
826828 int count = 0 ;
827829 if (java_thread->has_last_Java_frame ()) {
@@ -903,9 +905,8 @@ JvmtiEnvBase::get_frame_location(JavaThread *java_thread, jint depth,
903905 uint32_t debug_bits = 0 ;
904906#endif
905907 Thread* current_thread = Thread::current ();
906- assert (current_thread == java_thread ||
907- current_thread == java_thread->active_handshaker (),
908- " call by myself or at direct handshake" );
908+ assert (java_thread->is_handshake_safe_for (current_thread),
909+ " call by myself or at handshake" );
909910 ResourceMark rm (current_thread);
910911
911912 vframe *vf = vframeFor (java_thread, depth);
@@ -1159,9 +1160,8 @@ void
11591160MultipleStackTracesCollector::fill_frames (jthread jt, JavaThread *thr, oop thread_oop) {
11601161#ifdef ASSERT
11611162 Thread *current_thread = Thread::current ();
1162- assert (current_thread == thr ||
1163- SafepointSynchronize::is_at_safepoint () ||
1164- current_thread == thr->active_handshaker (),
1163+ assert (SafepointSynchronize::is_at_safepoint () ||
1164+ thr->is_handshake_safe_for (current_thread),
11651165 " call by myself / at safepoint / at handshake" );
11661166#endif
11671167
@@ -1305,7 +1305,7 @@ VM_GetAllStackTraces::doit() {
13051305// HandleMark must be defined in the caller only.
13061306// It is to keep a ret_ob_h handle alive after return to the caller.
13071307jvmtiError
1308- JvmtiEnvBase::check_top_frame (JavaThread * current_thread, JavaThread* java_thread,
1308+ JvmtiEnvBase::check_top_frame (Thread * current_thread, JavaThread* java_thread,
13091309 jvalue value, TosState tos, Handle* ret_ob_h) {
13101310 ResourceMark rm (current_thread);
13111311
@@ -1368,7 +1368,7 @@ JvmtiEnvBase::check_top_frame(JavaThread* current_thread, JavaThread* java_threa
13681368
13691369jvmtiError
13701370JvmtiEnvBase::force_early_return (JavaThread* java_thread, jvalue value, TosState tos) {
1371- JavaThread * current_thread = JavaThread ::current ();
1371+ Thread * current_thread = Thread ::current ();
13721372 HandleMark hm (current_thread);
13731373 uint32_t debug_bits = 0 ;
13741374
0 commit comments