Refactor StackVisitor to take a Thread*.

This allows assertion checking on the thread, principally that we never try to
walk the stack of an unsuspended thread.
Fix bug in the OwnedMonitorVisitor where GetVReg could be called on a
StackVisitor with no context.

Change-Id: I06539b624b253b6fb7385e7be11a4bced1d417b2
diff --git a/test/ReferenceMap/stack_walk_refmap_jni.cc b/test/ReferenceMap/stack_walk_refmap_jni.cc
index 8b1e6cf..60182e2 100644
--- a/test/ReferenceMap/stack_walk_refmap_jni.cc
+++ b/test/ReferenceMap/stack_walk_refmap_jni.cc
@@ -42,10 +42,9 @@
   } while (false)
 
 struct ReferenceMap2Visitor : public StackVisitor {
-  explicit ReferenceMap2Visitor(const ManagedStack* stack,
-                                const std::deque<InstrumentationStackFrame>* instrumentation_stack)
+  explicit ReferenceMap2Visitor(Thread* thread)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
-      : StackVisitor(stack, instrumentation_stack, NULL) {
+      : StackVisitor(thread, NULL) {
   }
 
   bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
@@ -274,9 +273,8 @@
 
 extern "C" JNIEXPORT jint JNICALL Java_ReferenceMap_refmap(JNIEnv*, jobject, jint count) {
   // Visitor
-  ScopedObjectAccess ts(Thread::Current());
-  ReferenceMap2Visitor mapper(Thread::Current()->GetManagedStack(),
-                              Thread::Current()->GetInstrumentationStack());
+  ScopedObjectAccess soa(Thread::Current());
+  ReferenceMap2Visitor mapper(soa.Self());
   mapper.WalkStack();
 
   return count + 1;
diff --git a/test/StackWalk/stack_walk_jni.cc b/test/StackWalk/stack_walk_jni.cc
index 8db36e9..dccd69f 100644
--- a/test/StackWalk/stack_walk_jni.cc
+++ b/test/StackWalk/stack_walk_jni.cc
@@ -40,10 +40,9 @@
 static int gJava_StackWalk_refmap_calls = 0;
 
 struct TestReferenceMapVisitor : public StackVisitor {
-  explicit TestReferenceMapVisitor(const ManagedStack* stack,
-                                   const std::deque<InstrumentationStackFrame>* instrumentation_stack)
+  explicit TestReferenceMapVisitor(Thread* thread)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
-      : StackVisitor(stack, instrumentation_stack, NULL) {
+      : StackVisitor(thread, NULL) {
   }
 
   bool VisitFrame() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
@@ -102,25 +101,23 @@
 };
 
 extern "C" JNIEXPORT jint JNICALL Java_StackWalk_refmap(JNIEnv*, jobject, jint count) {
-  ScopedObjectAccess ts(Thread::Current());
+  ScopedObjectAccess soa(Thread::Current());
   CHECK_EQ(count, 0);
   gJava_StackWalk_refmap_calls++;
 
   // Visitor
-  TestReferenceMapVisitor mapper(Thread::Current()->GetManagedStack(),
-                                 Thread::Current()->GetInstrumentationStack());
+  TestReferenceMapVisitor mapper(soa.Self());
   mapper.WalkStack();
 
   return count + 1;
 }
 
 extern "C" JNIEXPORT jint JNICALL Java_StackWalk2_refmap2(JNIEnv*, jobject, jint count) {
-  ScopedObjectAccess ts(Thread::Current());
+  ScopedObjectAccess soa(Thread::Current());
   gJava_StackWalk_refmap_calls++;
 
   // Visitor
-  TestReferenceMapVisitor mapper(Thread::Current()->GetManagedStack(),
-                                 Thread::Current()->GetInstrumentationStack());
+  TestReferenceMapVisitor mapper(soa.Self());
   mapper.WalkStack();
 
   return count + 1;