Fix mark stack expand race.

We now guard parallel mark stack pushing with a lock. This is
only used by checkpoint root marking. I did not observe a
significant slowdown by looking at ritzperf and maps, but it may
be worth reinvestigating in the future.

Also a bit of refactoring.

Bug: 10113123

Change-Id: Ifcb12d14df437e2aea9a1165a9568054f80d91b3
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 3178bf1..a454195 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -2209,14 +2209,12 @@
   mapper.WalkStack();
   ReleaseLongJumpContext(context);
 
-  std::deque<instrumentation::InstrumentationStackFrame>* instrumentation_stack = GetInstrumentationStack();
-  typedef std::deque<instrumentation::InstrumentationStackFrame>::const_iterator It;
-  for (It it = instrumentation_stack->begin(), end = instrumentation_stack->end(); it != end; ++it) {
-    mirror::Object* this_object = (*it).this_object_;
+  for (const instrumentation::InstrumentationStackFrame& frame : *GetInstrumentationStack()) {
+    mirror::Object* this_object = frame.this_object_;
     if (this_object != NULL) {
       visitor(this_object, arg);
     }
-    mirror::ArtMethod* method = (*it).method_;
+    mirror::ArtMethod* method = frame.method_;
     visitor(method, arg);
   }
 }