OSDN Git Service

Fix GC memory overhead accounting.
authorMathieu Chartier <mathieuc@google.com>
Thu, 21 Aug 2014 19:21:48 +0000 (12:21 -0700)
committerMathieu Chartier <mathieuc@google.com>
Mon, 25 Aug 2014 17:42:42 +0000 (10:42 -0700)
There was some missing null checks.

Bug: 16238192

(cherry picked from commit 2e290fb35ba1959e5a0ac85e87591ab9623808c1)

Change-Id: I4220272ac9c194e30fc307fca9918a4bb725e261

runtime/gc/accounting/gc_allocator.cc
runtime/gc/accounting/gc_allocator.h

index 49d84fa..ff6a135 100644 (file)
@@ -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);
 }
 
index 1d96112..d4142f8 100644 (file)
@@ -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 <typename T>
 class GcAllocatorImpl : public std::allocator<T> {