jvmtiError ThreadGroupUtil::GetTopThreadGroups(jvmtiEnv* env,
jint* group_count_ptr,
jthreadGroup** groups_ptr) { // We only have a single top group. So we can take the current thread and move upwards. if (group_count_ptr == nullptr || groups_ptr == nullptr) { return ERR(NULL_POINTER);
}
art::Runtime* runtime = art::Runtime::Current(); if (runtime == nullptr) { // Must be starting the runtime, or dying. return ERR(WRONG_PHASE);
}
jobject sys_thread_group = runtime->GetSystemThreadGroup(); if (sys_thread_group == nullptr) { // Seems we're still starting up. return ERR(WRONG_PHASE);
}
unsignedchar* data;
jvmtiError result = env->Allocate(sizeof(jthreadGroup), &data); if (result != ERR(NONE)) { return result;
}
art::MutexLock mu(art::Thread::Current(), *art::Locks::thread_list_lock_);
std::list<art::Thread*> thread_list = art::Runtime::Current()->GetThreadList()->GetList(); // We have to be careful with threads exiting while we build this list.
std::vector<art::ThreadExitFlag> tefs(thread_list.size()); auto i = tefs.begin(); for (art::Thread* thd : thread_list) {
thd->NotifyOnThreadExit(&*i++);
}
DCHECK(i == tefs.end());
i = tefs.begin(); for (art::Thread* t : thread_list) {
art::ThreadExitFlag* tef = &*i++;
art::ObjPtr<art::mirror::Object> peer = t->LockedGetPeerFromOtherThread(tef); // Ignore runtime threads. They are internal threads and we don't have to report them to // debuggers. if (peer != nullptr && !tef->HasExited() && !t->IsStillStarting() && !t->IsRuntimeThread() &&
IsInDesiredThreadGroup(thread_group, peer)) {
thread_peers->push_back(peer);
}
t->UnregisterThreadExitFlag(tef);
}
DCHECK(i == tefs.end());
}
// Get the ThreadGroup[] "groups" out of this thread group...
art::ArtField* groups_field = art::WellKnownClasses::java_lang_ThreadGroup_groups;
art::ObjPtr<art::mirror::Object> groups_array = groups_field->GetObject(thread_group.Get());
if (groups_array == nullptr) { return;
}
CHECK(groups_array->IsObjectArray());
// Copy data into out buffers. for (size_t i = 0; i != thread_peers.size(); ++i) {
peers_uptr[i] = soa.AddLocalReference<jthread>(thread_peers[i]);
} for (size_t i = 0; i != thread_groups.size(); ++i) {
group_uptr[i] = soa.AddLocalReference<jthreadGroup>(thread_groups[i]);
}
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.