Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Unified Diff: runtime/vm/malloc_hooks.h

Issue 2625613002: Implemented basic heap memory allocation tracking in MallocHooks using hooks registered with tcmall… (Closed)
Patch Set: Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/malloc_hooks.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/malloc_hooks.h
diff --git a/runtime/vm/malloc_hooks.h b/runtime/vm/malloc_hooks.h
index ae09402388d4fb9b7af1b932b4d78e3f2f6811d7..4f04209d9b5b790a8608f0e87c572a5b3e584123 100644
--- a/runtime/vm/malloc_hooks.h
+++ b/runtime/vm/malloc_hooks.h
@@ -7,12 +7,67 @@
#include "vm/globals.h"
+#if defined(DART_USE_TCMALLOC)
+// The following macros are also defined in tcmalloc.
+// We'll push them onto a stack and restore them after we're finished including
+// headers from tcmalloc.
+#pragma push_macro("COMPILE_ASSERT")
+#pragma push_macro("DISALLOW_COPY_AND_ASSIGN")
+#pragma push_macro("ASSERT")
+#undef COMPILE_ASSERT
+#undef DISALLOW_COPY_AND_ASSIGN
+#undef ASSERT
+
+#include "base/low_level_alloc.h"
+#include "./addressmap-inl.h"
+
+// Restore VM macro definitions.
+#pragma pop_macro("ASSERT")
+#pragma pop_macro("DISALLOW_COPY_AND_ASSIGN")
+#pragma pop_macro("COMPILE_ASSERT")
+#endif // defined(DART_USE_TCMALLOC)
+
namespace dart {
class MallocHooks {
+ public:
static void Init();
+ static void TearDown();
+
+#if defined(DART_USE_TCMALLOC)
+ static uintptr_t heap_allocated_memory_in_bytes() {
+ return heap_allocated_memory_in_bytes_;
+ }
+#else
+ static uintptr_t heap_allocated_memory_in_bytes() { return 0; }
+#endif
private:
+#if defined(DART_USE_TCMALLOC)
+
+ static bool initialized_;
+
+ // Memory arena used by MallocHooks custom malloc and free calls
+ // to avoid dependencies on tcmalloc malloc and free.
+ static LowLevelAlloc::Arena* malloc_hooks_memory_;
+
+ // Custom malloc implementation.
+ static void* MallocHooksMalloc(size_t bytes) {
+ return LowLevelAlloc::AllocWithArena(bytes, malloc_hooks_memory_);
+ }
+
+ // Custom free implementation.
+ static void MallocHooksFree(void* p) { LowLevelAlloc::Free(p); }
+
+ // Hooks.
+ static void RecordAllocHook(const void* ptr, size_t size);
+ static void RecordFreeHook(const void* ptr);
+
+ static uintptr_t heap_allocated_memory_in_bytes_;
+ static AddressMap<uintptr_t>* allocation_map_;
+
+#endif // defined(DART_USE_TCMALLOC)
+
DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(MallocHooks);
};
« no previous file with comments | « runtime/vm/dart_api_impl.cc ('k') | runtime/vm/malloc_hooks.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698