Bug 1708422: part 3) Add some documentation to `mozInlineSpellChecker::CheckWordsAndA...
[gecko.git] / memory / build / mozmemory.h
blob1fd2385f335dc7fd6ea1019231a9831e8bef9387
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/. */
7 #ifndef mozmemory_h
8 #define mozmemory_h
10 // This header is meant to be used when the following functions are
11 // necessary:
12 // - malloc_good_size (used to be called je_malloc_usable_in_advance)
13 // - jemalloc_stats
14 // - jemalloc_purge_freed_pages
15 // - jemalloc_free_dirty_pages
16 // - jemalloc_thread_local_arena
17 // - jemalloc_ptr_info
19 #ifdef MALLOC_H
20 # include MALLOC_H
21 #endif
22 #include "mozmemory_wrap.h"
23 #include "mozilla/Attributes.h"
24 #include "mozilla/Types.h"
25 #include "mozjemalloc_types.h"
27 #ifdef MOZ_MEMORY
28 // On OSX, malloc/malloc.h contains the declaration for malloc_good_size,
29 // which will call back in jemalloc, through the zone allocator so just use it.
30 # ifndef XP_DARWIN
31 MOZ_MEMORY_API size_t malloc_good_size_impl(size_t size);
33 // Note: the MOZ_GLUE_IN_PROGRAM ifdef below is there to avoid -Werror turning
34 // the protective if into errors. MOZ_GLUE_IN_PROGRAM is what triggers MFBT_API
35 // to use weak imports.
36 static inline size_t _malloc_good_size(size_t size) {
37 # if defined(MOZ_GLUE_IN_PROGRAM) && !defined(IMPL_MFBT)
38 if (!malloc_good_size) return size;
39 # endif
40 return malloc_good_size_impl(size);
43 # define malloc_good_size _malloc_good_size
44 # endif
46 # define MALLOC_DECL(name, return_type, ...) \
47 MOZ_JEMALLOC_API return_type name(__VA_ARGS__);
48 # define MALLOC_FUNCS MALLOC_FUNCS_JEMALLOC
49 # include "malloc_decls.h"
51 # ifdef __cplusplus
52 static inline void jemalloc_stats(jemalloc_stats_t* aStats,
53 jemalloc_bin_stats_t* aBinStats = nullptr) {
54 jemalloc_stats_internal(aStats, aBinStats);
56 # else
57 static inline void jemalloc_stats(jemalloc_stats_t* aStats) {
58 jemalloc_stats_internal(aStats, NULL);
60 # endif
62 #endif // MOZ_MEMORY
64 #define NOTHROW_MALLOC_DECL(name, return_type, ...) \
65 MOZ_JEMALLOC_API return_type name(__VA_ARGS__) noexcept(true);
66 #define MALLOC_DECL(name, return_type, ...) \
67 MOZ_JEMALLOC_API return_type name(__VA_ARGS__);
68 #define MALLOC_FUNCS MALLOC_FUNCS_ARENA
69 #include "malloc_decls.h"
71 #ifdef __cplusplus
72 # define moz_create_arena() moz_create_arena_with_params(nullptr)
73 #else
74 # define moz_create_arena() moz_create_arena_with_params(NULL)
75 #endif
77 #endif // mozmemory_h