Clean up shadow frame.

Created version of GetThisObject that takes num_ins to get the object
without having to get the code item again. Also using memset to clear
the registers on initialization.

Change-Id: I02b255f0c47d2d3c55783f4c96dc93983015f019
diff --git a/src/interpreter/interpreter.cc b/src/interpreter/interpreter.cc
index bce2ed2..2e87dfd 100644
--- a/src/interpreter/interpreter.cc
+++ b/src/interpreter/interpreter.cc
@@ -725,7 +725,7 @@
   // As the 'this' object won't change during the execution of current code, we
   // want to cache it in local variables. Nevertheless, in order to let the
   // garbage collector access it, we store it into sirt references.
-  SirtRef<Object> this_object_ref(self, shadow_frame.GetThisObject());
+  SirtRef<Object> this_object_ref(self, shadow_frame.GetThisObject(code_item->ins_size_));
 
   const Instruction* inst = Instruction::At(insns + shadow_frame.GetDexPC());
   if (inst->GetDexPc(insns) == 0) {  // We are entering the method as opposed to deoptimizing..
diff --git a/src/stack.cc b/src/stack.cc
index 8690a36..c32b822 100644
--- a/src/stack.cc
+++ b/src/stack.cc
@@ -42,6 +42,15 @@
   }
 }
 
+mirror::Object* ShadowFrame::GetThisObject(uint16_t num_ins) const {
+  mirror::AbstractMethod* m = GetMethod();
+  if (m->IsStatic()) {
+    return NULL;
+  } else {
+    return GetVRegReference(number_of_vregs_ - num_ins);
+  }
+}
+
 ThrowLocation ShadowFrame::GetCurrentLocationForThrow() const {
   return ThrowLocation(GetThisObject(), GetMethod(), GetDexPC());
 }
diff --git a/src/stack.h b/src/stack.h
index 1b4d285..fbfacb1 100644
--- a/src/stack.h
+++ b/src/stack.h
@@ -202,6 +202,8 @@
 
   mirror::Object* GetThisObject() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
+  mirror::Object* GetThisObject(uint16_t num_ins) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+
   ThrowLocation GetCurrentLocationForThrow() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
   void SetMethod(mirror::AbstractMethod* method) {
@@ -254,13 +256,9 @@
       CHECK_LT(num_vregs, static_cast<uint32_t>(kHasReferenceArray));
       number_of_vregs_ |= kHasReferenceArray;
 #endif
-      for (size_t i = 0; i < num_vregs; ++i) {
-        SetVRegReference(i, NULL);
-      }
+      memset(vregs_, 0, num_vregs * (sizeof(uint32_t) + sizeof(mirror::Object*)));
     } else {
-      for (size_t i = 0; i < num_vregs; ++i) {
-        SetVReg(i, 0);
-      }
+      memset(vregs_, 0, num_vregs * sizeof(uint32_t));
     }
   }