Fix up TODO: c++0x, update cpplint.

Needed to update cpplint to handle const auto.

Fixed a few cpplint errors that were being missed before.

Replaced most of the TODO c++0x with ranged based loops. Loops which
do not have a descriptive container name have a concrete type instead
of auto.

Change-Id: Id7cc0f27030f56057c544e94277300b3f298c9c5
diff --git a/runtime/gc/collector/garbage_collector.cc b/runtime/gc/collector/garbage_collector.cc
index 378a971..9260137 100644
--- a/runtime/gc/collector/garbage_collector.cc
+++ b/runtime/gc/collector/garbage_collector.cc
@@ -114,11 +114,7 @@
   // these bitmaps. The bitmap swapping is an optimization so that we do not need to clear the live
   // bits of dead objects in the live bitmap.
   const GcType gc_type = GetGcType();
-  const std::vector<space::ContinuousSpace*>& cont_spaces = GetHeap()->GetContinuousSpaces();
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = cont_spaces.begin(), end = cont_spaces.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
     // We never allocate into zygote spaces.
     if (space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect ||
         (gc_type == kGcTypeFull &&
@@ -132,11 +128,8 @@
       }
     }
   }
-  const std::vector<space::DiscontinuousSpace*>& disc_spaces = GetHeap()->GetDiscontinuousSpaces();
-  // TODO: C++0x
-  typedef std::vector<space::DiscontinuousSpace*>::const_iterator It2;
-  for (It2 it = disc_spaces.begin(), end = disc_spaces.end(); it != end; ++it) {
-    space::LargeObjectSpace* space = down_cast<space::LargeObjectSpace*>(*it);
+  for (const auto& disc_space : GetHeap()->GetDiscontinuousSpaces()) {
+    space::LargeObjectSpace* space = down_cast<space::LargeObjectSpace*>(disc_space);
     accounting::SpaceSetMap* live_set = space->GetLiveObjects();
     accounting::SpaceSetMap* mark_set = space->GetMarkObjects();
     heap_->GetLiveBitmap()->ReplaceObjectSet(live_set, mark_set);
diff --git a/runtime/gc/collector/mark_sweep.cc b/runtime/gc/collector/mark_sweep.cc
index 61570ae..e93bcd1 100644
--- a/runtime/gc/collector/mark_sweep.cc
+++ b/runtime/gc/collector/mark_sweep.cc
@@ -84,16 +84,13 @@
     SetImmuneRange(reinterpret_cast<Object*>(space->Begin()),
                    reinterpret_cast<Object*>(space->End()));
   } else {
-    const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
-    const space::ContinuousSpace* prev_space = NULL;
+    const space::ContinuousSpace* prev_space = nullptr;
     // Find out if the previous space is immune.
-    // TODO: C++0x
-    typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-    for (It it = spaces.begin(), end = spaces.end(); it != end; ++it) {
-      if (*it == space) {
+    for (space::ContinuousSpace* cur_space : GetHeap()->GetContinuousSpaces()) {
+      if (cur_space == space) {
         break;
       }
-      prev_space = *it;
+      prev_space = cur_space;
     }
 
     // If previous space was immune, then extend the immune region. Relies on continuous spaces
@@ -322,13 +319,9 @@
 
 void MarkSweep::FindDefaultMarkBitmap() {
   base::TimingLogger::ScopedSplit split("FindDefaultMarkBitmap", &timings_);
-  const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = spaces.begin(), end = spaces.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
     if (space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect) {
-      current_mark_bitmap_ = (*it)->GetMarkBitmap();
+      current_mark_bitmap_ = space->GetMarkBitmap();
       CHECK(current_mark_bitmap_ != NULL);
       return;
     }
@@ -344,11 +337,10 @@
     // Someone else acquired the lock and expanded the mark stack before us.
     return;
   }
-  std::vector<Object*> temp;
-  temp.insert(temp.begin(), mark_stack_->Begin(), mark_stack_->End());
+  std::vector<Object*> temp(mark_stack_->Begin(), mark_stack_->End());
   mark_stack_->Resize(mark_stack_->Capacity() * 2);
-  for (size_t i = 0; i < temp.size(); ++i) {
-    mark_stack_->PushBack(temp[i]);
+  for (const auto& obj : temp) {
+    mark_stack_->PushBack(obj);
   }
 }
 
@@ -608,12 +600,8 @@
 
 void MarkSweep::ScanGrayObjects(byte minimum_age) {
   accounting::CardTable* card_table = GetHeap()->GetCardTable();
-  const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
   ScanObjectVisitor visitor(this);
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = spaces.begin(), space_end = spaces.end(); it != space_end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
     switch (space->GetGcRetentionPolicy()) {
       case space::kGcRetentionPolicyNeverCollect:
         timings_.StartSplit("ScanGrayImageSpaceObjects");
@@ -656,15 +644,12 @@
   // space
   timings_.StartSplit("VerifyImageRoots");
   CheckBitmapVisitor visitor(this);
-  const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = spaces.begin(), end = spaces.end(); it != end; ++it) {
-    if ((*it)->IsImageSpace()) {
-      space::ImageSpace* space = (*it)->AsImageSpace();
-      uintptr_t begin = reinterpret_cast<uintptr_t>(space->Begin());
-      uintptr_t end = reinterpret_cast<uintptr_t>(space->End());
-      accounting::SpaceBitmap* live_bitmap = space->GetLiveBitmap();
+  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
+    if (space->IsImageSpace()) {
+      space::ImageSpace* image_space = space->AsImageSpace();
+      uintptr_t begin = reinterpret_cast<uintptr_t>(image_space->Begin());
+      uintptr_t end = reinterpret_cast<uintptr_t>(image_space->End());
+      accounting::SpaceBitmap* live_bitmap = image_space->GetLiveBitmap();
       DCHECK(live_bitmap != NULL);
       live_bitmap->VisitMarkedRange(begin, end, visitor);
     }
@@ -687,11 +672,7 @@
   const bool partial = GetGcType() == kGcTypePartial;
   ScanObjectVisitor scan_visitor(this);
   if (!kDisableFinger) {
-    const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
-    // TODO: C++0x
-    typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-    for (It it = spaces.begin(), end = spaces.end(); it != end; ++it) {
-      space::ContinuousSpace* space = *it;
+    for (const auto& space : GetHeap()->GetContinuousSpaces()) {
       if ((space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect) ||
           (!partial && space->GetGcRetentionPolicy() == space::kGcRetentionPolicyFullCollect)) {
         current_mark_bitmap_ = space->GetMarkBitmap();
@@ -729,10 +710,7 @@
 void MarkSweep::SweepJniWeakGlobals(IsMarkedTester is_marked, void* arg) {
   JavaVMExt* vm = Runtime::Current()->GetJavaVM();
   MutexLock mu(Thread::Current(), vm->weak_globals_lock);
-  IndirectReferenceTable* table = &vm->weak_globals;
-  typedef IndirectReferenceTable::iterator It;  // TODO: C++0x auto
-  for (It it = table->begin(), end = table->end(); it != end; ++it) {
-    const Object** entry = *it;
+  for (const Object** entry : vm->weak_globals) {
     if (!is_marked(*entry, arg)) {
       *entry = kClearedJniWeakGlobal;
     }
@@ -815,10 +793,7 @@
 
   JavaVMExt* vm = runtime->GetJavaVM();
   MutexLock mu(Thread::Current(), vm->weak_globals_lock);
-  IndirectReferenceTable* table = &vm->weak_globals;
-  typedef IndirectReferenceTable::iterator It;  // TODO: C++0x auto
-  for (It it = table->begin(), end = table->end(); it != end; ++it) {
-    const Object** entry = *it;
+  for (const Object** entry : vm->weak_globals) {
     VerifyIsLive(*entry);
   }
 }
@@ -988,11 +963,7 @@
   SweepCallbackContext scc;
   scc.mark_sweep = this;
   scc.self = Thread::Current();
-  const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = spaces.begin(), end = spaces.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
     // We always sweep always collect spaces.
     bool sweep_space = (space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect);
     if (!partial && !sweep_space) {
@@ -1040,11 +1011,9 @@
   size_t freed_objects = 0;
   size_t freed_bytes = 0;
   Thread* self = Thread::Current();
-  // TODO: C++0x
-  typedef accounting::SpaceSetMap::Objects::iterator It;
-  for (It it = live_objects.begin(), end = live_objects.end(); it != end; ++it) {
-    if (!large_mark_objects->Test(*it)) {
-      freed_bytes += large_object_space->Free(self, const_cast<Object*>(*it));
+  for (const Object* obj : live_objects) {
+    if (!large_mark_objects->Test(obj)) {
+      freed_bytes += large_object_space->Free(self, const_cast<Object*>(obj));
       ++freed_objects;
     }
   }
@@ -1054,11 +1023,7 @@
 }
 
 void MarkSweep::CheckReference(const Object* obj, const Object* ref, MemberOffset offset, bool is_static) {
-  const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = spaces.begin(), end = spaces.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
     if (space->IsDlMallocSpace() && space->Contains(ref)) {
       DCHECK(IsMarked(obj));
 
@@ -1508,11 +1473,7 @@
 
 void MarkSweep::UnBindBitmaps() {
   base::TimingLogger::ScopedSplit split("UnBindBitmaps", &timings_);
-  const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = spaces.begin(), end = spaces.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
     if (space->IsDlMallocSpace()) {
       space::DlMallocSpace* alloc_space = space->AsDlMallocSpace();
       if (alloc_space->temp_bitmap_.get() != NULL) {
@@ -1585,11 +1546,7 @@
   cumulative_timings_.End();
 
   // Clear all of the spaces' mark bitmaps.
-  const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = spaces.begin(), end = spaces.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
     if (space->GetGcRetentionPolicy() != space::kGcRetentionPolicyNeverCollect) {
       space->GetMarkBitmap()->Clear();
     }
diff --git a/runtime/gc/collector/mark_sweep.h b/runtime/gc/collector/mark_sweep.h
index e39e2f7..8db03d3 100644
--- a/runtime/gc/collector/mark_sweep.h
+++ b/runtime/gc/collector/mark_sweep.h
@@ -428,6 +428,7 @@
 
   bool clear_soft_references_;
 
+ private:
   friend class AddIfReachesAllocSpaceVisitor;  // Used by mod-union table.
   friend class CheckBitmapVisitor;
   friend class CheckObjectVisitor;
diff --git a/runtime/gc/collector/partial_mark_sweep.cc b/runtime/gc/collector/partial_mark_sweep.cc
index ef893c5..cc3cfe5 100644
--- a/runtime/gc/collector/partial_mark_sweep.cc
+++ b/runtime/gc/collector/partial_mark_sweep.cc
@@ -33,14 +33,10 @@
 void PartialMarkSweep::BindBitmaps() {
   MarkSweep::BindBitmaps();
 
-  const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
   WriterMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_);
   // For partial GCs we need to bind the bitmap of the zygote space so that all objects in the
   // zygote space are viewed as marked.
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = spaces.begin(), end = spaces.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
     if (space->GetGcRetentionPolicy() == space::kGcRetentionPolicyFullCollect) {
       CHECK(space->IsZygoteSpace());
       ImmuneSpace(space);
diff --git a/runtime/gc/collector/partial_mark_sweep.h b/runtime/gc/collector/partial_mark_sweep.h
index 25304b9..3b788f4 100644
--- a/runtime/gc/collector/partial_mark_sweep.h
+++ b/runtime/gc/collector/partial_mark_sweep.h
@@ -38,6 +38,7 @@
   // collections, ie the Zygote space. Also mark this space is immune.
   virtual void BindBitmaps() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
 
+ private:
   DISALLOW_COPY_AND_ASSIGN(PartialMarkSweep);
 };
 
diff --git a/runtime/gc/collector/sticky_mark_sweep.cc b/runtime/gc/collector/sticky_mark_sweep.cc
index aad7c29..008d3e0 100644
--- a/runtime/gc/collector/sticky_mark_sweep.cc
+++ b/runtime/gc/collector/sticky_mark_sweep.cc
@@ -33,15 +33,11 @@
 void StickyMarkSweep::BindBitmaps() {
   PartialMarkSweep::BindBitmaps();
 
-  const std::vector<space::ContinuousSpace*>& spaces = GetHeap()->GetContinuousSpaces();
   WriterMutexLock mu(Thread::Current(), *Locks::heap_bitmap_lock_);
   // For sticky GC, we want to bind the bitmaps of all spaces as the allocation stack lets us
   // know what was allocated since the last GC. A side-effect of binding the allocation space mark
   // and live bitmap is that marking the objects will place them in the live bitmap.
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = spaces.begin(), end = spaces.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : GetHeap()->GetContinuousSpaces()) {
     if (space->GetGcRetentionPolicy() == space::kGcRetentionPolicyAlwaysCollect) {
       BindLiveToMarkBitmap(space);
     }
diff --git a/runtime/gc/collector/sticky_mark_sweep.h b/runtime/gc/collector/sticky_mark_sweep.h
index e009b62..2099c79 100644
--- a/runtime/gc/collector/sticky_mark_sweep.h
+++ b/runtime/gc/collector/sticky_mark_sweep.h
@@ -45,6 +45,7 @@
 
   void Sweep(bool swap_bitmaps) EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_);
 
+ private:
   DISALLOW_COPY_AND_ASSIGN(StickyMarkSweep);
 };