Remove mirror:: and ArtMethod deps in utils.{h,cc}

The latest chapter in the ongoing saga of attempting to dump a DEX
file without having to start a whole runtime instance.  This episode
finds us removing references to ArtMethod/ArtField/mirror.

One aspect of this change that I would like to call out specfically
is that the utils versions of the "Pretty*" functions all were written
to accept nullptr as an argument.  I have split these functions up as
follows:
1) an instance method, such as PrettyClass that obviously requires
this != nullptr.
2) a static method, that behaves the same way as the util method, but
calls the instance method if p != nullptr.
This requires using a full class qualifier for the static methods,
which isn't exactly beautiful.  I have tried to remove as many cases
as possible where it was clear p != nullptr.

Bug: 22322814
Test: test-art-host
Change-Id: I21adee3614aa697aa580cd1b86b72d9206e1cb24
diff --git a/runtime/mirror/class.cc b/runtime/mirror/class.cc
index f93f72f..6a357b3 100644
--- a/runtime/mirror/class.cc
+++ b/runtime/mirror/class.cc
@@ -59,7 +59,7 @@
 }
 
 inline void Class::SetVerifyError(ObjPtr<Object> error) {
-  CHECK(error != nullptr) << PrettyClass(this);
+  CHECK(error != nullptr) << PrettyClass();
   if (Runtime::Current()->IsActiveTransaction()) {
     SetFieldObject<true>(OFFSET_OF_OBJECT_MEMBER(Class, verify_error_), error);
   } else {
@@ -74,22 +74,22 @@
   if (LIKELY(class_linker_initialized)) {
     if (UNLIKELY(new_status <= old_status && new_status != kStatusError &&
                  new_status != kStatusRetired)) {
-      LOG(FATAL) << "Unexpected change back of class status for " << PrettyClass(h_this.Get())
+      LOG(FATAL) << "Unexpected change back of class status for " << h_this->PrettyClass()
                  << " " << old_status << " -> " << new_status;
     }
     if (new_status >= kStatusResolved || old_status >= kStatusResolved) {
       // When classes are being resolved the resolution code should hold the lock.
       CHECK_EQ(h_this->GetLockOwnerThreadId(), self->GetThreadId())
             << "Attempt to change status of class while not holding its lock: "
-            << PrettyClass(h_this.Get()) << " " << old_status << " -> " << new_status;
+            << h_this->PrettyClass() << " " << old_status << " -> " << new_status;
     }
   }
   if (UNLIKELY(new_status == kStatusError)) {
     CHECK_NE(h_this->GetStatus(), kStatusError)
         << "Attempt to set as erroneous an already erroneous class "
-        << PrettyClass(h_this.Get());
+        << h_this->PrettyClass();
     if (VLOG_IS_ON(class_linker)) {
-      LOG(ERROR) << "Setting " << PrettyDescriptor(h_this.Get()) << " to erroneous.";
+      LOG(ERROR) << "Setting " << h_this->PrettyDescriptor() << " to erroneous.";
       if (self->IsExceptionPending()) {
         LOG(ERROR) << "Exception: " << self->GetException()->Dump();
       }
@@ -127,7 +127,7 @@
     if (h_this->IsTemp()) {
       // Class is a temporary one, ensure that waiters for resolution get notified of retirement
       // so that they can grab the new version of the class from the class linker's table.
-      CHECK_LT(new_status, kStatusResolved) << PrettyDescriptor(h_this.Get());
+      CHECK_LT(new_status, kStatusResolved) << h_this->PrettyDescriptor();
       if (new_status == kStatusRetired || new_status == kStatusError) {
         h_this->NotifyAll(self);
       }
@@ -149,7 +149,7 @@
   if (kIsDebugBuild && new_class_size < GetClassSize()) {
     DumpClass(LOG_STREAM(FATAL_WITHOUT_ABORT), kDumpClassFullDetail);
     LOG(FATAL_WITHOUT_ABORT) << new_class_size << " vs " << GetClassSize();
-    LOG(FATAL) << "class=" << PrettyTypeOf(this);
+    LOG(FATAL) << "class=" << PrettyTypeOf();
   }
   // Not called within a transaction.
   SetField32<false>(OFFSET_OF_OBJECT_MEMBER(Class, class_size_), new_class_size);
@@ -196,7 +196,7 @@
 
 void Class::DumpClass(std::ostream& os, int flags) {
   if ((flags & kDumpClassFullDetail) == 0) {
-    os << PrettyClass(this);
+    os << PrettyClass();
     if ((flags & kDumpClassClassLoader) != 0) {
       os << ' ' << GetClassLoader();
     }
@@ -221,7 +221,7 @@
   os << StringPrintf("  access=0x%04x.%04x\n",
       GetAccessFlags() >> 16, GetAccessFlags() & kAccJavaFlagsMask);
   if (h_super.Get() != nullptr) {
-    os << "  super='" << PrettyClass(h_super.Get()) << "' (cl=" << h_super->GetClassLoader()
+    os << "  super='" << h_super->PrettyClass() << "' (cl=" << h_super->GetClassLoader()
        << ")\n";
   }
   if (IsArrayClass()) {
@@ -247,19 +247,20 @@
     os << "  vtable (" << h_this->NumVirtualMethods() << " entries, "
         << (h_super.Get() != nullptr ? h_super->NumVirtualMethods() : 0) << " in super):\n";
     for (size_t i = 0; i < NumVirtualMethods(); ++i) {
-      os << StringPrintf("    %2zd: %s\n", i, PrettyMethod(
+      os << StringPrintf("    %2zd: %s\n", i, ArtMethod::PrettyMethod(
           h_this->GetVirtualMethodDuringLinking(i, image_pointer_size)).c_str());
     }
     os << "  direct methods (" << h_this->NumDirectMethods() << " entries):\n";
     for (size_t i = 0; i < h_this->NumDirectMethods(); ++i) {
-      os << StringPrintf("    %2zd: %s\n", i, PrettyMethod(
+      os << StringPrintf("    %2zd: %s\n", i, ArtMethod::PrettyMethod(
           h_this->GetDirectMethod(i, image_pointer_size)).c_str());
     }
     if (h_this->NumStaticFields() > 0) {
       os << "  static fields (" << h_this->NumStaticFields() << " entries):\n";
       if (h_this->IsResolved() || h_this->IsErroneous()) {
         for (size_t i = 0; i < h_this->NumStaticFields(); ++i) {
-          os << StringPrintf("    %2zd: %s\n", i, PrettyField(h_this->GetStaticField(i)).c_str());
+          os << StringPrintf("    %2zd: %s\n", i,
+                             ArtField::PrettyField(h_this->GetStaticField(i)).c_str());
         }
       } else {
         os << "    <not yet available>";
@@ -269,7 +270,8 @@
       os << "  instance fields (" << h_this->NumInstanceFields() << " entries):\n";
       if (h_this->IsResolved() || h_this->IsErroneous()) {
         for (size_t i = 0; i < h_this->NumInstanceFields(); ++i) {
-          os << StringPrintf("    %2zd: %s\n", i, PrettyField(h_this->GetInstanceField(i)).c_str());
+          os << StringPrintf("    %2zd: %s\n", i,
+                             ArtField::PrettyField(h_this->GetInstanceField(i)).c_str());
         }
       } else {
         os << "    <not yet available>";
@@ -690,7 +692,7 @@
         break;
       }
     }
-    CHECK_EQ(found, ret) << "Found " << PrettyField(found) << " vs  " << PrettyField(ret);
+    CHECK_EQ(found, ret) << "Found " << found->PrettyField() << " vs  " << ret->PrettyField();
   }
   return ret;
 }
@@ -919,7 +921,7 @@
   while (!common_super_class->IsAssignableFrom(klass.Get())) {
     ObjPtr<Class> old_common = common_super_class;
     common_super_class = old_common->GetSuperClass();
-    DCHECK(common_super_class != nullptr) << PrettyClass(old_common);
+    DCHECK(common_super_class != nullptr) << old_common->PrettyClass();
   }
   return common_super_class;
 }
@@ -953,7 +955,7 @@
 
 void Class::PopulateEmbeddedVTable(PointerSize pointer_size) {
   PointerArray* table = GetVTableDuringLinking();
-  CHECK(table != nullptr) << PrettyClass(this);
+  CHECK(table != nullptr) << PrettyClass();
   const size_t table_length = table->GetLength();
   SetEmbeddedVTableLength(table_length);
   for (size_t i = 0; i < table_length; i++) {
@@ -1239,5 +1241,50 @@
   }
 }
 
+std::string Class::PrettyDescriptor(ObjPtr<mirror::Class> klass) {
+  if (klass == nullptr) {
+    return "null";
+  }
+  return klass->PrettyDescriptor();
+}
+
+std::string Class::PrettyDescriptor() {
+  std::string temp;
+  return art::PrettyDescriptor(GetDescriptor(&temp));
+}
+
+std::string Class::PrettyClass(ObjPtr<mirror::Class> c) {
+  if (c == nullptr) {
+    return "null";
+  }
+  return c->PrettyClass();
+}
+
+std::string Class::PrettyClass() {
+  std::string result;
+  result += "java.lang.Class<";
+  result += PrettyDescriptor();
+  result += ">";
+  return result;
+}
+
+std::string Class::PrettyClassAndClassLoader(ObjPtr<mirror::Class> c) {
+  if (c == nullptr) {
+    return "null";
+  }
+  return c->PrettyClassAndClassLoader();
+}
+
+std::string Class::PrettyClassAndClassLoader() {
+  std::string result;
+  result += "java.lang.Class<";
+  result += PrettyDescriptor();
+  result += ",";
+  result += mirror::Object::PrettyTypeOf(GetClassLoader());
+  // TODO: add an identifying hash value for the loader
+  result += ">";
+  return result;
+}
+
 }  // namespace mirror
 }  // namespace art