OSDN Git Service

Implement << operator for DexRegisterLocation::Kind.
authorDavid Srbecky <dsrbecky@google.com>
Thu, 25 Feb 2016 13:23:56 +0000 (13:23 +0000)
committerDavid Srbecky <dsrbecky@google.com>
Thu, 25 Feb 2016 14:07:27 +0000 (14:07 +0000)
This makes it comparable in DCHECK_EQ and similar methods.

Change-Id: I6b5b237be89325850ae6860d011fd6741189ab01

compiler/debug/elf_debug_loc_writer.h
compiler/optimizing/stack_map_stream.cc
runtime/check_reference_map_visitor.h
runtime/jit/jit.cc
runtime/quick_exception_handler.cc
runtime/stack.cc
runtime/stack_map.cc
runtime/stack_map.h

index 8fd20aa..32f624a 100644 (file)
@@ -232,8 +232,7 @@ static void WriteDebugLocEntry(const MethodDebugInfo* method_info,
         // kInStackLargeOffset and kConstantLargeValue are hidden by GetKind().
         // kInRegisterHigh and kInFpuRegisterHigh should be handled by
         // the special cases above and they should not occur alone.
-        LOG(ERROR) << "Unexpected register location kind: "
-                   << DexRegisterLocation::PrettyDescriptor(kind);
+        LOG(ERROR) << "Unexpected register location kind: " << kind;
         break;
       }
       if (is64bitValue) {
index 4784de1..b44f508 100644 (file)
@@ -63,8 +63,7 @@ void StackMapStream::EndStackMapEntry() {
 void StackMapStream::AddDexRegisterEntry(DexRegisterLocation::Kind kind, int32_t value) {
   if (kind != DexRegisterLocation::Kind::kNone) {
     // Ensure we only use non-compressed location kind at this stage.
-    DCHECK(DexRegisterLocation::IsShortLocationKind(kind))
-        << DexRegisterLocation::PrettyDescriptor(kind);
+    DCHECK(DexRegisterLocation::IsShortLocationKind(kind)) << kind;
     DexRegisterLocation location(kind, value);
 
     // Look for Dex register `location` in the location catalog (using the
index b9ea475..fcf3326 100644 (file)
@@ -100,8 +100,7 @@ class CheckReferenceMapVisitor : public StackVisitor {
           CHECK_EQ(location.GetValue(), 0);
           break;
         default:
-          LOG(FATAL) << "Unexpected location kind"
-                     << DexRegisterLocation::PrettyDescriptor(location.GetInternalKind());
+          LOG(FATAL) << "Unexpected location kind " << location.GetInternalKind();
       }
     }
   }
index 8d3da37..c6ec5b0 100644 (file)
@@ -378,8 +378,7 @@ bool Jit::MaybeDoOnStackReplacement(Thread* thread,
           continue;
         }
 
-        DCHECK(location == DexRegisterLocation::Kind::kInStack)
-            << DexRegisterLocation::PrettyDescriptor(location);
+        DCHECK_EQ(location, DexRegisterLocation::Kind::kInStack);
 
         int32_t vreg_value = shadow_frame->GetVReg(vreg);
         int32_t slot_offset = vreg_map.GetStackOffsetInBytes(vreg,
index dd384c7..fe6a529 100644 (file)
@@ -204,8 +204,7 @@ static VRegKind ToVRegKind(DexRegisterLocation::Kind kind) {
       return VRegKind::kDoubleHiVReg;
 
     default:
-      LOG(FATAL) << "Unexpected vreg location "
-                 << DexRegisterLocation::PrettyDescriptor(kind);
+      LOG(FATAL) << "Unexpected vreg location " << kind;
       UNREACHABLE();
   }
 }
@@ -450,12 +449,11 @@ class DeoptimizeStackVisitor FINAL : public StackVisitor {
         }
         default: {
           LOG(FATAL)
-              << "Unexpected location kind"
-              << DexRegisterLocation::PrettyDescriptor(
-                    vreg_map.GetLocationInternalKind(vreg,
-                                                     number_of_vregs,
-                                                     code_info,
-                                                     encoding));
+              << "Unexpected location kind "
+              << vreg_map.GetLocationInternalKind(vreg,
+                                                  number_of_vregs,
+                                                  code_info,
+                                                  encoding);
           UNREACHABLE();
         }
       }
index 5faff93..b1f1ed6 100644 (file)
@@ -352,12 +352,11 @@ bool StackVisitor::GetVRegFromOptimizedCode(ArtMethod* m, uint16_t vreg, VRegKin
       return false;
     default:
       LOG(FATAL)
-          << "Unexpected location kind"
-          << DexRegisterLocation::PrettyDescriptor(
-                dex_register_map.GetLocationInternalKind(vreg,
-                                                         number_of_dex_registers,
-                                                         code_info,
-                                                         encoding));
+          << "Unexpected location kind "
+          << dex_register_map.GetLocationInternalKind(vreg,
+                                                      number_of_dex_registers,
+                                                      code_info,
+                                                      encoding);
       UNREACHABLE();
   }
 }
index 5544507..3093436 100644 (file)
@@ -27,6 +27,31 @@ constexpr size_t DexRegisterLocationCatalog::kNoLocationEntryIndex;
 constexpr uint32_t StackMap::kNoDexRegisterMap;
 constexpr uint32_t StackMap::kNoInlineInfo;
 
