From 2796a1669ae0f3b96db8432fbd8be1b93bf335c4 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Fri, 25 Jul 2014 11:50:47 -0700 Subject: Fix main space memory leak and add checks. The hypothesis is that we were leaking the main space and its bitmaps, then eventually we would run out of virtual address space, which would cause a null bitmap (DCHECK). Finally when we tried adding the space with a null bitmap to the heap bitmap it segfaulted. Changed some non performance critical DCHECK -> CHECK. Bug: 16563323 Change-Id: I08a1f873752e28ebcf63ebbd90f92d994d7ca96b --- runtime/gc/heap.cc | 15 ++++++++------- runtime/gc/space/malloc_space.cc | 4 ++-- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/runtime/gc/heap.cc b/runtime/gc/heap.cc index 33ff3bb1f2..1d80833b63 100644 --- a/runtime/gc/heap.cc +++ b/runtime/gc/heap.cc @@ -692,7 +692,7 @@ void Heap::AddSpace(space::Space* space) { accounting::ContinuousSpaceBitmap* live_bitmap = continuous_space->GetLiveBitmap(); accounting::ContinuousSpaceBitmap* mark_bitmap = continuous_space->GetMarkBitmap(); if (live_bitmap != nullptr) { - DCHECK(mark_bitmap != nullptr); + CHECK(mark_bitmap != nullptr); live_bitmap_->AddContinuousSpaceBitmap(live_bitmap); mark_bitmap_->AddContinuousSpaceBitmap(mark_bitmap); } @@ -703,7 +703,7 @@ void Heap::AddSpace(space::Space* space) { return a->Begin() < b->Begin(); }); } else { - DCHECK(space->IsDiscontinuousSpace()); + CHECK(space->IsDiscontinuousSpace()); space::DiscontinuousSpace* discontinuous_space = space->AsDiscontinuousSpace(); live_bitmap_->AddLargeObjectBitmap(discontinuous_space->GetLiveBitmap()); mark_bitmap_->AddLargeObjectBitmap(discontinuous_space->GetMarkBitmap()); @@ -1595,19 +1595,20 @@ void Heap::TransitionCollector(CollectorType collector_type) { Compact(bump_pointer_space_, main_space_, kGcCauseCollectorTransition); // Use the now empty main space mem map for the bump pointer temp space. mem_map.reset(main_space_->ReleaseMemMap()); - // Remove the main space so that we don't try to trim it, this doens't work for debug - // builds since RosAlloc attempts to read the magic number from a protected page. - RemoveSpace(main_space_); // Unset the pointers just in case. if (dlmalloc_space_ == main_space_) { dlmalloc_space_ = nullptr; } else if (rosalloc_space_ == main_space_) { rosalloc_space_ = nullptr; } + // Remove the main space so that we don't try to trim it, this doens't work for debug + // builds since RosAlloc attempts to read the magic number from a protected page. + RemoveSpace(main_space_); RemoveRememberedSet(main_space_); - RemoveRememberedSet(main_space_backup_.get()); - main_space_backup_.reset(nullptr); + delete main_space_; // Delete the space since it has been removed. main_space_ = nullptr; + RemoveRememberedSet(main_space_backup_.get()); + main_space_backup_.reset(nullptr); // Deletes the space. temp_space_ = space::BumpPointerSpace::CreateFromMemMap("Bump pointer space 2", mem_map.release()); AddSpace(temp_space_); diff --git a/runtime/gc/space/malloc_space.cc b/runtime/gc/space/malloc_space.cc index 27f92b571e..ba7e5c1eca 100644 --- a/runtime/gc/space/malloc_space.cc +++ b/runtime/gc/space/malloc_space.cc @@ -51,12 +51,12 @@ MallocSpace::MallocSpace(const std::string& name, MemMap* mem_map, live_bitmap_.reset(accounting::ContinuousSpaceBitmap::Create( StringPrintf("allocspace %s live-bitmap %d", name.c_str(), static_cast(bitmap_index)), Begin(), NonGrowthLimitCapacity())); - DCHECK(live_bitmap_.get() != nullptr) << "could not create allocspace live bitmap #" + CHECK(live_bitmap_.get() != nullptr) << "could not create allocspace live bitmap #" << bitmap_index; mark_bitmap_.reset(accounting::ContinuousSpaceBitmap::Create( StringPrintf("allocspace %s mark-bitmap %d", name.c_str(), static_cast(bitmap_index)), Begin(), NonGrowthLimitCapacity())); - DCHECK(live_bitmap_.get() != nullptr) << "could not create allocspace mark bitmap #" + CHECK(live_bitmap_.get() != nullptr) << "could not create allocspace mark bitmap #" << bitmap_index; } for (auto& freed : recent_freed_objects_) { -- cgit v1.2.3-59-g8ed1b