jvmtiError ObjectUtil::GetObjectMonitorUsage(
jvmtiEnv* baseenv, jobject obj, jvmtiMonitorUsage* usage) {
ArtJvmTiEnv* env = ArtJvmTiEnv::AsArtJvmTiEnv(baseenv); if (obj == nullptr) { return ERR(INVALID_OBJECT);
} if (usage == nullptr) { return ERR(NULL_POINTER);
}
art::Thread* self = art::Thread::Current();
ThreadUtil::SuspendCheck(self);
art::JNIEnvExt* jni = self->GetJniEnv();
std::vector<jthread> wait;
std::vector<jthread> notify_wait;
{
art::ScopedObjectAccess soa(self); // Now we know we have the shared lock.
art::ScopedThreadSuspension sts(self, art::ThreadState::kNative);
art::ScopedSuspendAll ssa("GetObjectMonitorUsage", /*long_suspend=*/false);
art::ObjPtr<art::mirror::Object> target(self->DecodeJObject(obj)); // This gets the list of threads trying to lock or wait on the monitor.
art::MonitorInfo info(target.Ptr()); if (info.owner_ == nullptr) {
usage->owner = nullptr;
} elseif (info.owner_.IsVirtualThread()) { // TODO(b/460438903): Return the virtual thread peer object.
usage->owner = nullptr;
} else {
usage->owner =
jni->AddLocalReference<jthread>(info.owner_.GetThreadPtr()->GetPeerFromOtherThread());
}
usage->entry_count = info.entry_count_; for (art::Thread* thd : info.waiters_) { // RI seems to consider waiting for notify to be included in those waiting to acquire the // monitor. We will match this behavior.
notify_wait.push_back(jni->AddLocalReference<jthread>(thd->GetPeerFromOtherThread()));
wait.push_back(jni->AddLocalReference<jthread>(thd->GetPeerFromOtherThread()));
} // Scan all threads to see which are waiting on this particular monitor.
std::list<art::Thread*> thread_list;
{ // Since we're in a SuspendAll, exiting threads are not a concern.
art::MutexLock tll(self, *art::Locks::thread_list_lock_);
thread_list = art::Runtime::Current()->GetThreadList()->GetList();
} for (art::Thread* thd : thread_list) { if (thd != info.owner_ && target.Ptr() == thd->GetMonitorEnterObject()) {
art::mirror::Object* peer = thd->GetPeerFromOtherThread();
wait.push_back(jni->AddLocalReference<jthread>(peer));
}
}
}
usage->waiter_count = wait.size();
usage->notify_waiter_count = notify_wait.size();
jvmtiError ret = CopyDataIntoJvmtiBuffer(env, reinterpret_cast<constunsignedchar*>(wait.data()),
wait.size() * sizeof(jthread), reinterpret_cast<unsignedchar**>(&usage->waiters)); if (ret != OK) { return ret;
} return CopyDataIntoJvmtiBuffer(env, reinterpret_cast<constunsignedchar*>(notify_wait.data()),
notify_wait.size() * sizeof(jthread), reinterpret_cast<unsignedchar**>(&usage->notify_waiters));
}
} // namespace openjdkjvmti
Messung V0.5 in Prozent
¤ Dauer der Verarbeitung: 0.10 Sekunden
(vorverarbeitet am 2026-06-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.