2017-11-01 10:56:27 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-12-07 12:32:24 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
2017-11-01 10:56:27 +03:00
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2012-12-07 12:32:24 +04:00
|
|
|
|
|
|
|
#ifndef mozmemory_h
|
|
|
|
#define mozmemory_h
|
|
|
|
|
2017-11-01 11:15:12 +03:00
|
|
|
// This header is meant to be used when the following functions are
|
|
|
|
// necessary:
|
|
|
|
// - malloc_good_size (used to be called je_malloc_usable_in_advance)
|
|
|
|
// - jemalloc_stats
|
2021-10-21 09:42:34 +03:00
|
|
|
// - jemalloc_stats_num_bins
|
2017-11-01 11:15:12 +03:00
|
|
|
// - jemalloc_purge_freed_pages
|
|
|
|
// - jemalloc_free_dirty_pages
|
|
|
|
// - jemalloc_thread_local_arena
|
|
|
|
// - jemalloc_ptr_info
|
2012-12-07 12:32:24 +04:00
|
|
|
|
2017-09-22 01:22:38 +03:00
|
|
|
#ifdef MALLOC_H
|
|
|
|
# include MALLOC_H
|
2012-12-07 12:32:24 +04:00
|
|
|
#endif
|
|
|
|
#include "mozmemory_wrap.h"
|
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
#include "mozilla/Types.h"
|
2017-05-12 15:52:25 +03:00
|
|
|
#include "mozjemalloc_types.h"
|
2012-12-07 12:32:24 +04:00
|
|
|
|
2017-09-22 01:22:38 +03:00
|
|
|
#ifdef MOZ_MEMORY
|
2017-11-01 11:15:12 +03:00
|
|
|
// On OSX, malloc/malloc.h contains the declaration for malloc_good_size,
|
|
|
|
// which will call back in jemalloc, through the zone allocator so just use it.
|
2017-09-22 01:22:38 +03:00
|
|
|
# ifndef XP_DARWIN
|
2012-12-07 12:32:24 +04:00
|
|
|
MOZ_MEMORY_API size_t malloc_good_size_impl(size_t size);
|
|
|
|
|
2017-11-01 11:15:12 +03:00
|
|
|
// Note: the MOZ_GLUE_IN_PROGRAM ifdef below is there to avoid -Werror turning
|
|
|
|
// the protective if into errors. MOZ_GLUE_IN_PROGRAM is what triggers MFBT_API
|
|
|
|
// to use weak imports.
|
2013-10-22 01:34:24 +04:00
|
|
|
static inline size_t _malloc_good_size(size_t size) {
|
2012-12-07 12:32:24 +04:00
|
|
|
# if defined(MOZ_GLUE_IN_PROGRAM) && !defined(IMPL_MFBT)
|
|
|
|
if (!malloc_good_size) return size;
|
|
|
|
# endif
|
|
|
|
return malloc_good_size_impl(size);
|
|
|
|
}
|
|
|
|
|
|
|
|
# define malloc_good_size _malloc_good_size
|
|
|
|
# endif
|
|
|
|
|
2017-09-14 12:28:12 +03:00
|
|
|
# define MALLOC_DECL(name, return_type, ...) \
|
|
|
|
MOZ_JEMALLOC_API return_type name(__VA_ARGS__);
|
|
|
|
# define MALLOC_FUNCS MALLOC_FUNCS_JEMALLOC
|
|
|
|
# include "malloc_decls.h"
|
2017-09-01 04:52:23 +03:00
|
|
|
|
2020-10-09 01:42:45 +03:00
|
|
|
# ifdef __cplusplus
|
|
|
|
static inline void jemalloc_stats(jemalloc_stats_t* aStats,
|
|
|
|
jemalloc_bin_stats_t* aBinStats = nullptr) {
|
|
|
|
jemalloc_stats_internal(aStats, aBinStats);
|
|
|
|
}
|
|
|
|
# else
|
|
|
|
static inline void jemalloc_stats(jemalloc_stats_t* aStats) {
|
|
|
|
jemalloc_stats_internal(aStats, NULL);
|
|
|
|
}
|
|
|
|
# endif
|
|
|
|
|
|
|
|
#endif // MOZ_MEMORY
|
2017-09-22 01:22:38 +03:00
|
|
|
|
2019-09-05 02:40:15 +03:00
|
|
|
#define NOTHROW_MALLOC_DECL(name, return_type, ...) \
|
|
|
|
MOZ_JEMALLOC_API return_type name(__VA_ARGS__) noexcept(true);
|
2017-09-22 01:22:38 +03:00
|
|
|
#define MALLOC_DECL(name, return_type, ...) \
|
|
|
|
MOZ_JEMALLOC_API return_type name(__VA_ARGS__);
|
|
|
|
#define MALLOC_FUNCS MALLOC_FUNCS_ARENA
|
|
|
|
#include "malloc_decls.h"
|
|
|
|
|
2017-11-17 01:27:35 +03:00
|
|
|
#ifdef __cplusplus
|
|
|
|
# define moz_create_arena() moz_create_arena_with_params(nullptr)
|
|
|
|
#else
|
|
|
|
# define moz_create_arena() moz_create_arena_with_params(NULL)
|
|
|
|
#endif
|
|
|
|
|
2017-11-01 11:15:12 +03:00
|
|
|
#endif // mozmemory_h
|