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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #ifndef RUNTIME_VM_MALLOC_HOOKS_H_ 5 #ifndef RUNTIME_VM_MALLOC_HOOKS_H_
6 #define RUNTIME_VM_MALLOC_HOOKS_H_ 6 #define RUNTIME_VM_MALLOC_HOOKS_H_
7 7
8 #include "vm/globals.h" 8 #include "vm/globals.h"
9 9
10 #if defined(DART_USE_TCMALLOC)
11 // The following macros are also defined in tcmalloc.
12 // We'll push them onto a stack and restore them after we're finished including
13 // headers from tcmalloc.
14 #pragma push_macro("COMPILE_ASSERT")
15 #pragma push_macro("DISALLOW_COPY_AND_ASSIGN")
16 #pragma push_macro("ASSERT")
17 #undef COMPILE_ASSERT
18 #undef DISALLOW_COPY_AND_ASSIGN
19 #undef ASSERT
20
21 #include "base/low_level_alloc.h"
22 #include "./addressmap-inl.h"
23
24 // Restore VM macro definitions.
25 #pragma pop_macro("ASSERT")
26 #pragma pop_macro("DISALLOW_COPY_AND_ASSIGN")
27 #pragma pop_macro("COMPILE_ASSERT")
28 #endif // defined(DART_USE_TCMALLOC)
29
10 namespace dart { 30 namespace dart {
11 31
12 class MallocHooks { 32 class MallocHooks {
33 public:
13 static void Init(); 34 static void Init();
35 static void TearDown();
36
37 #if defined(DART_USE_TCMALLOC)
38 static uintptr_t heap_allocated_memory_in_bytes() {
39 return heap_allocated_memory_in_bytes_;
40 }
41 #else
42 static uintptr_t heap_allocated_memory_in_bytes() { return 0; }
43 #endif
14 44
15 private: 45 private:
46 #if defined(DART_USE_TCMALLOC)
47
48 static bool initialized_;
49
50 // Memory arena used by MallocHooks custom malloc and free calls
51 // to avoid dependencies on tcmalloc malloc and free.
52 static LowLevelAlloc::Arena* malloc_hooks_memory_;
53
54 // Custom malloc implementation.
55 static void* MallocHooksMalloc(size_t bytes) {
56 return LowLevelAlloc::AllocWithArena(bytes, malloc_hooks_memory_);
57 }
58
59 // Custom free implementation.
60 static void MallocHooksFree(void* p) { LowLevelAlloc::Free(p); }
61
62 // Hooks.
63 static void RecordAllocHook(const void* ptr, size_t size);
64 static void RecordFreeHook(const void* ptr);
65
66 static uintptr_t heap_allocated_memory_in_bytes_;
67 static AddressMap<uintptr_t>* allocation_map_;
68
69 #endif // defined(DART_USE_TCMALLOC)
70
16 DISALLOW_ALLOCATION(); 71 DISALLOW_ALLOCATION();
17 DISALLOW_IMPLICIT_CONSTRUCTORS(MallocHooks); 72 DISALLOW_IMPLICIT_CONSTRUCTORS(MallocHooks);
18 }; 73 };
19 74
20 } // namespace dart 75 } // namespace dart
21 76
22 #endif // RUNTIME_VM_MALLOC_HOOKS_H_ 77 #endif // RUNTIME_VM_MALLOC_HOOKS_H_
OLDNEW
« 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