Remove unused GetDexRegisterMap arguments.

They are no longer needed in the new encoding.

I reuse the local variables in most places to DCHECK the size
of the decoded register map.  This has one catch though:
We sometimes omit all dex registers, so the DCHECK should be
done only after checking if the map is empty (if applicable).

Test: test-art-host-gtest-stack_map_test
Change-Id: I94b67029842374bc8eb7c9e5eac76fc93a651f24
diff --git a/runtime/check_reference_map_visitor.h b/runtime/check_reference_map_visitor.h
index acdb235..8a2a70e 100644
--- a/runtime/check_reference_map_visitor.h
+++ b/runtime/check_reference_map_visitor.h
@@ -68,8 +68,8 @@
     StackMap stack_map = code_info.GetStackMapForNativePcOffset(native_pc_offset);
     CodeItemDataAccessor accessor(m->DexInstructionData());
     uint16_t number_of_dex_registers = accessor.RegistersSize();
-    DexRegisterMap dex_register_map =
-        code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers);
+    DexRegisterMap dex_register_map = code_info.GetDexRegisterMapOf(stack_map);
+    DCHECK_EQ(dex_register_map.size(), number_of_dex_registers);
     uint32_t register_mask = code_info.GetRegisterMaskOf(stack_map);
     BitMemoryRegion stack_mask = code_info.GetStackMaskOf(stack_map);
     for (int i = 0; i < number_of_references; ++i) {
diff --git a/runtime/jit/jit.cc b/runtime/jit/jit.cc
index b7b779c..5a5634e 100644
--- a/runtime/jit/jit.cc
+++ b/runtime/jit/jit.cc
@@ -493,8 +493,7 @@
 
     // We found a stack map, now fill the frame with dex register values from the interpreter's
     // shadow frame.
-    DexRegisterMap vreg_map =
-        code_info.GetDexRegisterMapOf(stack_map, number_of_vregs);
+    DexRegisterMap vreg_map = code_info.GetDexRegisterMapOf(stack_map);
 
     frame_size = osr_method->GetFrameSizeInBytes();
 
@@ -510,10 +509,11 @@
     memory[0] = method;
 
     shadow_frame = thread->PopShadowFrame();
-    if (!vreg_map.IsValid()) {
+    if (vreg_map.empty()) {
       // If we don't have a dex register map, then there are no live dex registers at
       // this dex pc.
     } else {
+      DCHECK_EQ(vreg_map.size(), number_of_vregs);
       for (uint16_t vreg = 0; vreg < number_of_vregs; ++vreg) {
         DexRegisterLocation::Kind location = vreg_map.GetLocationKind(vreg);
         if (location == DexRegisterLocation::Kind::kNone) {
diff --git a/runtime/quick_exception_handler.cc b/runtime/quick_exception_handler.cc
index 23ccf6a..cf1cbe7 100644
--- a/runtime/quick_exception_handler.cc
+++ b/runtime/quick_exception_handler.cc
@@ -230,19 +230,18 @@
   // Find stack map of the catch block.
   StackMap catch_stack_map = code_info.GetCatchStackMapForDexPc(GetHandlerDexPc());
   DCHECK(catch_stack_map.IsValid());
-  DexRegisterMap catch_vreg_map =
-      code_info.GetDexRegisterMapOf(catch_stack_map, number_of_vregs);
-  if (!catch_vreg_map.IsValid() || !catch_vreg_map.HasAnyLiveDexRegisters()) {
+  DexRegisterMap catch_vreg_map = code_info.GetDexRegisterMapOf(catch_stack_map);
+  if (!catch_vreg_map.HasAnyLiveDexRegisters()) {
     return;
   }
+  DCHECK_EQ(catch_vreg_map.size(), number_of_vregs);
 
   // Find stack map of the throwing instruction.
   StackMap throw_stack_map =
       code_info.GetStackMapForNativePcOffset(stack_visitor->GetNativePcOffset());
   DCHECK(throw_stack_map.IsValid());
-  DexRegisterMap throw_vreg_map =
-      code_info.GetDexRegisterMapOf(throw_stack_map, number_of_vregs);
-  DCHECK(throw_vreg_map.IsValid());
+  DexRegisterMap throw_vreg_map = code_info.GetDexRegisterMapOf(throw_stack_map);
+  DCHECK_EQ(throw_vreg_map.size(), number_of_vregs);
 
   // Copy values between them.
   for (uint16_t vreg = 0; vreg < number_of_vregs; ++vreg) {
@@ -405,14 +404,12 @@
     uint32_t register_mask = code_info.GetRegisterMaskOf(stack_map);
     BitMemoryRegion stack_mask = code_info.GetStackMaskOf(stack_map);
     DexRegisterMap vreg_map = IsInInlinedFrame()
-        ? code_info.GetDexRegisterMapAtDepth(GetCurrentInliningDepth() - 1,
-                                             stack_map,
-                                             number_of_vregs)
-        : code_info.GetDexRegisterMapOf(stack_map, number_of_vregs);
-
-    if (!vreg_map.IsValid()) {
+        ? code_info.GetDexRegisterMapAtDepth(GetCurrentInliningDepth() - 1, stack_map)
+        : code_info.GetDexRegisterMapOf(stack_map);
+    if (vreg_map.empty()) {
       return;
     }
+    DCHECK_EQ(vreg_map.size(), number_of_vregs);
 
     for (uint16_t vreg = 0; vreg < number_of_vregs; ++vreg) {
       if (updated_vregs != nullptr && updated_vregs[vreg]) {
diff --git a/runtime/stack.cc b/runtime/stack.cc
index 0b3441a..56e47b9 100644
--- a/runtime/stack.cc
+++ b/runtime/stack.cc
@@ -236,14 +236,12 @@
   size_t depth_in_stack_map = current_inlining_depth_ - 1;
 
   DexRegisterMap dex_register_map = IsInInlinedFrame()
-      ? code_info.GetDexRegisterMapAtDepth(depth_in_stack_map,
-                                           stack_map,
-                                           number_of_dex_registers)
-      : code_info.GetDexRegisterMapOf(stack_map, number_of_dex_registers);
-
-  if (!dex_register_map.IsValid()) {
+      ? code_info.GetDexRegisterMapAtDepth(depth_in_stack_map, stack_map)
+      : code_info.GetDexRegisterMapOf(stack_map);
+  if (dex_register_map.empty()) {
     return false;
   }
+  DCHECK_EQ(dex_register_map.size(), number_of_dex_registers);
   DexRegisterLocation::Kind location_kind = dex_register_map.GetLocationKind(vreg);
   switch (location_kind) {
     case DexRegisterLocation::Kind::kInStack: {
diff --git a/runtime/stack_map.cc b/runtime/stack_map.cc
index 59a89e1..a25c9fd 100644
--- a/runtime/stack_map.cc
+++ b/runtime/stack_map.cc
@@ -115,7 +115,7 @@
 
 static void DumpDexRegisterMap(VariableIndentationOutputStream* vios,
                                const DexRegisterMap& map) {
-  if (map.IsValid()) {
+  if (!map.empty()) {
     ScopedIndentation indent1(vios);
     for (size_t i = 0; i < map.size(); ++i) {
       if (map.IsDexRegisterLive(i)) {
@@ -163,7 +163,6 @@
 
 void CodeInfo::Dump(VariableIndentationOutputStream* vios,
                     uint32_t code_offset,
-                    uint16_t num_dex_registers,
                     bool verbose,
                     InstructionSet instruction_set,
                     const MethodInfo& method_info) const {
@@ -185,7 +184,7 @@
   if (verbose) {
     for (size_t i = 0; i < GetNumberOfStackMaps(); ++i) {
       StackMap stack_map = GetStackMapAt(i);
-      stack_map.Dump(vios, *this, method_info, code_offset, num_dex_registers, instruction_set);
+      stack_map.Dump(vios, *this, method_info, code_offset, instruction_set);
     }
   }
 }
@@ -194,7 +193,6 @@
                     const CodeInfo& code_info,
                     const MethodInfo& method_info,
                     uint32_t code_offset,
-                    uint16_t number_of_dex_registers,
                     InstructionSet instruction_set) const {
   const uint32_t pc_offset = GetNativePcOffset(instruction_set);
   vios->Stream()
@@ -210,22 +208,18 @@
     vios->Stream() << stack_mask.LoadBit(e - i - 1);
   }
   vios->Stream() << ")\n";
-  DumpDexRegisterMap(vios, code_info.GetDexRegisterMapOf(*this, number_of_dex_registers));
+  DumpDexRegisterMap(vios, code_info.GetDexRegisterMapOf(*this));
   uint32_t depth = code_info.GetInlineDepthOf(*this);
   for (size_t d = 0; d < depth; d++) {
     InlineInfo inline_info = code_info.GetInlineInfoAtDepth(*this, d);
-    // We do not know the length of the dex register maps of inlined frames
-    // at this level, so we just pass null to `InlineInfo::Dump` to tell
-    // it not to look at these maps.
-    inline_info.Dump(vios, code_info, *this, method_info, 0);
+    inline_info.Dump(vios, code_info, *this, method_info);
   }
 }
 
 void InlineInfo::Dump(VariableIndentationOutputStream* vios,
                       const CodeInfo& code_info,
                       const StackMap& stack_map,
-                      const MethodInfo& method_info,
-                      uint16_t number_of_dex_registers) const {
+                      const MethodInfo& method_info) const {
   uint32_t depth = Row() - stack_map.GetInlineInfoIndex();
   vios->Stream()
       << "InlineInfo[" << Row() << "]"
@@ -241,10 +235,7 @@
         << ", method_index=" << GetMethodIndex(method_info);
   }
   vios->Stream() << ")\n";
-  if (number_of_dex_registers != 0) {
-    uint16_t vregs = number_of_dex_registers;
-    DumpDexRegisterMap(vios, code_info.GetDexRegisterMapAtDepth(depth, stack_map, vregs));
-  }
+  DumpDexRegisterMap(vios, code_info.GetDexRegisterMapAtDepth(depth, stack_map));
 }
 
 }  // namespace art
diff --git a/runtime/stack_map.h b/runtime/stack_map.h
index ff70b6c..53f80e5 100644
--- a/runtime/stack_map.h
+++ b/runtime/stack_map.h
@@ -75,7 +75,7 @@
 
   size_t size() const { return count_; }
 
-  bool IsValid() const { return count_ != 0; }
+  bool empty() const { return count_ == 0; }
 
   DexRegisterLocation Get(size_t index) const {
     DCHECK_LT(index, count_);
@@ -194,7 +194,6 @@
             const CodeInfo& code_info,
             const MethodInfo& method_info,
             uint32_t code_offset,
-            uint16_t number_of_dex_registers,
             InstructionSet instruction_set) const;
 };
 
@@ -234,8 +233,7 @@
   void Dump(VariableIndentationOutputStream* vios,
             const CodeInfo& info,
             const StackMap& stack_map,
-            const MethodInfo& method_info,
-            uint16_t number_of_dex_registers) const;
+            const MethodInfo& method_info) const;
 };
 
 class InvokeInfo : public BitTable<3>::Accessor {
@@ -358,8 +356,7 @@
     return InvokeInfo(&invoke_infos_, index);
   }
 
-  ALWAYS_INLINE DexRegisterMap GetDexRegisterMapOf(StackMap stack_map,
-                                                   size_t vregs ATTRIBUTE_UNUSED = 0) const {
+  ALWAYS_INLINE DexRegisterMap GetDexRegisterMapOf(StackMap stack_map) const {
     if (stack_map.HasDexRegisterMap()) {
       DexRegisterMap map(number_of_dex_registers_, DexRegisterLocation::Invalid());
       DecodeDexRegisterMap(stack_map.Row(), /* first_dex_register */ 0, &map);
@@ -368,9 +365,7 @@
     return DexRegisterMap(0, DexRegisterLocation::None());
   }
 
-  ALWAYS_INLINE DexRegisterMap GetDexRegisterMapAtDepth(uint8_t depth,
-                                                        StackMap stack_map,
-                                                        size_t vregs ATTRIBUTE_UNUSED = 0) const {
+  ALWAYS_INLINE DexRegisterMap GetDexRegisterMapAtDepth(uint8_t depth, StackMap stack_map) const {
     if (stack_map.HasDexRegisterMap()) {
       // The register counts are commutative and include all outer levels.
       // This allows us to determine the range [first, last) in just two lookups.
@@ -481,7 +476,6 @@
   // `code_offset` is the (absolute) native PC of the compiled method.
   void Dump(VariableIndentationOutputStream* vios,
             uint32_t code_offset,
-            uint16_t number_of_dex_registers,
             bool verbose,
             InstructionSet instruction_set,
             const MethodInfo& method_info) const;
diff --git a/runtime/thread.cc b/runtime/thread.cc
index b59606a..bb4f186 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -3656,8 +3656,7 @@
                        RootVisitor& _visitor)
           : number_of_dex_registers(method->DexInstructionData().RegistersSize()),
             code_info(_code_info),
-            dex_register_map(code_info.GetDexRegisterMapOf(map,
-                                                           number_of_dex_registers)),
+            dex_register_map(code_info.GetDexRegisterMapOf(map)),
             visitor(_visitor) {
       }