Fix a per-process dumpsys meminfo crash.
In the InvalidateAllocator() function, DlMallocSpace and RosAllocSpace
both null out the underlying allocator pointer at the zygote fork time
so that new allocations won't accidentally happen in the zygote space
after a zygote fork. However, nulling out the only allocator pointer
would cause crashes in non-allocation uses such as GetFootprint() in
this particular crash. Fix this by creating a second pointer just for
the allocation purpose that gets nulled upon a InvalidateAllocator()
call while the original pointer keeps pointing to the allocator.
Change-Id: Ie751d9380db39baace9e25712a3824eec9a9969a
diff --git a/runtime/gc/space/dlmalloc_space.cc b/runtime/gc/space/dlmalloc_space.cc
index fcac588..b067bbc 100644
--- a/runtime/gc/space/dlmalloc_space.cc
+++ b/runtime/gc/space/dlmalloc_space.cc
@@ -111,7 +111,7 @@
DlMallocSpace::DlMallocSpace(const std::string& name, MemMap* mem_map, void* mspace, byte* begin,
byte* end, byte* limit, size_t growth_limit)
: MallocSpace(name, mem_map, begin, end, limit, growth_limit),
- total_bytes_freed_(0), total_objects_freed_(0), mspace_(mspace) {
+ total_bytes_freed_(0), total_objects_freed_(0), mspace_(mspace), mspace_for_alloc_(mspace) {
CHECK(mspace != NULL);
}
@@ -334,25 +334,17 @@
}
uint64_t DlMallocSpace::GetBytesAllocated() {
- if (mspace_ != nullptr) {
- MutexLock mu(Thread::Current(), lock_);
- size_t bytes_allocated = 0;
- mspace_inspect_all(mspace_, DlmallocBytesAllocatedCallback, &bytes_allocated);
- return bytes_allocated;
- } else {
- return Size();
- }
+ MutexLock mu(Thread::Current(), lock_);
+ size_t bytes_allocated = 0;
+ mspace_inspect_all(mspace_, DlmallocBytesAllocatedCallback, &bytes_allocated);
+ return bytes_allocated;
}
uint64_t DlMallocSpace::GetObjectsAllocated() {
- if (mspace_ != nullptr) {
- MutexLock mu(Thread::Current(), lock_);
- size_t objects_allocated = 0;
- mspace_inspect_all(mspace_, DlmallocObjectsAllocatedCallback, &objects_allocated);
- return objects_allocated;
- } else {
- return 0;
- }
+ MutexLock mu(Thread::Current(), lock_);
+ size_t objects_allocated = 0;
+ mspace_inspect_all(mspace_, DlmallocObjectsAllocatedCallback, &objects_allocated);
+ return objects_allocated;
}
#ifndef NDEBUG