Fix ThreadStress, unify ANR lock descriptions.
Bug: 13323656
Change-Id: I902825a847af9aa570ed79701409298e3532bebf
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 @@
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;