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

Side by Side Diff: base/allocator/tcmalloc_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
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/allocator/allocator_extension_thunks.h"
6
7 #include "third_party/tcmalloc/chromium/src/gperftools/heap-profiler.h"
8 #include "third_party/tcmalloc/chromium/src/gperftools/malloc_extension.h"
9
10 extern "C" {
11 int tc_set_new_mode(int mode);
12 }
13
14 namespace {
15
16 bool GetAllocatorWasteSizeHelper(size_t* size) {
17 size_t heap_size, allocated_bytes, unmapped_bytes;
18 MallocExtension* ext = MallocExtension::instance();
19 if (ext->GetNumericProperty("generic.heap_size", &heap_size) &&
20 ext->GetNumericProperty("generic.current_allocated_bytes",
21 &allocated_bytes) &&
22 ext->GetNumericProperty("tcmalloc.pageheap_unmapped_bytes",
23 &unmapped_bytes)) {
24 *size = heap_size - allocated_bytes - unmapped_bytes;
25 return true;
26 }
27 return false;
28 }
29
30 void GetStatsHelper(char* buffer, int buffer_length) {
31 MallocExtension::instance()->GetStats(buffer, buffer_length);
32 }
33
34 bool GetNumericPropertyHelper(const char* name, size_t* value) {
35 return MallocExtension::instance()->GetNumericProperty(name, value);
36 }
37
38 void ReleaseFreeMemoryHelper() {
39 MallocExtension::instance()->ReleaseFreeMemory();
40 }
41
42 unsigned int GetBytesAllocatedOnCurrentThreadHelper() {
43 return MallocExtension::instance()->GetBytesAllocatedOnCurrentThread();
44 }
45
46 bool IsHeapProfilerRunningHelper() {
47 return IsHeapProfilerRunning();
48 }
49
50 } // namespace
51
52 namespace base {
53 namespace allocator {
54
55 __attribute__((visibility("default"))) thunks::AllocatorExtensionFunctions
56 InitializeAllocatorWeak();
57
58 thunks::AllocatorExtensionFunctions InitializeAllocatorWeak() {
59 // For tcmalloc, we need to tell it to behave like new.
60 tc_set_new_mode(1);
61
62 thunks::AllocatorExtensionFunctions allocator_funtions = {
63 GetAllocatorWasteSizeHelper, GetStatsHelper,
64 ReleaseFreeMemoryHelper, GetBytesAllocatedOnCurrentThreadHelper,
65 GetNumericPropertyHelper, ::HeapProfilerWithPseudoStackStart,
66 ::HeapProfilerStop, ::GetHeapProfile,
67 ::HeapProfilerDump, IsHeapProfilerRunningHelper};
68 return allocator_funtions;
69 }
70
71 } // namespace allocator
72 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698