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/. */
10 // This header is meant to be used when the following functions are
12 // - malloc_good_size (used to be called je_malloc_usable_in_advance)
14 // - jemalloc_stats_num_bins
15 // - jemalloc_purge_freed_pages
16 // - jemalloc_free_dirty_pages
17 // - jemalloc_thread_local_arena
18 // - jemalloc_ptr_info
23 #include "mozmemory_wrap.h"
24 #include "mozilla/Attributes.h"
25 #include "mozilla/Types.h"
26 #include "mozjemalloc_types.h"
30 // On OSX, malloc/malloc.h contains the declaration for malloc_good_size,
31 // which will call back in jemalloc, through the zone allocator so just use it.
33 MOZ_MEMORY_API
size_t malloc_good_size_impl(size_t size
);
35 // Note: the MOZ_GLUE_IN_PROGRAM ifdef below is there to avoid -Werror turning
36 // the protective if into errors. MOZ_GLUE_IN_PROGRAM is what triggers MFBT_API
37 // to use weak imports.
38 static inline size_t _malloc_good_size(size_t size
) {
39 # if defined(MOZ_GLUE_IN_PROGRAM) && !defined(IMPL_MFBT)
40 if (!malloc_good_size
) return size
;
42 return malloc_good_size_impl(size
);
45 # define malloc_good_size _malloc_good_size
48 # define MALLOC_DECL(name, return_type, ...) \
49 MOZ_JEMALLOC_API return_type name(__VA_ARGS__);
50 # define MALLOC_FUNCS MALLOC_FUNCS_JEMALLOC
51 # include "malloc_decls.h"
53 // jemalloc_stats may only be called on the main thread so that it can access
54 // main thread only arenas.
56 static inline void jemalloc_stats(jemalloc_stats_t
* aStats
,
57 jemalloc_bin_stats_t
* aBinStats
= nullptr) {
58 jemalloc_stats_internal(aStats
, aBinStats
);
61 static inline void jemalloc_stats(jemalloc_stats_t
* aStats
) {
62 jemalloc_stats_internal(aStats
, NULL
);
68 #define NOTHROW_MALLOC_DECL(name, return_type, ...) \
69 MOZ_JEMALLOC_API return_type name(__VA_ARGS__) noexcept(true);
70 #define MALLOC_DECL(name, return_type, ...) \
71 MOZ_JEMALLOC_API return_type name(__VA_ARGS__);
72 #define MALLOC_FUNCS MALLOC_FUNCS_ARENA
73 #include "malloc_decls.h"
76 # define moz_create_arena() moz_create_arena_with_params(nullptr)
78 # define moz_create_arena() moz_create_arena_with_params(NULL)