diff options
author | Ian Rogers <irogers@google.com> | 2014-04-01 22:46:11 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2014-04-01 22:46:11 +0000 |
commit | 52f5ecb1714a17b72182fcdf88ae7f6d817855cc (patch) | |
tree | 5d15e7229eedb937ce8a5dfeeec519967fbfe09b | |
parent | f5424f29709f40c2b3d98e2a5ed56c40187d368b (diff) | |
parent | d803bc7ce255be6c16eaf6a8a58a742515e9da9f (diff) | |
download | art-52f5ecb1714a17b72182fcdf88ae7f6d817855cc.zip art-52f5ecb1714a17b72182fcdf88ae7f6d817855cc.tar.gz art-52f5ecb1714a17b72182fcdf88ae7f6d817855cc.tar.bz2 |
Merge "Fix ThreadStress, unify ANR lock descriptions."
-rw-r--r-- | runtime/monitor.cc | 71 | ||||
-rw-r--r-- | runtime/thread.cc | 16 |
2 files changed, 51 insertions, 36 deletions
diff --git a/runtime/monitor.cc b/runtime/monitor.cc index 2d3d318..bcaf8ec 100644 --- a/runtime/monitor.cc +++ b/runtime/monitor.cc @@ -871,49 +871,50 @@ uint32_t Monitor::GetLockOwnerThreadId(mirror::Object* obj) { } void Monitor::DescribeWait(std::ostream& os, const Thread* thread) { - ThreadState state = thread->GetState(); - - int32_t object_identity_hashcode = 0; + // Determine the wait message and object we're waiting or blocked upon. + mirror::Object* pretty_object = nullptr; + const char* wait_message = nullptr; uint32_t lock_owner = ThreadList::kInvalidThreadId; - std::string pretty_type; + ThreadState state = thread->GetState(); if (state == kWaiting || state == kTimedWaiting || state == kSleeping) { - if (state == kSleeping) { - os << " - sleeping on "; - } else { - os << " - waiting on "; - } - { - Thread* self = Thread::Current(); - MutexLock mu(self, *thread->GetWaitMutex()); - Monitor* monitor = thread->GetWaitMonitor(); - if (monitor != NULL) { - mirror::Object* object = monitor->obj_; - object_identity_hashcode = object->IdentityHashCode(); - pretty_type = PrettyTypeOf(object); - } + wait_message = (state == kSleeping) ? " - sleeping on " : " - waiting on "; + Thread* self = Thread::Current(); + MutexLock mu(self, *thread->GetWaitMutex()); + Monitor* monitor = thread->GetWaitMonitor(); + if (monitor != nullptr) { + pretty_object = monitor->obj_; } } else if (state == kBlocked) { - os << " - waiting to lock "; - mirror::Object* object = thread->GetMonitorEnterObject(); - if (object != NULL) { - object_identity_hashcode = object->IdentityHashCode(); - lock_owner = object->GetLockOwnerThreadId(); - pretty_type = PrettyTypeOf(object); + wait_message = " - waiting to lock "; + pretty_object = thread->GetMonitorEnterObject(); + if (pretty_object != nullptr) { + lock_owner = pretty_object->GetLockOwnerThreadId(); } - } else { - // We're not waiting on anything. - return; } - // - waiting on <0x6008c468> (a java.lang.Class<java.lang.ref.ReferenceQueue>) - os << StringPrintf("<0x%08x> (a %s)", object_identity_hashcode, pretty_type.c_str()); - - // - waiting to lock <0x613f83d8> (a java.lang.Object) held by thread 5 - if (lock_owner != ThreadList::kInvalidThreadId) { - os << " held by thread " << lock_owner; + if (wait_message != nullptr) { + if (pretty_object == nullptr) { + os << wait_message << "an unknown object"; + } else { + if ((pretty_object->GetLockWord().GetState() == LockWord::kThinLocked) && + Locks::mutator_lock_->IsExclusiveHeld(Thread::Current())) { + // Getting the identity hashcode here would result in lock inflation and suspension of the + // current thread, which isn't safe if this is the only runnable thread. + os << wait_message << StringPrintf("<@addr=0x%" PRIxPTR "> (a %s)", + reinterpret_cast<intptr_t>(pretty_object), + PrettyTypeOf(pretty_object).c_str()); + } else { + // - waiting on <0x6008c468> (a java.lang.Class<java.lang.ref.ReferenceQueue>) + os << wait_message << StringPrintf("<0x%08x> (a %s)", pretty_object->IdentityHashCode(), + PrettyTypeOf(pretty_object).c_str()); + } + } + // - waiting to lock <0x613f83d8> (a java.lang.Object) held by thread 5 + if (lock_owner != ThreadList::kInvalidThreadId) { + os << " held by thread " << lock_owner; + } + os << "\n"; } - - os << "\n"; } mirror::Object* Monitor::GetContendedMonitor(Thread* thread) { diff --git a/runtime/thread.cc b/runtime/thread.cc index 2125ad5..c2fad44 100644 --- a/runtime/thread.cc +++ b/runtime/thread.cc @@ -868,7 +868,21 @@ struct StackDumpVisitor : public StackVisitor { static void DumpLockedObject(mirror::Object* o, void* context) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { std::ostream& os = *reinterpret_cast<std::ostream*>(context); - os << " - locked <" << o << "> (a " << PrettyTypeOf(o) << ")\n"; + os << " - locked "; + if (o == nullptr) { + os << "an unknown object"; + } else { + if ((o->GetLockWord().GetState() == LockWord::kThinLocked) && + Locks::mutator_lock_->IsExclusiveHeld(Thread::Current())) { + // Getting the identity hashcode here would result in lock inflation and suspension of the + // current thread, which isn't safe if this is the only runnable thread. + os << StringPrintf("<@addr=0x%" PRIxPTR "> (a %s)", reinterpret_cast<intptr_t>(o), + PrettyTypeOf(o).c_str()); + } else { + os << StringPrintf("<0x%08x> (a %s)", o->IdentityHashCode(), PrettyTypeOf(o).c_str()); + } + } + os << "\n"; } std::ostream& os; |