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/accounting/gc_allocator.cc b/runtime/gc/accounting/gc_allocator.cc
index 0b0d3ed..11d0e67 100644
--- a/runtime/gc/accounting/gc_allocator.cc
+++ b/runtime/gc/accounting/gc_allocator.cc
@@ -31,6 +31,6 @@
     Runtime::Current()->GetHeap()->RegisterGCDeAllocation(bytes);
     free(p);
   }
-}
-}
-}
+}  // namespace accounting
+}  // namespace gc
+}  // namespace art
diff --git a/runtime/gc/accounting/gc_allocator.h b/runtime/gc/accounting/gc_allocator.h
index d1356a7..1fba858 100644
--- a/runtime/gc/accounting/gc_allocator.h
+++ b/runtime/gc/accounting/gc_allocator.h
@@ -75,8 +75,8 @@
                                           GCAllocatorImpl<T>,
                                           std::allocator<T> >::value {
   };
-}
-}
-}
+}  // namespace accounting
+}  // namespace gc
+}  // namespace art
 
 #endif  // ART_RUNTIME_GC_ACCOUNTING_GC_ALLOCATOR_H_
diff --git a/runtime/gc/accounting/heap_bitmap-inl.h b/runtime/gc/accounting/heap_bitmap-inl.h
index 0524ccb..18b93d4 100644
--- a/runtime/gc/accounting/heap_bitmap-inl.h
+++ b/runtime/gc/accounting/heap_bitmap-inl.h
@@ -25,20 +25,12 @@
 
 template <typename Visitor>
 inline void HeapBitmap::Visit(const Visitor& visitor) {
-  // TODO: C++0x auto
-  typedef SpaceBitmapVector::iterator It;
-  for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end();
-      it != end; ++it) {
-    SpaceBitmap* bitmap = *it;
+  for (const auto& bitmap : continuous_space_bitmaps_) {
     bitmap->VisitMarkedRange(bitmap->HeapBegin(), bitmap->HeapLimit(), visitor);
   }
-  // TODO: C++0x auto
-  typedef SpaceSetMapVector::iterator It2;
-  DCHECK(discontinuous_space_sets_.begin() !=  discontinuous_space_sets_.end());
-  for (It2 it = discontinuous_space_sets_.begin(), end = discontinuous_space_sets_.end();
-      it != end; ++it) {
-    SpaceSetMap* set = *it;
-    set->Visit(visitor);
+  DCHECK(!discontinuous_space_sets_.empty());
+  for (const auto& space_set : discontinuous_space_sets_) {
+    space_set->Visit(visitor);
   }
 }
 
diff --git a/runtime/gc/accounting/heap_bitmap.cc b/runtime/gc/accounting/heap_bitmap.cc
index 0462905..5589461 100644
--- a/runtime/gc/accounting/heap_bitmap.cc
+++ b/runtime/gc/accounting/heap_bitmap.cc
@@ -23,12 +23,9 @@
 namespace accounting {
 
 void HeapBitmap::ReplaceBitmap(SpaceBitmap* old_bitmap, SpaceBitmap* new_bitmap) {
-  // TODO: C++0x auto
-  typedef SpaceBitmapVector::iterator It;
-  for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end();
-      it != end; ++it) {
-    if (*it == old_bitmap) {
-      *it = new_bitmap;
+  for (auto& bitmap : continuous_space_bitmaps_) {
+    if (bitmap == old_bitmap) {
+      bitmap = new_bitmap;
       return;
     }
   }
@@ -36,12 +33,9 @@
 }
 
 void HeapBitmap::ReplaceObjectSet(SpaceSetMap* old_set, SpaceSetMap* new_set) {
-  // TODO: C++0x auto
-  typedef SpaceSetMapVector::iterator It;
-  for (It it = discontinuous_space_sets_.begin(), end = discontinuous_space_sets_.end();
-      it != end; ++it) {
-    if (*it == old_set) {
-      *it = new_set;
+  for (auto& space_set : discontinuous_space_sets_) {
+    if (space_set == old_set) {
+      space_set = new_set;
       return;
     }
   }
@@ -52,13 +46,10 @@
   DCHECK(bitmap != NULL);
 
   // Check for interval overlap.
-  typedef SpaceBitmapVector::iterator It;
-  for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end();
-      it != end; ++it) {
-    SpaceBitmap* bitmap = *it;
-    SpaceBitmap* cur_bitmap = *it;
-    CHECK(bitmap->HeapBegin() < cur_bitmap->HeapLimit() &&
-          bitmap->HeapLimit() > cur_bitmap->HeapBegin())
+  for (const auto& cur_bitmap : continuous_space_bitmaps_) {
+    CHECK(!(
+        bitmap->HeapBegin() < cur_bitmap->HeapLimit() &&
+        bitmap->HeapLimit() > cur_bitmap->HeapBegin()))
         << "Bitmap " << bitmap->Dump() << " overlaps with existing bitmap " << cur_bitmap->Dump();
   }
   continuous_space_bitmaps_.push_back(bitmap);
@@ -70,20 +61,13 @@
 }
 
 void HeapBitmap::Walk(SpaceBitmap::Callback* callback, void* arg) {
-  // TODO: C++0x auto
-  typedef SpaceBitmapVector::iterator It;
-  for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end();
-      it != end; ++it) {
-    SpaceBitmap* bitmap = *it;
+  for (const auto& bitmap : continuous_space_bitmaps_) {
     bitmap->Walk(callback, arg);
   }
-  // TODO: C++0x auto
-  typedef SpaceSetMapVector::iterator It2;
-  DCHECK(discontinuous_space_sets_.begin() !=  discontinuous_space_sets_.end());
-  for (It2 it = discontinuous_space_sets_.begin(), end = discontinuous_space_sets_.end();
-      it != end; ++it) {
-    SpaceSetMap* set = *it;
-    set->Walk(callback, arg);
+
+  DCHECK(!discontinuous_space_sets_.empty());
+  for (const auto& space_set : discontinuous_space_sets_) {
+    space_set->Walk(callback, arg);
   }
 }
 
diff --git a/runtime/gc/accounting/heap_bitmap.h b/runtime/gc/accounting/heap_bitmap.h
index ada976f..2ca8c4a 100644
--- a/runtime/gc/accounting/heap_bitmap.h
+++ b/runtime/gc/accounting/heap_bitmap.h
@@ -66,11 +66,7 @@
   }
 
   SpaceBitmap* GetContinuousSpaceBitmap(const mirror::Object* obj) {
-    // TODO: C++0x auto
-    typedef SpaceBitmapVector::iterator It;
-    for (It it = continuous_space_bitmaps_.begin(), end = continuous_space_bitmaps_.end();
-        it != end; ++it) {
-      SpaceBitmap* bitmap = *it;
+    for (const auto& bitmap : continuous_space_bitmaps_) {
       if (bitmap->HasAddress(obj)) {
         return bitmap;
       }
@@ -79,13 +75,9 @@
   }
 
   SpaceSetMap* GetDiscontinuousSpaceObjectSet(const mirror::Object* obj) {
-    // TODO: C++0x auto
-    typedef SpaceSetMapVector::iterator It;
-    for (It it = discontinuous_space_sets_.begin(), end = discontinuous_space_sets_.end();
-        it != end; ++it) {
-      SpaceSetMap* set = *it;
-      if (set->Test(obj)) {
-        return set;
+    for (const auto& space_set : discontinuous_space_sets_) {
+      if (space_set->Test(obj)) {
+        return space_set;
       }
     }
     return NULL;
diff --git a/runtime/gc/accounting/mod_union_table.cc b/runtime/gc/accounting/mod_union_table.cc
index 3bbc381..4865219 100644
--- a/runtime/gc/accounting/mod_union_table.cc
+++ b/runtime/gc/accounting/mod_union_table.cc
@@ -36,54 +36,6 @@
 namespace gc {
 namespace accounting {
 
-class MarkIfReachesAllocspaceVisitor {
- public:
-  explicit MarkIfReachesAllocspaceVisitor(Heap* const heap, accounting::SpaceBitmap* bitmap)
-    : heap_(heap),
-      bitmap_(bitmap) {
-  }
-
-  // Extra parameters are required since we use this same visitor signature for checking objects.
-  void operator()(const Object* obj, const Object* ref, const MemberOffset& /* offset */,
-                  bool /* is_static */) const {
-    // TODO: Optimize?
-    // TODO: C++0x auto
-    const std::vector<space::ContinuousSpace*>& spaces = heap_->GetContinuousSpaces();
-    typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-    for (It cur = spaces.begin(); cur != spaces.end(); ++cur) {
-      if ((*cur)->IsDlMallocSpace() && (*cur)->Contains(ref)) {
-        bitmap_->Set(obj);
-        break;
-      }
-    }
-  }
-
- private:
-  Heap* const heap_;
-  accounting::SpaceBitmap* const bitmap_;
-};
-
-class ModUnionVisitor {
- public:
-  explicit ModUnionVisitor(Heap* const heap, accounting::SpaceBitmap* bitmap)
-    : heap_(heap),
-      bitmap_(bitmap) {
-  }
-
-  void operator()(const Object* obj) const
-      SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_,
-                            Locks::mutator_lock_) {
-    DCHECK(obj != NULL);
-    // We don't have an early exit since we use the visitor pattern, an early exit should
-    // significantly speed this up.
-    MarkIfReachesAllocspaceVisitor visitor(heap_, bitmap_);
-    collector::MarkSweep::VisitObjectReferences(obj, visitor);
-  }
- private:
-  Heap* const heap_;
-  accounting::SpaceBitmap* const bitmap_;
-};
-
 class ModUnionClearCardSetVisitor {
  public:
   explicit ModUnionClearCardSetVisitor(ModUnionTable::CardSet* const cleared_cards)
@@ -237,29 +189,23 @@
 void ModUnionTableReferenceCache::Verify() {
   // Start by checking that everything in the mod union table is marked.
   Heap* heap = GetHeap();
-  typedef SafeMap<const byte*, std::vector<const Object*> >::const_iterator It;
-  typedef std::vector<const Object*>::const_iterator It2;
-  for (It it = references_.begin(), end = references_.end(); it != end; ++it) {
-    for (It2 it_ref = it->second.begin(), end_ref = it->second.end(); it_ref != end_ref;
-        ++it_ref ) {
-      CHECK(heap->IsLiveObjectLocked(*it_ref));
+  for (const std::pair<const byte*, std::vector<const Object*> >& it : references_) {
+    for (const Object* ref : it.second) {
+      CHECK(heap->IsLiveObjectLocked(ref));
     }
   }
 
   // Check the references of each clean card which is also in the mod union table.
   CardTable* card_table = heap->GetCardTable();
-  for (It it = references_.begin(); it != references_.end(); ++it) {
-    const byte* card = &*it->first;
+  for (const std::pair<const byte*, std::vector<const Object*> > & it : references_) {
+    const byte* card = it.first;
     if (*card == CardTable::kCardClean) {
-      std::set<const Object*> reference_set;
-      for (It2 itr = it->second.begin(); itr != it->second.end(); ++itr) {
-        reference_set.insert(*itr);
-      }
+      std::set<const Object*> reference_set(it.second.begin(), it.second.end());
       ModUnionCheckReferences visitor(this, reference_set);
       uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
       uintptr_t end = start + CardTable::kCardSize;
-      space::ContinuousSpace* space =
-          heap->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
+      auto* space = heap->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
+      DCHECK(space != nullptr);
       SpaceBitmap* live_bitmap = space->GetLiveBitmap();
       live_bitmap->VisitMarkedRange(start, end, visitor);
     }
@@ -268,24 +214,20 @@
 
 void ModUnionTableReferenceCache::Dump(std::ostream& os) {
   CardTable* card_table = heap_->GetCardTable();
-  typedef std::set<byte*>::const_iterator It;
   os << "ModUnionTable cleared cards: [";
-  for (It it = cleared_cards_.begin(); it != cleared_cards_.end(); ++it) {
-    byte* card = *it;
-    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
+  for (byte* card_addr : cleared_cards_) {
+    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
     uintptr_t end = start + CardTable::kCardSize;
     os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << ",";
   }
   os << "]\nModUnionTable references: [";
-  typedef SafeMap<const byte*, std::vector<const Object*> >::const_iterator It2;
-  for (It2 it = references_.begin(); it != references_.end(); ++it) {
-    const byte* card = &*it->first;
-    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
+  for (const std::pair<const byte*, std::vector<const Object*> >& it : references_) {
+    const byte* card_addr = it.first;
+    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
     uintptr_t end = start + CardTable::kCardSize;
     os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << "->{";
-    typedef std::vector<const Object*>::const_iterator It3;
-    for (It3 itr = it->second.begin(); itr != it->second.end(); ++itr) {
-      os << reinterpret_cast<const void*>(*itr) << ",";
+    for (const mirror::Object* ref : it.second) {
+      os << reinterpret_cast<const void*>(ref) << ",";
     }
     os << "},";
   }
@@ -298,20 +240,18 @@
   std::vector<const Object*> cards_references;
   ModUnionReferenceVisitor visitor(this, &cards_references);
 
-  typedef std::set<byte*>::iterator It;
-  for (It it = cleared_cards_.begin(), cc_end = cleared_cards_.end(); it != cc_end; ++it) {
-    byte* card = *it;
+  for (const auto& card : cleared_cards_) {
     // Clear and re-compute alloc space references associated with this card.
     cards_references.clear();
     uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
     uintptr_t end = start + CardTable::kCardSize;
-    SpaceBitmap* live_bitmap =
-        heap->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false)->GetLiveBitmap();
+    auto* space = heap->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
+    DCHECK(space != nullptr);
+    SpaceBitmap* live_bitmap = space->GetLiveBitmap();
     live_bitmap->VisitMarkedRange(start, end, visitor);
 
     // Update the corresponding references for the card.
-    // TODO: C++0x auto
-    SafeMap<const byte*, std::vector<const Object*> >::iterator found = references_.find(card);
+    auto found = references_.find(card);
     if (found == references_.end()) {
       if (cards_references.empty()) {
         // No reason to add empty array.
@@ -326,14 +266,11 @@
 }
 
 void ModUnionTableReferenceCache::MarkReferences(collector::MarkSweep* mark_sweep) {
-  // TODO: C++0x auto
   size_t count = 0;
 
-  typedef SafeMap<const byte*, std::vector<const Object*> >::const_iterator It;
-  for (It it = references_.begin(); it != references_.end(); ++it) {
-    typedef std::vector<const Object*>::const_iterator It2;
-    for (It2 it_ref = it->second.begin(); it_ref != it->second.end(); ++it_ref) {
-      mark_sweep->MarkRoot(*it_ref);
+  for (const auto& ref : references_) {
+    for (const auto& obj : ref.second) {
+      mark_sweep->MarkRoot(obj);
       ++count;
     }
   }
@@ -353,38 +290,28 @@
 void ModUnionTableCardCache::MarkReferences(collector::MarkSweep* mark_sweep) {
   CardTable* card_table = heap_->GetCardTable();
   ModUnionScanImageRootVisitor visitor(mark_sweep);
-  typedef std::set<byte*>::const_iterator It;
-  It it = cleared_cards_.begin();
-  It cc_end = cleared_cards_.end();
-  if (it != cc_end) {
-    byte* card = *it;
-    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
-    uintptr_t end = start + CardTable::kCardSize;
-    space::ContinuousSpace* cur_space =
-        heap_->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
-    accounting::SpaceBitmap* cur_live_bitmap = cur_space->GetLiveBitmap();
-    cur_live_bitmap->VisitMarkedRange(start, end, visitor);
-    for (++it; it != cc_end; ++it) {
-      card = *it;
-      start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
-      end = start + CardTable::kCardSize;
-      if (UNLIKELY(!cur_space->Contains(reinterpret_cast<Object*>(start)))) {
-        cur_space = heap_->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
-        cur_live_bitmap = cur_space->GetLiveBitmap();
-      }
-      cur_live_bitmap->VisitMarkedRange(start, end, visitor);
+  space::ContinuousSpace* space = nullptr;
+  SpaceBitmap* bitmap = nullptr;
+  for (const byte* card_addr : cleared_cards_) {
+    auto start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
+    auto end = start + CardTable::kCardSize;
+    auto obj_start = reinterpret_cast<Object*>(start);
+    if (UNLIKELY(space == nullptr || !space->Contains(obj_start))) {
+      space = heap_->FindContinuousSpaceFromObject(obj_start, false);
+      DCHECK(space != nullptr);
+      bitmap = space->GetLiveBitmap();
+      DCHECK(bitmap != nullptr);
     }
+    bitmap->VisitMarkedRange(start, end, visitor);
   }
 }
 
 void ModUnionTableCardCache::Dump(std::ostream& os) {
   CardTable* card_table = heap_->GetCardTable();
-  typedef std::set<byte*>::const_iterator It;
   os << "ModUnionTable dirty cards: [";
-  for (It it = cleared_cards_.begin(); it != cleared_cards_.end(); ++it) {
-    byte* card = *it;
-    uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
-    uintptr_t end = start + CardTable::kCardSize;
+  for (const byte* card_addr : cleared_cards_) {
+    auto start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
+    auto end = start + CardTable::kCardSize;
     os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << ",";
   }
   os << "]";
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);
 };
 
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index a2453b8..d5a8d75 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -183,11 +183,8 @@
     heap_capacity += continuous_spaces_.back()->AsDlMallocSpace()->NonGrowthLimitCapacity();
   }
 
-  // Mark image objects in the live bitmap
-  // TODO: C++0x
-  typedef std::vector<space::ContinuousSpace*>::iterator It;
-  for (It it = continuous_spaces_.begin(); it != continuous_spaces_.end(); ++it) {
-    space::ContinuousSpace* space = *it;
+  // Mark image objects in the live bitmap.
+  for (const auto& space : continuous_spaces_) {
     if (space->IsImageSpace()) {
       space::ImageSpace* image_space = space->AsImageSpace();
       image_space->RecordImageAllocations(image_space->GetLiveBitmap());
@@ -393,9 +390,7 @@
   // Ensure that ImageSpaces < ZygoteSpaces < AllocSpaces so that we can do address based checks to
   // avoid redundant marking.
   bool seen_zygote = false, seen_alloc = false;
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = continuous_spaces_.begin(); it != continuous_spaces_.end(); ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : continuous_spaces_) {
     if (space->IsImageSpace()) {
       DCHECK(!seen_zygote);
       DCHECK(!seen_alloc);
@@ -436,17 +431,13 @@
   uint64_t total_duration = 0;
 
   // Dump cumulative loggers for each GC type.
-  // TODO: C++0x
   uint64_t total_paused_time = 0;
-  typedef std::vector<collector::MarkSweep*>::const_iterator It;
-  for (It it = mark_sweep_collectors_.begin();
-       it != mark_sweep_collectors_.end(); ++it) {
-    collector::MarkSweep* collector = *it;
+  for (const auto& collector : mark_sweep_collectors_) {
     CumulativeLogger& logger = collector->GetCumulativeTimings();
     if (logger.GetTotalNs() != 0) {
       os << Dumpable<CumulativeLogger>(logger);
       const uint64_t total_ns = logger.GetTotalNs();
-      const uint64_t total_pause_ns = (*it)->GetTotalPausedTimeNs();
+      const uint64_t total_pause_ns = collector->GetTotalPausedTimeNs();
       double seconds = NsToMs(logger.GetTotalNs()) / 1000.0;
       const uint64_t freed_bytes = collector->GetTotalFreedBytes();
       const uint64_t freed_objects = collector->GetTotalFreedObjects();
@@ -507,11 +498,9 @@
 
 space::ContinuousSpace* Heap::FindContinuousSpaceFromObject(const mirror::Object* obj,
                                                             bool fail_ok) const {
-  // TODO: C++0x auto
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = continuous_spaces_.begin(), end = continuous_spaces_.end(); it != end; ++it) {
-    if ((*it)->Contains(obj)) {
-      return *it;
+  for (const auto& space : continuous_spaces_) {
+    if (space->Contains(obj)) {
+      return space;
     }
   }
   if (!fail_ok) {
@@ -522,11 +511,9 @@
 
 space::DiscontinuousSpace* Heap::FindDiscontinuousSpaceFromObject(const mirror::Object* obj,
                                                                   bool fail_ok) const {
-  // TODO: C++0x auto
-  typedef std::vector<space::DiscontinuousSpace*>::const_iterator It;
-  for (It it = discontinuous_spaces_.begin(), end = discontinuous_spaces_.end(); it != end; ++it) {
-    if ((*it)->Contains(obj)) {
-      return *it;
+  for (const auto& space : discontinuous_spaces_) {
+    if (space->Contains(obj)) {
+      return space;
     }
   }
   if (!fail_ok) {
@@ -544,11 +531,9 @@
 }
 
 space::ImageSpace* Heap::GetImageSpace() const {
-  // TODO: C++0x auto
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = continuous_spaces_.begin(), end = continuous_spaces_.end(); it != end; ++it) {
-    if ((*it)->IsImageSpace()) {
-      return (*it)->AsImageSpace();
+  for (const auto& space : continuous_spaces_) {
+    if (space->IsImageSpace()) {
+      return space->AsImageSpace();
     }
   }
   return NULL;
@@ -627,10 +612,7 @@
     // If the allocation failed due to fragmentation, print out the largest continuous allocation.
     if (!large_object_allocation && total_bytes_free >= byte_count) {
       size_t max_contiguous_allocation = 0;
-      // TODO: C++0x auto
-      typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-      for (It it = continuous_spaces_.begin(), end = continuous_spaces_.end(); it != end; ++it) {
-        space::ContinuousSpace* space = *it;
+      for (const auto& space : continuous_spaces_) {
         if (space->IsDlMallocSpace()) {
           space->AsDlMallocSpace()->Walk(MSpaceChunkCallback, &max_contiguous_allocation);
         }
@@ -706,19 +688,14 @@
 }
 
 void Heap::DumpSpaces() {
-  // TODO: C++0x auto
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = continuous_spaces_.begin(), end = continuous_spaces_.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : continuous_spaces_) {
     accounting::SpaceBitmap* live_bitmap = space->GetLiveBitmap();
     accounting::SpaceBitmap* mark_bitmap = space->GetMarkBitmap();
     LOG(INFO) << space << " " << *space << "\n"
               << live_bitmap << " " << *live_bitmap << "\n"
               << mark_bitmap << " " << *mark_bitmap;
   }
-  typedef std::vector<space::DiscontinuousSpace*>::const_iterator It2;
-  for (It2 it = discontinuous_spaces_.begin(), end = discontinuous_spaces_.end(); it != end; ++it) {
-    space::DiscontinuousSpace* space = *it;
+  for (const auto& space : discontinuous_spaces_) {
     LOG(INFO) << space << " " << *space << "\n";
   }
 }
@@ -1143,11 +1120,8 @@
   have_zygote_space_ = true;
 
   // Reset the cumulative loggers since we now have a few additional timing phases.
-  // TODO: C++0x
-  typedef std::vector<collector::MarkSweep*>::const_iterator It;
-  for (It it = mark_sweep_collectors_.begin(), end = mark_sweep_collectors_.end();
-      it != end; ++it) {
-    (*it)->ResetCumulativeStatistics();
+  for (const auto& collector : mark_sweep_collectors_) {
+    collector->ResetCumulativeStatistics();
   }
 }
 
@@ -1238,10 +1212,7 @@
   ATRACE_BEGIN(gc_cause_and_type_strings[gc_cause][gc_type]);
 
   collector::MarkSweep* collector = NULL;
-  typedef std::vector<collector::MarkSweep*>::iterator It;
-  for (It it = mark_sweep_collectors_.begin(), end = mark_sweep_collectors_.end();
-      it != end; ++it) {
-    collector::MarkSweep* cur_collector = *it;
+  for (const auto& cur_collector : mark_sweep_collectors_) {
     if (cur_collector->IsConcurrent() == concurrent_gc_ && cur_collector->GetGcType() == gc_type) {
       collector = cur_collector;
       break;
@@ -1596,9 +1567,7 @@
 
 void Heap::ProcessCards(base::TimingLogger& timings) {
   // Clear cards and keep track of cards cleared in the mod-union table.
-  typedef std::vector<space::ContinuousSpace*>::iterator It;
-  for (It it = continuous_spaces_.begin(), end = continuous_spaces_.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : continuous_spaces_) {
     if (space->IsImageSpace()) {
       base::TimingLogger::ScopedSplit split("ImageModUnionClearCards", &timings);
       image_mod_union_table_->ClearCards(space);
@@ -2085,9 +2054,7 @@
 
 int64_t Heap::GetTotalMemory() const {
   int64_t ret = 0;
-  typedef std::vector<space::ContinuousSpace*>::const_iterator It;
-  for (It it = continuous_spaces_.begin(), end = continuous_spaces_.end(); it != end; ++it) {
-    space::ContinuousSpace* space = *it;
+  for (const auto& space : continuous_spaces_) {
     if (space->IsImageSpace()) {
       // Currently don't include the image space.
     } else if (space->IsDlMallocSpace()) {
@@ -2095,9 +2062,7 @@
       ret += space->AsDlMallocSpace()->GetFootprint();
     }
   }
-  typedef std::vector<space::DiscontinuousSpace*>::const_iterator It2;
-  for (It2 it = discontinuous_spaces_.begin(), end = discontinuous_spaces_.end(); it != end; ++it) {
-    space::DiscontinuousSpace* space = *it;
+  for (const auto& space : discontinuous_spaces_) {
     if (space->IsLargeObjectSpace()) {
       ret += space->AsLargeObjectSpace()->GetBytesAllocated();
     }