template <typename T, typename ResultT = typename std::invoke_result_t<T, Thread*, const ScopedFastNativeObjectAccess&>> static ResultT GetThreadStack(const ScopedFastNativeObjectAccess& soa, jobject peer, T fn)
REQUIRES_SHARED(Locks::mutator_lock_) {
ResultT trace = nullptr;
ObjPtr<mirror::Object> decoded_peer = soa.Decode<mirror::Object>(peer); if (decoded_peer == soa.Self()->GetPeer()) {
trace = fn(soa.Self(), soa); return trace;
} // Suspend thread to build stack trace.
ScopedThreadSuspension sts(soa.Self(), ThreadState::kNative);
Runtime* runtime = Runtime::Current();
ThreadList* thread_list = runtime->GetThreadList();
Thread* thread = thread_list->SuspendThreadByPeer(peer, SuspendReason::kInternal); if (thread != nullptr) { // If we were asked for the HeapTaskDaemon's stack trace, we went ahead and suspended it. // It's usually already in a suspended state anyway. But we should immediately give up and // resume it, since we must be able to allocate while generating the stack trace. if (!runtime->GetHeap()->GetTaskProcessor()->IsRunningThread(thread, /*wait=*/true)) {
{ // Must be runnable to create returned array.
ScopedObjectAccess soa2(soa.Self());
trace = fn(thread, soa);
} // Else either thread is the HeapTaskDaemon, or we couldn't identify the thread yet. The // HeapTaskDaemon can appear in enumerations before it is registered with the task // processor, and we don't wait indefinitely, so there is a tiny chance of the latter.
} // Restart suspended thread. bool resumed = thread_list->Resume(thread, SuspendReason::kInternal);
DCHECK(resumed);
} return trace;
}
// Returns the class of the caller's caller's caller. static jclass VMStack_getStackClass2(JNIEnv* env, jclass) {
ScopedFastNativeObjectAccess soa(env);
NthCallerVisitor visitor(soa.Self(), 3);
visitor.WalkStack(); if (UNLIKELY(visitor.caller == nullptr)) { // The caller is an attached native thread. return nullptr;
} return soa.AddLocalReference<jclass>(visitor.caller->GetDeclaringClass());
}
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.