Fix frequent gcstress ThreadStress crash

Calling IdentityHashCode before PrettyTypeOf was causing occasional
stale root errors since IdentityHashCode can cause thread suspension.

Cleaned up VisitLocks.

Bug: 18766916
Change-Id: I7679539877e48a8c9aadb8a34718404ebce98d25
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 23c6557..d2d5be7 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -932,7 +932,10 @@
         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());
+        // IdentityHashCode can cause thread suspension, which would invalidate o if it moved. So
+        // we get the pretty type beofre we call IdentityHashCode.
+        const std::string pretty_type(PrettyTypeOf(o));
+        os << StringPrintf("<0x%08x> (a %s)", o->IdentityHashCode(), pretty_type.c_str());
       }
     }
     os << "\n";