| 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);
|
| };
|
|
|