ScopedObjectAccess soa(env);
ThreadState internal_thread_state =
(has_been_started ? ThreadState::kTerminated : ThreadState::kStarting);
MutexLock mu(soa.Self(), *Locks::thread_list_lock_);
Thread* thread = Thread::FromManagedThread(soa, java_thread); if (thread != nullptr) {
internal_thread_state = thread->GetState();
} switch (internal_thread_state) { case ThreadState::kTerminated: return kJavaTerminated; case ThreadState::kRunnable: return kJavaRunnable; case ThreadState::kObsoleteRunnable: break; // Obsolete value. case ThreadState::kTimedWaiting: return kJavaTimedWaiting; case ThreadState::kSleeping: return kJavaTimedWaiting; case ThreadState::kBlocked: return kJavaBlocked; case ThreadState::kWaiting: return kJavaWaiting; case ThreadState::kStarting: return kJavaNew; case ThreadState::kNative: return kJavaRunnable; case ThreadState::kWaitingForTaskProcessor: return kJavaWaiting; case ThreadState::kWaitingForLockInflation: return kJavaWaiting; case ThreadState::kWaitingForGcToComplete: return kJavaWaiting; case ThreadState::kWaitingPerformingGc: return kJavaWaiting; case ThreadState::kWaitingForCheckPointsToRun: return kJavaWaiting; case ThreadState::kWaitingForDebuggerSend: return kJavaWaiting; case ThreadState::kWaitingForDebuggerToAttach: return kJavaWaiting; case ThreadState::kWaitingInMainDebuggerLoop: return kJavaWaiting; case ThreadState::kWaitingForDebuggerSuspension: return kJavaWaiting; case ThreadState::kWaitingForDeoptimization: return kJavaWaiting; case ThreadState::kWaitingForGetObjectsAllocated: return kJavaWaiting; case ThreadState::kWaitingForJniOnLoad: return kJavaWaiting; case ThreadState::kWaitingForSignalCatcherOutput: return kJavaWaiting; case ThreadState::kWaitingInMainSignalCatcherLoop: return kJavaWaiting; case ThreadState::kWaitingForMethodTracingStart: return kJavaWaiting; case ThreadState::kWaitingForVisitObjects: return kJavaWaiting; case ThreadState::kWaitingWeakGcRootRead: return kJavaRunnable; case ThreadState::kWaitingForGcThreadFlip: return kJavaWaiting; case ThreadState::kNativeForAbort: return kJavaWaiting; case ThreadState::kSuspended: return kJavaRunnable; case ThreadState::kInvalidState: break; // Don't add a 'default' here so the compiler can spot incompatible enum changes.
}
LOG(ERROR) << "Unexpected thread state: " << internal_thread_state; return -1; // Unreachable.
}
staticvoid Thread_setNativeName(JNIEnv* env, jobject peer, jstring java_name) {
ScopedUtfChars name(env, java_name);
{
ScopedObjectAccess soa(env); if (soa.Decode<mirror::Object>(peer) == soa.Self()->GetPeer()) {
soa.Self()->SetThreadName(name.c_str()); return;
}
} // Suspend thread to avoid it from killing itself while we set its name. We don't just hold the // thread list lock to avoid this, as setting the thread name causes mutator to lock/unlock // in the DDMS send code.
ThreadList* thread_list = Runtime::Current()->GetThreadList(); // Take suspend thread lock to avoid races with threads trying to suspend this one.
Thread* thread = thread_list->SuspendThreadByPeer(peer, SuspendReason::kInternal); if (thread != nullptr) {
{
ScopedObjectAccess soa(env);
thread->SetThreadName(name.c_str());
} bool resumed = thread_list->Resume(thread, SuspendReason::kInternal);
DCHECK(resumed);
}
}
/* *Alterthepriorityofthespecifiedthread."new_priority"willrange *fromThread.MIN_PRIORITYtoThread.MAX_PRIORITY(1-10),with"normal" *threadsatThread.NORM_PRIORITY(5).Returnscorrespondingniceness.
*/ staticvoid Thread_setPriority0([[maybe_unused]] JNIEnv* env,
jobject java_thread,
jint new_priority,
jint new_niceness) REQUIRES_SHARED(art::Locks::mutator_lock_) { // We should just do the conversion and call the above. But that would bypass the // Android S workaround in SetNativePriority. So we have a separate code path.
Thread* self = Thread::Current();
MutexLock mu(self, *Locks::thread_list_lock_);
Thread* thread = Thread::FromManagedThread(self, self->DecodeJObject(java_thread)); if (thread != nullptr) {
thread->SetNativePriority(new_priority, new_niceness);
}
}
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.