summaryrefslogtreecommitdiffstats
path: root/runtime/native
diff options
context:
space:
mode:
authorBrian Carlstrom <bdc@google.com>2014-08-27 23:43:46 -0700
committerBrian Carlstrom <bdc@google.com>2014-08-28 15:37:27 -0700
commitba32de47e32f436d7c11cb4a2e78bdd4ad4dc5d2 (patch)
tree1b56397dfce317d2034feebfb2191bcb09b78823 /runtime/native
parent14515d738dadf88e3e00b7dd1bd69899c4df4b91 (diff)
downloadart-ba32de47e32f436d7c11cb4a2e78bdd4ad4dc5d2.zip
art-ba32de47e32f436d7c11cb4a2e78bdd4ad4dc5d2.tar.gz
art-ba32de47e32f436d7c11cb4a2e78bdd4ad4dc5d2.tar.bz2
Fix issue with Thread.setName hanging after Thread.start
When suspending a thread by peer the invariant that only attached threads are suspended must be maintained. Add a ThreadList::Contains check which requires making this method non-static. Add some extra thread logging. Bug: 17302037 (cherry picked from commit 37c16453a92bbf1a47f042000318a1b60381017d) Change-Id: I51832785d4b4b431e035318e75635f442e89a1fb
Diffstat (limited to 'runtime/native')
-rw-r--r--runtime/native/dalvik_system_VMStack.cc5
-rw-r--r--runtime/native/java_lang_Thread.cc5
2 files changed, 6 insertions, 4 deletions
diff --git a/runtime/native/dalvik_system_VMStack.cc b/runtime/native/dalvik_system_VMStack.cc
index b079229..eef1c46 100644
--- a/runtime/native/dalvik_system_VMStack.cc
+++ b/runtime/native/dalvik_system_VMStack.cc
@@ -34,12 +34,13 @@ static jobject GetThreadStack(const ScopedFastNativeObjectAccess& soa, jobject p
} else {
// Suspend thread to build stack trace.
soa.Self()->TransitionFromRunnableToSuspended(kNative);
+ ThreadList* thread_list = Runtime::Current()->GetThreadList();
bool timed_out;
Thread* thread;
{
// Take suspend thread lock to avoid races with threads trying to suspend this one.
MutexLock mu(soa.Self(), *Locks::thread_list_suspend_thread_lock_);
- thread = ThreadList::SuspendThreadByPeer(peer, true, false, &timed_out);
+ thread = thread_list->SuspendThreadByPeer(peer, true, false, &timed_out);
}
if (thread != nullptr) {
// Must be runnable to create returned array.
@@ -47,7 +48,7 @@ static jobject GetThreadStack(const ScopedFastNativeObjectAccess& soa, jobject p
trace = thread->CreateInternalStackTrace<false>(soa);
soa.Self()->TransitionFromRunnableToSuspended(kNative);
// Restart suspended thread.
- Runtime::Current()->GetThreadList()->Resume(thread, false);
+ thread_list->Resume(thread, false);
} else {
if (timed_out) {
LOG(ERROR) << "Trying to get thread's stack failed as the thread failed to suspend within a "
diff --git a/runtime/native/java_lang_Thread.cc b/runtime/native/java_lang_Thread.cc
index 8f83f96..c0c7265 100644
--- a/runtime/native/java_lang_Thread.cc
+++ b/runtime/native/java_lang_Thread.cc
@@ -128,19 +128,20 @@ static void Thread_nativeSetName(JNIEnv* env, jobject peer, jstring java_name) {
// 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();
bool timed_out;
// Take suspend thread lock to avoid races with threads trying to suspend this one.
Thread* thread;
{
MutexLock mu(self, *Locks::thread_list_suspend_thread_lock_);
- thread = ThreadList::SuspendThreadByPeer(peer, true, false, &timed_out);
+ thread = thread_list->SuspendThreadByPeer(peer, true, false, &timed_out);
}
if (thread != NULL) {
{
ScopedObjectAccess soa(env);
thread->SetThreadName(name.c_str());
}
- Runtime::Current()->GetThreadList()->Resume(thread, false);
+ thread_list->Resume(thread, false);
} else if (timed_out) {
LOG(ERROR) << "Trying to set thread name to '" << name.c_str() << "' failed as the thread "
"failed to suspend within a generous timeout.";