From 2e290fb35ba1959e5a0ac85e87591ab9623808c1 Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Thu, 21 Aug 2014 12:21:48 -0700 Subject: [PATCH] Fix GC memory overhead accounting. There was some missing null checks. Bug: 16238192 Change-Id: Iaf8d752db5f21e76f668c0066a063239ff374eee --- runtime/gc/accounting/gc_allocator.cc | 10 ++++++++-- runtime/gc/accounting/gc_allocator.h | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/runtime/gc/accounting/gc_allocator.cc b/runtime/gc/accounting/gc_allocator.cc index 49d84faf3..ff6a1356e 100644 --- a/runtime/gc/accounting/gc_allocator.cc +++ b/runtime/gc/accounting/gc_allocator.cc @@ -24,12 +24,18 @@ namespace gc { namespace accounting { void* RegisterGcAllocation(size_t bytes) { - Runtime::Current()->GetHeap()->RegisterGCAllocation(bytes); + gc::Heap* heap = Runtime::Current()->GetHeap(); + if (heap != nullptr) { + heap->RegisterGCAllocation(bytes); + } return malloc(bytes); } void RegisterGcDeallocation(void* p, size_t bytes) { - Runtime::Current()->GetHeap()->RegisterGCDeAllocation(bytes); + gc::Heap* heap = Runtime::Current()->GetHeap(); + if (heap != nullptr) { + heap->RegisterGCDeAllocation(bytes); + } free(p); } diff --git a/runtime/gc/accounting/gc_allocator.h b/runtime/gc/accounting/gc_allocator.h index 1d96112b0..d4142f824 100644 --- a/runtime/gc/accounting/gc_allocator.h +++ b/runtime/gc/accounting/gc_allocator.h @@ -30,7 +30,7 @@ namespace accounting { void* RegisterGcAllocation(size_t bytes); void RegisterGcDeallocation(void* p, size_t bytes); -static const bool kMeasureGcMemoryOverhead = false; +static constexpr bool kMeasureGcMemoryOverhead = false; template class GcAllocatorImpl : public std::allocator { -- 2.11.0