--- old/src/hotspot/share/prims/jvmtiEnv.cpp 2020-04-10 20:26:14.036661700 +0900 +++ new/src/hotspot/share/prims/jvmtiEnv.cpp 2020-04-10 20:26:13.753294400 +0900 @@ -1201,21 +1201,19 @@ jvmtiError JvmtiEnv::GetOwnedMonitorInfo(JavaThread* java_thread, jint* owned_monitor_count_ptr, jobject** owned_monitors_ptr) { jvmtiError err = JVMTI_ERROR_NONE; - JavaThread* calling_thread = JavaThread::current(); // growable array of jvmti monitors info on the C-heap GrowableArray *owned_monitors_list = new (ResourceObj::C_HEAP, mtInternal) GrowableArray(1, true); // It is only safe to perform the direct operation on the current - // thread. All other usage needs to use a vm-safepoint-op for safety. - if (java_thread == calling_thread) { - err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list); + // thread. All other usage needs to use a direct handshake for safety. + if (java_thread == JavaThread::current()) { + err = get_owned_monitors(java_thread, owned_monitors_list); } else { - // JVMTI get monitors info at safepoint. Do not require target thread to - // be suspended. - VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list); - VMThread::execute(&op); + // get owned monitors info with handshake + GetOwnedMonitorInfoClosure op(this, owned_monitors_list); + Handshake::execute_direct(&op, java_thread); err = op.result(); } jint owned_monitor_count = owned_monitors_list->length(); @@ -1247,21 +1245,19 @@ jvmtiError JvmtiEnv::GetOwnedMonitorStackDepthInfo(JavaThread* java_thread, jint* monitor_info_count_ptr, jvmtiMonitorStackDepthInfo** monitor_info_ptr) { jvmtiError err = JVMTI_ERROR_NONE; - JavaThread* calling_thread = JavaThread::current(); // growable array of jvmti monitors info on the C-heap GrowableArray *owned_monitors_list = new (ResourceObj::C_HEAP, mtInternal) GrowableArray(1, true); // It is only safe to perform the direct operation on the current - // thread. All other usage needs to use a vm-safepoint-op for safety. - if (java_thread == calling_thread) { - err = get_owned_monitors(calling_thread, java_thread, owned_monitors_list); + // thread. All other usage needs to use a direct handshake for safety. + if (java_thread == JavaThread::current()) { + err = get_owned_monitors(java_thread, owned_monitors_list); } else { - // JVMTI get owned monitors info at safepoint. Do not require target thread to - // be suspended. - VM_GetOwnedMonitorInfo op(this, calling_thread, java_thread, owned_monitors_list); - VMThread::execute(&op); + // get owned monitors info with handshake + GetOwnedMonitorInfoClosure op(this, owned_monitors_list); + Handshake::execute_direct(&op, java_thread); err = op.result(); } @@ -1296,16 +1292,15 @@ jvmtiError JvmtiEnv::GetCurrentContendedMonitor(JavaThread* java_thread, jobject* monitor_ptr) { jvmtiError err = JVMTI_ERROR_NONE; - JavaThread* calling_thread = JavaThread::current(); // It is only safe to perform the direct operation on the current - // thread. All other usage needs to use a vm-safepoint-op for safety. - if (java_thread == calling_thread) { - err = get_current_contended_monitor(calling_thread, java_thread, monitor_ptr); + // thread. All other usage needs to use a direct handshake for safety. + if (java_thread == JavaThread::current()) { + err = get_current_contended_monitor(java_thread, monitor_ptr); } else { - // get contended monitor information at safepoint. - VM_GetCurrentContendedMonitor op(this, calling_thread, java_thread, monitor_ptr); - VMThread::execute(&op); + // get contended monitor information with handshake + GetCurrentContendedMonitorClosure op(this, monitor_ptr); + Handshake::execute_direct(&op, java_thread); err = op.result(); } return err;