Fix some ArtMethod related bugs

Added root visiting for runtime methods, not currently required
since the GcRoots in these methods are null.

Added missing GetInterfaceMethodIfProxy in GetMethodLine, fixes
--trace run-tests 005, 044.

Fixed optimizing compiler bug where we used a normal stack location
instead of double on ARM64, this fixes the debuggable tests.

TODO: Fix JDWP tests.

Bug: 19264997

Change-Id: I7c55f69c61d1b45351fd0dc7185ffe5efad82bd3
diff --git a/compiler/optimizing/code_generator.cc b/compiler/optimizing/code_generator.cc
index c106d30..0cd63a6 100644
--- a/compiler/optimizing/code_generator.cc
+++ b/compiler/optimizing/code_generator.cc
@@ -124,13 +124,14 @@
   if (!is_leaf) {
     MarkNotLeaf();
   }
+  const bool is_64_bit = Is64BitInstructionSet(GetInstructionSet());
   InitializeCodeGeneration(GetGraph()->GetNumberOfLocalVRegs()
                              + GetGraph()->GetTemporariesVRegSlots()
                              + 1 /* filler */,
                            0, /* the baseline compiler does not have live registers at slow path */
                            0, /* the baseline compiler does not have live registers at slow path */
                            GetGraph()->GetMaximumNumberOfOutVRegs()
-                             + 1 /* current method */,
+                             + (is_64_bit ? 2 : 1) /* current method */,
                            GetGraph()->GetBlocks());
   CompileInternal(allocator, /* is_baseline */ true);
 }
diff --git a/compiler/optimizing/code_generator_arm64.cc b/compiler/optimizing/code_generator_arm64.cc
index fbe26b0..40432e4 100644
--- a/compiler/optimizing/code_generator_arm64.cc
+++ b/compiler/optimizing/code_generator_arm64.cc
@@ -637,7 +637,7 @@
   DCHECK_NE(type, Primitive::kPrimVoid);
 
   if (instruction->IsCurrentMethod()) {
-    MoveLocation(location, Location::StackSlot(kCurrentMethodStackOffset));
+    MoveLocation(location, Location::DoubleStackSlot(kCurrentMethodStackOffset));
   } else if (locations != nullptr && locations->Out().Equals(location)) {
     return;
   } else if (instruction->IsIntConstant()
diff --git a/compiler/optimizing/code_generator_x86_64.cc b/compiler/optimizing/code_generator_x86_64.cc
index 59a9565..78d5851 100644
--- a/compiler/optimizing/code_generator_x86_64.cc
+++ b/compiler/optimizing/code_generator_x86_64.cc
@@ -692,7 +692,7 @@
                                HInstruction* move_for) {
   LocationSummary* locations = instruction->GetLocations();
   if (instruction->IsCurrentMethod()) {
-    Move(location, Location::StackSlot(kCurrentMethodStackOffset));
+    Move(location, Location::DoubleStackSlot(kCurrentMethodStackOffset));
   } else if (locations != nullptr && locations->Out().Equals(location)) {
     return;
   } else if (locations != nullptr && locations->Out().IsConstant()) {
diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h
index ad1ecea..5cfce41 100644
--- a/runtime/art_method-inl.h
+++ b/runtime/art_method-inl.h
@@ -484,9 +484,9 @@
 
 template<typename RootVisitorType>
 void ArtMethod::VisitRoots(RootVisitorType& visitor) {
-  visitor.VisitRoot(declaring_class_.AddressWithoutBarrier());
-  visitor.VisitRoot(dex_cache_resolved_methods_.AddressWithoutBarrier());
-  visitor.VisitRoot(dex_cache_resolved_types_.AddressWithoutBarrier());
+  visitor.VisitRootIfNonNull(declaring_class_.AddressWithoutBarrier());
+  visitor.VisitRootIfNonNull(dex_cache_resolved_methods_.AddressWithoutBarrier());
+  visitor.VisitRootIfNonNull(dex_cache_resolved_types_.AddressWithoutBarrier());
 }
 
 inline void ArtMethod::CopyFrom(const ArtMethod* src, size_t image_pointer_size) {
diff --git a/runtime/runtime.cc b/runtime/runtime.cc
index 81846df..65ea77a 100644
--- a/runtime/runtime.cc
+++ b/runtime/runtime.cc
@@ -1329,6 +1329,24 @@
   mirror::PrimitiveArray<int32_t>::VisitRoots(visitor);   // IntArray
   mirror::PrimitiveArray<int64_t>::VisitRoots(visitor);   // LongArray
   mirror::PrimitiveArray<int16_t>::VisitRoots(visitor);   // ShortArray
+  // Visiting the roots of these ArtMethods is not currently required since all the GcRoots are
+  // null.
+  BufferedRootVisitor<16> buffered_visitor(visitor, RootInfo(kRootVMInternal));
+  if (HasResolutionMethod()) {
+    resolution_method_->VisitRoots(buffered_visitor);
+  }
+  if (HasImtConflictMethod()) {
+    imt_conflict_method_->VisitRoots(buffered_visitor);
+  }
+  if (imt_unimplemented_method_ != nullptr) {
+    imt_unimplemented_method_->VisitRoots(buffered_visitor);
+  }
+  for (size_t i = 0; i < kLastCalleeSaveType; ++i) {
+    auto* m = reinterpret_cast<ArtMethod*>(callee_save_methods_[i]);
+    if (m != nullptr) {
+      m->VisitRoots(buffered_visitor);
+    }
+  }
 }
 
 void Runtime::VisitConcurrentRoots(RootVisitor* visitor, VisitRootFlags flags) {
diff --git a/runtime/trace.cc b/runtime/trace.cc
index 13efb53..d3b3af8 100644
--- a/runtime/trace.cc
+++ b/runtime/trace.cc
@@ -879,6 +879,7 @@
 
 static std::string GetMethodLine(ArtMethod* method)
     SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+  method = method->GetInterfaceMethodIfProxy(sizeof(void*));
   return StringPrintf("%p\t%s\t%s\t%s\t%s\n", method,
       PrettyDescriptor(method->GetDeclaringClassDescriptor()).c_str(), method->GetName(),
       method->GetSignature().ToString().c_str(), method->GetDeclaringClassSourceFile());