forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathallocator_shim_default_dispatch_to_tcmalloc.cc
92 lines (73 loc) · 2.61 KB
/
allocator_shim_default_dispatch_to_tcmalloc.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "base/allocator/allocator_shim.h"
#include "base/allocator/allocator_shim_internals.h"
#include "third_party/tcmalloc/chromium/src/config.h"
#include "third_party/tcmalloc/chromium/src/gperftools/tcmalloc.h"
namespace {
using base::allocator::AllocatorDispatch;
void* TCMalloc(const AllocatorDispatch*, size_t size, void* context) {
return tc_malloc(size);
}
void* TCCalloc(const AllocatorDispatch*, size_t n, size_t size, void* context) {
return tc_calloc(n, size);
}
void* TCMemalign(const AllocatorDispatch*,
size_t alignment,
size_t size,
void* context) {
return tc_memalign(alignment, size);
}
void* TCRealloc(const AllocatorDispatch*,
void* address,
size_t size,
void* context) {
return tc_realloc(address, size);
}
void TCFree(const AllocatorDispatch*, void* address, void* context) {
tc_free(address);
}
size_t TCGetSizeEstimate(const AllocatorDispatch*,
void* address,
void* context) {
return tc_malloc_size(address);
}
} // namespace
const AllocatorDispatch AllocatorDispatch::default_dispatch = {
&TCMalloc, /* alloc_function */
&TCCalloc, /* alloc_zero_initialized_function */
&TCMemalign, /* alloc_aligned_function */
&TCRealloc, /* realloc_function */
&TCFree, /* free_function */
&TCGetSizeEstimate, /* get_size_estimate_function */
nullptr, /* batch_malloc_function */
nullptr, /* batch_free_function */
nullptr, /* free_definite_size_function */
nullptr, /* next */
};
// In the case of tcmalloc we have also to route the diagnostic symbols,
// which are not part of the unified shim layer, to tcmalloc for consistency.
extern "C" {
SHIM_ALWAYS_EXPORT void malloc_stats(void) __THROW {
return tc_malloc_stats();
}
SHIM_ALWAYS_EXPORT int mallopt(int cmd, int value) __THROW {
return tc_mallopt(cmd, value);
}
#ifdef HAVE_STRUCT_MALLINFO
SHIM_ALWAYS_EXPORT struct mallinfo mallinfo(void) __THROW {
return tc_mallinfo();
}
#endif
SHIM_ALWAYS_EXPORT size_t malloc_size(void* address) __THROW {
return tc_malloc_size(address);
}
#if defined(__ANDROID__)
SHIM_ALWAYS_EXPORT size_t malloc_usable_size(const void* address) __THROW {
#else
SHIM_ALWAYS_EXPORT size_t malloc_usable_size(void* address) __THROW {
#endif
return tc_malloc_size(address);
}
} // extern "C"