Remove zygote space from alloc_spaces_ array.
Not removing this space was causing a crash in
Heap::GetObjectsAllocated since the new zygote bin packing places
objects where the normal DlMalloc/RosAlloc accounting would be.
Going to refactor zygote spaces to be a new space type in the near
future to avoid more of these types of issues.
Bug: 12490061
Change-Id: Id4f75d0315c63e0e8c19f6fba9ad9cb2ba9017e5
diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc
index b2429a4..56e3e00 100644
--- a/runtime/gc/heap.cc
+++ b/runtime/gc/heap.cc
@@ -1414,7 +1414,16 @@
zygote_space->SetGcRetentionPolicy(space::kGcRetentionPolicyFullCollect);
AddSpace(main_space_);
have_zygote_space_ = true;
- zygote_space->InvalidateAllocator();
+ // Remove the zygote space from alloc_spaces_ array since not doing so causes crashes in
+ // GetObjectsAllocated. This happens because the bin packing blows away the internal accounting
+ // stored in between objects.
+ if (zygote_space->IsAllocSpace()) {
+ // TODO: Refactor zygote spaces to be a new space type to avoid more of these types of issues.
+ auto it = std::find(alloc_spaces_.begin(), alloc_spaces_.end(), zygote_space->AsAllocSpace());
+ CHECK(it != alloc_spaces_.end());
+ alloc_spaces_.erase(it);
+ zygote_space->InvalidateAllocator();
+ }
// Create the zygote space mod union table.
accounting::ModUnionTable* mod_union_table =
new accounting::ModUnionTableCardCache("zygote space mod-union table", this, zygote_space);