+std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation::Kind& kind) {
+  using Kind = DexRegisterLocation::Kind;
+  switch (kind) {
+    case Kind::kNone:
+      return stream << "none";
+    case Kind::kInStack:
+      return stream << "in stack";
+    case Kind::kInRegister:
+      return stream << "in register";
+    case Kind::kInRegisterHigh:
+      return stream << "in register high";
+    case Kind::kInFpuRegister:
+      return stream << "in fpu register";
+    case Kind::kInFpuRegisterHigh:
+      return stream << "in fpu register high";
+    case Kind::kConstant:
+      return stream << "as constant";
+    case Kind::kInStackLargeOffset:
+      return stream << "in stack (large offset)";
+    case Kind::kConstantLargeValue:
+      return stream << "as constant (large value)";
+  }
+  return stream << "Kind<" << static_cast<uint32_t>(kind) << ">";
+}
+
 DexRegisterLocation::Kind DexRegisterMap::GetLocationInternalKind(
     uint16_t dex_register_number,
     uint16_t number_of_dex_registers,
@@ -97,7 +122,7 @@ static void DumpRegisterMapping(std::ostream& os,
                                 const std::string& prefix = "v",
                                 const std::string& suffix = "") {
   os << prefix << dex_register_num << ": "
-     << DexRegisterLocation::PrettyDescriptor(location.GetInternalKind())
+     << location.GetInternalKind()
      << " (" << location.GetValue() << ")" << suffix << '\n';
 }
 
index 97eb805..dbf23aa 100644 (file)
@@ -110,30 +110,6 @@ class DexRegisterLocation {
       sizeof(Kind) == 1u,
       "art::DexRegisterLocation::Kind has a size different from one byte.");
 
-  static const char* PrettyDescriptor(Kind kind) {
-    switch (kind) {
-      case Kind::kNone:
-        return "none";
-      case Kind::kInStack:
-        return "in stack";
-      case Kind::kInRegister:
-        return "in register";
-      case Kind::kInRegisterHigh:
-        return "in register high";
-      case Kind::kInFpuRegister:
-        return "in fpu register";
-      case Kind::kInFpuRegisterHigh:
-        return "in fpu register high";
-      case Kind::kConstant:
-        return "as constant";
-      case Kind::kInStackLargeOffset:
-        return "in stack (large offset)";
-      case Kind::kConstantLargeValue:
-        return "as constant (large value)";
-    }
-    UNREACHABLE();
-  }
-
   static bool IsShortLocationKind(Kind kind) {
     switch (kind) {
       case Kind::kInStack:
@@ -149,7 +125,7 @@ class DexRegisterLocation {
         return false;
 
       case Kind::kNone:
-        LOG(FATAL) << "Unexpected location kind " << PrettyDescriptor(kind);
+        LOG(FATAL) << "Unexpected location kind";
     }
     UNREACHABLE();
   }
@@ -215,6 +191,8 @@ class DexRegisterLocation {
   friend class DexRegisterLocationHashFn;
 };
 
+std::ostream& operator<<(std::ostream& stream, const DexRegisterLocation::Kind& kind);
+
 /**
  * Store information on unique Dex register locations used in a method.
  * The information is of the form:
@@ -349,7 +327,7 @@ class DexRegisterLocationCatalog {
       case DexRegisterLocation::Kind::kConstantLargeValue:
       case DexRegisterLocation::Kind::kInStackLargeOffset:
       case DexRegisterLocation::Kind::kNone:
-        LOG(FATAL) << "Unexpected location kind " << DexRegisterLocation::PrettyDescriptor(kind);
+        LOG(FATAL) << "Unexpected location kind " << kind;
     }
     UNREACHABLE();
   }
@@ -373,7 +351,7 @@ class DexRegisterLocationCatalog {
       case DexRegisterLocation::Kind::kConstantLargeValue:
       case DexRegisterLocation::Kind::kInStackLargeOffset:
       case DexRegisterLocation::Kind::kNone:
-        LOG(FATAL) << "Unexpected location kind " << DexRegisterLocation::PrettyDescriptor(kind);
+        LOG(FATAL) << "Unexpected location kind " << kind;
     }
     UNREACHABLE();
   }
@@ -515,8 +493,7 @@ class DexRegisterMap {
                       const StackMapEncoding& enc) const {
     DexRegisterLocation location =
         GetDexRegisterLocation(dex_register_number, number_of_dex_registers, code_info, enc);
-    DCHECK(location.GetKind() == DexRegisterLocation::Kind::kConstant)
-        << DexRegisterLocation::PrettyDescriptor(location.GetKind());
+    DCHECK_EQ(location.GetKind(), DexRegisterLocation::Kind::kConstant);
     return location.GetValue();
   }
 
@@ -530,7 +507,7 @@ class DexRegisterMap {
            location.GetInternalKind() == DexRegisterLocation::Kind::kInRegisterHigh ||
            location.GetInternalKind() == DexRegisterLocation::Kind::kInFpuRegister ||
            location.GetInternalKind() == DexRegisterLocation::Kind::kInFpuRegisterHigh)
-        << DexRegisterLocation::PrettyDescriptor(location.GetInternalKind());
+        << location.GetInternalKind();
     return location.GetValue();
   }