/src/mozilla-central/memory/build/mozjemalloc.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=8 sts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
5 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | #ifndef mozjemalloc_h |
8 | | #define mozjemalloc_h |
9 | | |
10 | | #include "mozjemalloc_types.h" |
11 | | #include "mozilla/MacroArgs.h" |
12 | | |
13 | | // Macro helpers |
14 | | |
15 | | #define MACRO_CALL(a, b) a b |
16 | | // Can't use macros recursively, so we need another one doing the same as above. |
17 | 14.6M | #define MACRO_CALL2(a, b) a b |
18 | | |
19 | | #define ARGS_HELPER(name, ...) \ |
20 | 14.6M | MACRO_CALL2(MOZ_PASTE_PREFIX_AND_ARG_COUNT(name, ##__VA_ARGS__), \ |
21 | 14.6M | (__VA_ARGS__)) |
22 | | #define TYPED_ARGS0() |
23 | | #define TYPED_ARGS1(t1) t1 arg1 |
24 | | #define TYPED_ARGS2(t1, t2) TYPED_ARGS1(t1), t2 arg2 |
25 | | #define TYPED_ARGS3(t1, t2, t3) TYPED_ARGS2(t1, t2), t3 arg3 |
26 | | |
27 | | #define ARGS0() |
28 | 14.6M | #define ARGS1(t1) arg1 |
29 | 4.89M | #define ARGS2(t1, t2) ARGS1(t1), arg2 |
30 | 4.33k | #define ARGS3(t1, t2, t3) ARGS2(t1, t2), arg3 |
31 | | |
32 | | #ifdef MOZ_MEMORY |
33 | | |
34 | | // Generic interface exposing the whole public allocator API |
35 | | // This facilitates the implementation of things like replace-malloc. |
36 | | // Note: compilers are expected to be able to optimize out `this`. |
37 | | template<typename T> |
38 | | struct Allocator : public T |
39 | | { |
40 | | #define MALLOC_DECL(name, return_type, ...) \ |
41 | | static return_type name(__VA_ARGS__); |
42 | | #include "malloc_decls.h" |
43 | | }; |
44 | | |
45 | | // The MozJemalloc allocator |
46 | | struct MozJemallocBase |
47 | | { |
48 | | }; |
49 | | typedef Allocator<MozJemallocBase> MozJemalloc; |
50 | | |
51 | | #ifdef MOZ_REPLACE_MALLOC |
52 | | // The replace-malloc allocator |
53 | | struct ReplaceMallocBase |
54 | | { |
55 | | }; |
56 | | typedef Allocator<ReplaceMallocBase> ReplaceMalloc; |
57 | | |
58 | | typedef ReplaceMalloc DefaultMalloc; |
59 | | #else |
60 | | typedef MozJemalloc DefaultMalloc; |
61 | | #endif |
62 | | |
63 | | #endif // MOZ_MEMORY |
64 | | |
65 | | // Dummy implementation of the moz_arena_* API, falling back to a given |
66 | | // implementation of the base allocator. |
67 | | template<typename T> |
68 | | struct DummyArenaAllocator |
69 | | { |
70 | 6 | static arena_id_t moz_create_arena_with_params(arena_params_t*) { return 0; } |
71 | | |
72 | 0 | static void moz_dispose_arena(arena_id_t) {} |
73 | | |
74 | | #define MALLOC_DECL(name, return_type, ...) \ |
75 | | static return_type moz_arena_##name(arena_id_t, \ |
76 | | ARGS_HELPER(TYPED_ARGS, ##__VA_ARGS__)) \ |
77 | 4.88M | { \ |
78 | 4.88M | return T::name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \ |
79 | 4.88M | } DummyArenaAllocator<SystemMalloc>::moz_arena_malloc(unsigned long, unsigned long) Line | Count | Source | 77 | 4.88M | { \ | 78 | 4.88M | return T::name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \ | 79 | 4.88M | } |
DummyArenaAllocator<SystemMalloc>::moz_arena_calloc(unsigned long, unsigned long, unsigned long) Line | Count | Source | 77 | 1.55k | { \ | 78 | 1.55k | return T::name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \ | 79 | 1.55k | } |
DummyArenaAllocator<SystemMalloc>::moz_arena_realloc(unsigned long, void*, unsigned long) Line | Count | Source | 77 | 2.78k | { \ | 78 | 2.78k | return T::name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \ | 79 | 2.78k | } |
Unexecuted instantiation: DummyArenaAllocator<SystemMalloc>::moz_arena_free(unsigned long, void*) Unexecuted instantiation: DummyArenaAllocator<SystemMalloc>::moz_arena_memalign(unsigned long, unsigned long, unsigned long) |
80 | | #define MALLOC_FUNCS MALLOC_FUNCS_MALLOC_BASE |
81 | | #include "malloc_decls.h" |
82 | | }; |
83 | | |
84 | | #endif |