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

Side by Side Diff: base/allocator/allocator_extension.cc

Issue 1469843002: Remove dependency on allocator from 'content' targets (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@unify_allocator1_2
Patch Set: Fix build Created 5 years, 1 month 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/allocator/allocator_extension.h" 5 #include "base/allocator/allocator_extension.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "build/build_config.h"
8 9
9 namespace base { 10 namespace base {
10 namespace allocator { 11 namespace allocator {
11 12
13 #if defined(USE_TCMALLOC)
14 // Since the base library does not know about allocator, the initialization
15 // method would call this function which is declared as a weak symbol. This
16 // should be replaced by a strong symbol linked from the actual allocator
17 // library. The executable target is expected include an allocator shim layer
Primiano Tucci (use gerrit) 2015/11/25 12:47:17 remove "shim layer"
18 // replaces this weak symbol.
19 // Such an implementation of this method should return a set of callbacks that
20 // are used to implement the required allocator extension functions.
21 // This method is defined in .cc file so that the allocator implementation can
22 // still include the header file without getting a "weak" declaration of this
23 // function.
24 __attribute__((weak, visibility("default"), noinline))
25 thunks::AllocatorExtensionFunctions
26 InitializeAllocatorWeak();
27 #endif
28
29 void InitializeAllocator() {
30 #if defined(USE_TCMALLOC)
31 // This calls into the weak function declared above. If a specific allocator
32 // implementation needs initialization then it should define and link a strong
33 // symbol of "InitializeAllocatorWeak" function, that returns the necessary
34 // callbacks.
35 thunks::AllocatorExtensionFunctions functions = InitializeAllocatorWeak();
36 thunks::SetAllocatorExtensionFunctions(functions);
37 #endif
38 }
39
12 bool GetAllocatorWasteSize(size_t* size) { 40 bool GetAllocatorWasteSize(size_t* size) {
13 thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function = 41 auto get_allocator_waste_size_function =
14 thunks::GetGetAllocatorWasteSizeFunction(); 42 thunks::GetAllocatorExtensionFunctions().get_allocator_waste_size;
15 return get_allocator_waste_size_function != NULL && 43 return get_allocator_waste_size_function != NULL &&
16 get_allocator_waste_size_function(size); 44 get_allocator_waste_size_function(size);
17 } 45 }
18 46
19 void GetStats(char* buffer, int buffer_length) { 47 void GetStats(char* buffer, int buffer_length) {
20 DCHECK_GT(buffer_length, 0); 48 DCHECK_GT(buffer_length, 0);
21 thunks::GetStatsFunction get_stats_function = thunks::GetGetStatsFunction(); 49 auto get_stats_function = thunks::GetAllocatorExtensionFunctions().get_stats;
22 if (get_stats_function) 50 if (get_stats_function)
23 get_stats_function(buffer, buffer_length); 51 get_stats_function(buffer, buffer_length);
24 else 52 else
25 buffer[0] = '\0'; 53 buffer[0] = '\0';
26 } 54 }
27 55
28 void ReleaseFreeMemory() { 56 void ReleaseFreeMemory() {
29 thunks::ReleaseFreeMemoryFunction release_free_memory_function = 57 auto release_free_memory_function =
30 thunks::GetReleaseFreeMemoryFunction(); 58 thunks::GetAllocatorExtensionFunctions().release_free_memory;
31 if (release_free_memory_function) 59 if (release_free_memory_function)
32 release_free_memory_function(); 60 release_free_memory_function();
33 } 61 }
34 62
35 void SetGetAllocatorWasteSizeFunction( 63 size_t GetBytesAllocatedOnCurrentThread() {
36 thunks::GetAllocatorWasteSizeFunction get_allocator_waste_size_function) { 64 auto get_bytes_allocated_on_current_thread_function =
37 DCHECK_EQ(thunks::GetGetAllocatorWasteSizeFunction(), 65 thunks::GetAllocatorExtensionFunctions()
38 reinterpret_cast<thunks::GetAllocatorWasteSizeFunction>(NULL)); 66 .get_bytes_allocated_on_current_thread;
39 thunks::SetGetAllocatorWasteSizeFunction(get_allocator_waste_size_function); 67 DCHECK(get_bytes_allocated_on_current_thread_function);
68 return get_bytes_allocated_on_current_thread_function();
40 } 69 }
41 70
42 void SetGetStatsFunction(thunks::GetStatsFunction get_stats_function) { 71 bool GetNumericProperty(const char* name, size_t* value) {
43 DCHECK_EQ(thunks::GetGetStatsFunction(), 72 auto get_numeric_property_function =
44 reinterpret_cast<thunks::GetStatsFunction>(NULL)); 73 thunks::GetAllocatorExtensionFunctions().get_numeric_property;
45 thunks::SetGetStatsFunction(get_stats_function); 74 return get_numeric_property_function != NULL &&
75 get_numeric_property_function(name, value);
46 } 76 }
47 77
48 void SetReleaseFreeMemoryFunction( 78 void HeapProfilerStart(StackGeneratorFunction callback) {
49 thunks::ReleaseFreeMemoryFunction release_free_memory_function) { 79 auto heap_profiler_start_function =
50 DCHECK_EQ(thunks::GetReleaseFreeMemoryFunction(), 80 thunks::GetAllocatorExtensionFunctions().heap_profiler_start;
51 reinterpret_cast<thunks::ReleaseFreeMemoryFunction>(NULL)); 81 if (heap_profiler_start_function)
52 thunks::SetReleaseFreeMemoryFunction(release_free_memory_function); 82 heap_profiler_start_function(callback);
53 } 83 }
54 84
55 void SetGetNumericPropertyFunction( 85 void HeapProfilerStop() {
56 thunks::GetNumericPropertyFunction get_numeric_property_function) { 86 auto heap_profiler_stop_function =
57 DCHECK_EQ(thunks::GetGetNumericPropertyFunction(), 87 thunks::GetAllocatorExtensionFunctions().heap_profiler_stop;
58 reinterpret_cast<thunks::GetNumericPropertyFunction>(NULL)); 88 if (heap_profiler_stop_function)
59 thunks::SetGetNumericPropertyFunction(get_numeric_property_function); 89 heap_profiler_stop_function();
90 }
91
92 char* GetHeapProfile() {
93 auto get_heap_profile_function =
94 thunks::GetAllocatorExtensionFunctions().get_heap_profile;
95 if (get_heap_profile_function)
96 return get_heap_profile_function();
97 return NULL;
98 }
99
100 void HeapProfilerDump(const char* reason) {
101 auto heap_profiler_dump_function =
102 thunks::GetAllocatorExtensionFunctions().heap_profiler_dump;
103 if (heap_profiler_dump_function)
104 heap_profiler_dump_function(reason);
105 }
106
107 bool IsHeapProfilerRunning() {
108 auto is_heap_profiler_running_function =
109 thunks::GetAllocatorExtensionFunctions().is_heap_profiler_running;
110 return is_heap_profiler_running_function != NULL &&
111 is_heap_profiler_running_function();
60 } 112 }
61 113
62 } // namespace allocator 114 } // namespace allocator
63 } // namespace base 115 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698