8328758: GetCurrentContendedMonitor function should use JvmtiHandshake
Reviewed-by: lmesnik, pchilanomate
This commit is contained in:
parent
7560dbb925
commit
5f7432f7b1
@ -1463,44 +1463,14 @@ JvmtiEnv::GetOwnedMonitorStackDepthInfo(jthread thread, jint* monitor_info_count
|
||||
// monitor_ptr - pre-checked for null
|
||||
jvmtiError
|
||||
JvmtiEnv::GetCurrentContendedMonitor(jthread thread, jobject* monitor_ptr) {
|
||||
JavaThread* calling_thread = JavaThread::current();
|
||||
HandleMark hm(calling_thread);
|
||||
JavaThread* current = JavaThread::current();
|
||||
|
||||
JvmtiVTMSTransitionDisabler disabler(thread);
|
||||
ThreadsListHandle tlh(calling_thread);
|
||||
*monitor_ptr = nullptr;
|
||||
|
||||
JavaThread* java_thread = nullptr;
|
||||
oop thread_oop = nullptr;
|
||||
jvmtiError err = get_threadOop_and_JavaThread(tlh.list(), thread, &java_thread, &thread_oop);
|
||||
if (err != JVMTI_ERROR_NONE) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (java_lang_VirtualThread::is_instance(thread_oop)) {
|
||||
// There is no monitor info to collect if target virtual thread is unmounted.
|
||||
if (java_thread != nullptr) {
|
||||
GetCurrentContendedMonitorClosure op(calling_thread, this, monitor_ptr, /* is_virtual */ true);
|
||||
Handshake::execute(&op, java_thread);
|
||||
err = op.result();
|
||||
} else {
|
||||
*monitor_ptr = nullptr;
|
||||
if (!JvmtiEnvBase::is_vthread_alive(thread_oop)) {
|
||||
err = JVMTI_ERROR_THREAD_NOT_ALIVE;
|
||||
}
|
||||
}
|
||||
return err;
|
||||
}
|
||||
if (java_thread == calling_thread) {
|
||||
// It is only safe to make a direct call on the current thread.
|
||||
// All other usage needs to use a direct handshake for safety.
|
||||
err = get_current_contended_monitor(calling_thread, java_thread, monitor_ptr, /* is_virtual */ false);
|
||||
} else {
|
||||
// get contended monitor information with handshake
|
||||
GetCurrentContendedMonitorClosure op(calling_thread, this, monitor_ptr, /* is_virtual */ false);
|
||||
Handshake::execute(&op, java_thread);
|
||||
err = op.result();
|
||||
}
|
||||
return err;
|
||||
// get contended monitor information with handshake
|
||||
GetCurrentContendedMonitorClosure op(this, current, monitor_ptr);
|
||||
JvmtiHandshake::execute(&op, thread);
|
||||
return op.result();
|
||||
} /* end GetCurrentContendedMonitor */
|
||||
|
||||
|
||||
|
@ -2497,6 +2497,16 @@ GetCurrentContendedMonitorClosure::do_thread(Thread *target) {
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GetCurrentContendedMonitorClosure::do_vthread(Handle target_h) {
|
||||
if (_target_jt == nullptr) {
|
||||
_result = JVMTI_ERROR_NONE; // target virtual thread is unmounted
|
||||
return;
|
||||
}
|
||||
// mounted virtual thread case
|
||||
do_thread(_target_jt);
|
||||
}
|
||||
|
||||
void
|
||||
GetStackTraceClosure::do_thread(Thread *target) {
|
||||
Thread* current = Thread::current();
|
||||
|
@ -593,21 +593,22 @@ public:
|
||||
};
|
||||
|
||||
// HandshakeClosure to get current contended monitor. It is used for both platform and virtual threads.
|
||||
class GetCurrentContendedMonitorClosure : public JvmtiHandshakeClosure {
|
||||
class GetCurrentContendedMonitorClosure : public JvmtiUnitedHandshakeClosure {
|
||||
private:
|
||||
JavaThread *_calling_thread;
|
||||
JvmtiEnv *_env;
|
||||
JavaThread *_calling_thread;
|
||||
jobject *_owned_monitor_ptr;
|
||||
bool _is_virtual;
|
||||
|
||||
public:
|
||||
GetCurrentContendedMonitorClosure(JavaThread* calling_thread, JvmtiEnv *env, jobject *mon_ptr, bool is_virtual)
|
||||
: JvmtiHandshakeClosure("GetCurrentContendedMonitor"),
|
||||
_calling_thread(calling_thread),
|
||||
GetCurrentContendedMonitorClosure(JvmtiEnv *env,
|
||||
JavaThread* calling_thread,
|
||||
jobject *owned_monitor_ptr)
|
||||
: JvmtiUnitedHandshakeClosure("GetCurrentContendedMonitor"),
|
||||
_env(env),
|
||||
_owned_monitor_ptr(mon_ptr),
|
||||
_is_virtual(is_virtual) {}
|
||||
_calling_thread(calling_thread),
|
||||
_owned_monitor_ptr(owned_monitor_ptr) {}
|
||||
void do_thread(Thread *target);
|
||||
void do_vthread(Handle target_h);
|
||||
};
|
||||
|
||||
// HandshakeClosure to get stack trace.
|
||||
|
Loading…
Reference in New Issue
Block a user