--- old/src/hotspot/share/prims/jvmtiEnv.cpp 2020-06-18 11:53:50.919310536 +0900 +++ new/src/hotspot/share/prims/jvmtiEnv.cpp 2020-06-18 11:53:50.837308239 +0900 @@ -2839,15 +2839,11 @@ // info_ptr - pre-checked for NULL jvmtiError JvmtiEnv::GetObjectMonitorUsage(jobject object, jvmtiMonitorUsage* info_ptr) { - JavaThread* calling_thread = JavaThread::current(); - jvmtiError err = get_object_monitor_usage(calling_thread, object, info_ptr); - if (err == JVMTI_ERROR_THREAD_NOT_SUSPENDED) { - // Some of the critical threads were not suspended. go to a safepoint and try again - VM_GetObjectMonitorUsage op(this, calling_thread, object, info_ptr); - VMThread::execute(&op); - err = op.result(); - } - return err; + // It need to perform at safepoint for gathering stable data + // because monitor owner / waiters might not be suspended. + VM_GetObjectMonitorUsage op(this, JavaThread::current(), object, info_ptr); + VMThread::execute(&op); + return op.result(); } /* end GetObjectMonitorUsage */ --- old/src/hotspot/share/prims/jvmtiEnvBase.cpp 2020-06-18 11:53:51.322321825 +0900 +++ new/src/hotspot/share/prims/jvmtiEnvBase.cpp 2020-06-18 11:53:51.246319696 +0900 @@ -937,11 +937,12 @@ jvmtiError JvmtiEnvBase::get_object_monitor_usage(JavaThread* calling_thread, jobject object, jvmtiMonitorUsage* info_ptr) { + assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint"); + HandleMark hm; Handle hobj; Thread* current_thread = Thread::current(); - bool at_safepoint = SafepointSynchronize::is_at_safepoint(); // Check arguments { @@ -962,11 +963,7 @@ // first derive the object's owner and entry_count (if any) { // Revoke any biases before querying the mark word - if (at_safepoint) { - BiasedLocking::revoke_at_safepoint(hobj); - } else { - BiasedLocking::revoke(hobj, calling_thread); - } + BiasedLocking::revoke_at_safepoint(hobj); address owner = NULL; { @@ -999,26 +996,9 @@ ThreadsListHandle tlh; // This monitor is owned so we have to find the owning JavaThread. owning_thread = Threads::owning_thread_from_monitor_owner(tlh.list(), owner); - // Cannot assume (owning_thread != NULL) here because this function - // may not have been called at a safepoint and the owning_thread - // might not be suspended. - if (owning_thread != NULL) { - // The monitor's owner either has to be the current thread, at safepoint - // or it has to be suspended. Any of these conditions will prevent both - // contending and waiting threads from modifying the state of - // the monitor. - if (!at_safepoint && !owning_thread->is_thread_fully_suspended(true, &debug_bits)) { - // Don't worry! This return of JVMTI_ERROR_THREAD_NOT_SUSPENDED - // will not make it back to the JVM/TI agent. The error code will - // get intercepted in JvmtiEnv::GetObjectMonitorUsage() which - // will retry the call via a VM_GetObjectMonitorUsage VM op. - return JVMTI_ERROR_THREAD_NOT_SUSPENDED; - } - HandleMark hm; - Handle th(current_thread, owning_thread->threadObj()); - ret.owner = (jthread)jni_reference(calling_thread, th); - } - // implied else: no owner + assert(owning_thread != NULL, "owning JavaThread must not be NULL"); + Handle th(current_thread, owning_thread->threadObj()); + ret.owner = (jthread)jni_reference(calling_thread, th); } // ThreadsListHandle is destroyed here. if (owning_thread != NULL) { // monitor is owned @@ -1085,21 +1065,6 @@ } for (int i = 0; i < nWant; i++) { JavaThread *pending_thread = wantList->at(i); - // If the monitor has no owner, then a non-suspended contending - // thread could potentially change the state of the monitor by - // entering it. The JVM/TI spec doesn't allow this. - if (owning_thread == NULL && !at_safepoint && - !pending_thread->is_thread_fully_suspended(true, &debug_bits)) { - if (ret.owner != NULL) { - destroy_jni_reference(calling_thread, ret.owner); - } - for (int j = 0; j < i; j++) { - destroy_jni_reference(calling_thread, ret.waiters[j]); - } - deallocate((unsigned char*)ret.waiters); - deallocate((unsigned char*)ret.notify_waiters); - return JVMTI_ERROR_THREAD_NOT_SUSPENDED; - } Handle th(current_thread, pending_thread->threadObj()); ret.waiters[i] = (jthread)jni_reference(calling_thread, th); }