зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1420353 - Don't define replace_init through malloc_decls.h. r=njn
The definition for replace_init is only used in two places: replace_malloc.h and mozjemalloc.cpp. Invoking the malloc_decls.h machinery for just that one function is a lot of overhead, and things are actually simpler doing the declaration directly, especially thanks to the use of C++11 decltype to avoid duplication of the function type. This has the additional advantage that now malloc_decls.h only contains the allocator API. While here, replace the MOZ_WIDGET_ANDROID ifdef with ANDROID. --HG-- extra : rebase_source : 50ddf044f43904575598f17bd4c3477fc1a1155f
This commit is contained in:
Родитель
32ecc64ada
Коммит
feda5d4e15
|
@ -20,25 +20,19 @@
|
||||||
#define MALLOC_FUNCS_MALLOC \
|
#define MALLOC_FUNCS_MALLOC \
|
||||||
(MALLOC_FUNCS_MALLOC_BASE | MALLOC_FUNCS_MALLOC_EXTRA)
|
(MALLOC_FUNCS_MALLOC_BASE | MALLOC_FUNCS_MALLOC_EXTRA)
|
||||||
#define MALLOC_FUNCS_JEMALLOC 4
|
#define MALLOC_FUNCS_JEMALLOC 4
|
||||||
#define MALLOC_FUNCS_INIT 8
|
#define MALLOC_FUNCS_ARENA_BASE 8
|
||||||
#define MALLOC_FUNCS_ARENA_BASE 16
|
#define MALLOC_FUNCS_ARENA_ALLOC 16
|
||||||
#define MALLOC_FUNCS_ARENA_ALLOC 32
|
|
||||||
#define MALLOC_FUNCS_ARENA (MALLOC_FUNCS_ARENA_BASE | MALLOC_FUNCS_ARENA_ALLOC)
|
#define MALLOC_FUNCS_ARENA (MALLOC_FUNCS_ARENA_BASE | MALLOC_FUNCS_ARENA_ALLOC)
|
||||||
#define MALLOC_FUNCS_ALL \
|
#define MALLOC_FUNCS_ALL \
|
||||||
(MALLOC_FUNCS_INIT | MALLOC_FUNCS_MALLOC | MALLOC_FUNCS_JEMALLOC | \
|
(MALLOC_FUNCS_MALLOC | MALLOC_FUNCS_JEMALLOC | MALLOC_FUNCS_ARENA)
|
||||||
MALLOC_FUNCS_ARENA)
|
|
||||||
|
|
||||||
#endif // malloc_decls_h
|
#endif // malloc_decls_h
|
||||||
|
|
||||||
#ifndef MALLOC_FUNCS
|
#ifndef MALLOC_FUNCS
|
||||||
#define MALLOC_FUNCS \
|
#define MALLOC_FUNCS MALLOC_FUNCS_ALL
|
||||||
(MALLOC_FUNCS_MALLOC | MALLOC_FUNCS_JEMALLOC | MALLOC_FUNCS_ARENA)
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef MALLOC_DECL
|
#ifdef MALLOC_DECL
|
||||||
#if MALLOC_FUNCS & MALLOC_FUNCS_INIT
|
|
||||||
MALLOC_DECL(init, void, malloc_table_t*, struct ReplaceMallocBridge**)
|
|
||||||
#endif
|
|
||||||
#if MALLOC_FUNCS & MALLOC_FUNCS_MALLOC_BASE
|
#if MALLOC_FUNCS & MALLOC_FUNCS_MALLOC_BASE
|
||||||
MALLOC_DECL(malloc, void*, size_t)
|
MALLOC_DECL(malloc, void*, size_t)
|
||||||
MALLOC_DECL(calloc, void*, size_t, size_t)
|
MALLOC_DECL(calloc, void*, size_t, size_t)
|
||||||
|
|
|
@ -4812,8 +4812,9 @@ static
|
||||||
// the zygote.
|
// the zygote.
|
||||||
#ifdef XP_DARWIN
|
#ifdef XP_DARWIN
|
||||||
#define MOZ_REPLACE_WEAK __attribute__((weak_import))
|
#define MOZ_REPLACE_WEAK __attribute__((weak_import))
|
||||||
#elif defined(XP_WIN) || defined(MOZ_WIDGET_ANDROID)
|
#elif defined(XP_WIN) || defined(ANDROID)
|
||||||
#define MOZ_NO_REPLACE_FUNC_DECL
|
#define MOZ_DYNAMIC_REPLACE_INIT
|
||||||
|
#define replace_init replace_init_decl
|
||||||
#elif defined(__GNUC__)
|
#elif defined(__GNUC__)
|
||||||
#define MOZ_REPLACE_WEAK __attribute__((weak))
|
#define MOZ_REPLACE_WEAK __attribute__((weak))
|
||||||
#endif
|
#endif
|
||||||
|
@ -4826,12 +4827,10 @@ static malloc_table_t gReplaceMallocTable = {
|
||||||
#include "malloc_decls.h"
|
#include "malloc_decls.h"
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef MOZ_NO_REPLACE_FUNC_DECL
|
#ifdef MOZ_DYNAMIC_REPLACE_INIT
|
||||||
#define MALLOC_DECL(name, return_type, ...) \
|
#undef replace_init
|
||||||
typedef return_type(name##_impl_t)(__VA_ARGS__); \
|
typedef decltype(replace_init_decl) replace_init_impl_t;
|
||||||
name##_impl_t* replace_##name = nullptr;
|
static replace_init_impl_t* replace_init = nullptr;
|
||||||
#define MALLOC_FUNCS MALLOC_FUNCS_INIT
|
|
||||||
#include "malloc_decls.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef XP_WIN
|
#ifdef XP_WIN
|
||||||
|
@ -4849,8 +4848,8 @@ replace_malloc_handle()
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define REPLACE_MALLOC_GET_FUNC(handle, name) \
|
#define REPLACE_MALLOC_GET_INIT_FUNC(handle) \
|
||||||
(name##_impl_t*)GetProcAddress(handle, "replace_" #name)
|
(replace_init_impl_t*)GetProcAddress(handle, "replace_init")
|
||||||
|
|
||||||
#elif defined(ANDROID)
|
#elif defined(ANDROID)
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
|
@ -4867,8 +4866,8 @@ replace_malloc_handle()
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define REPLACE_MALLOC_GET_FUNC(handle, name) \
|
#define REPLACE_MALLOC_GET_INIT_FUNC(handle) \
|
||||||
(name##_impl_t*)dlsym(handle, "replace_" #name)
|
(replace_init_impl_t*)dlsym(handle, "replace_init")
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -4882,14 +4881,10 @@ static ReplaceMallocBridge* gReplaceMallocBridge = nullptr;
|
||||||
static void
|
static void
|
||||||
init()
|
init()
|
||||||
{
|
{
|
||||||
#ifdef MOZ_NO_REPLACE_FUNC_DECL
|
#ifdef MOZ_DYNAMIC_REPLACE_INIT
|
||||||
replace_malloc_handle_t handle = replace_malloc_handle();
|
replace_malloc_handle_t handle = replace_malloc_handle();
|
||||||
if (handle) {
|
if (handle) {
|
||||||
#define MALLOC_DECL(name, ...) \
|
replace_init = REPLACE_MALLOC_GET_INIT_FUNC(handle);
|
||||||
replace_##name = REPLACE_MALLOC_GET_FUNC(handle, name);
|
|
||||||
|
|
||||||
#define MALLOC_FUNCS MALLOC_FUNCS_INIT
|
|
||||||
#include "malloc_decls.h"
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -80,29 +80,21 @@
|
||||||
|
|
||||||
MOZ_BEGIN_EXTERN_C
|
MOZ_BEGIN_EXTERN_C
|
||||||
|
|
||||||
// MOZ_NO_REPLACE_FUNC_DECL and MOZ_REPLACE_WEAK are only defined in
|
// MOZ_REPLACE_WEAK is only defined in mozjemalloc.cpp. Normally including
|
||||||
// replace_malloc.c. Normally including this header will add function
|
// this header will add function definitions.
|
||||||
// definitions.
|
|
||||||
#ifndef MOZ_NO_REPLACE_FUNC_DECL
|
|
||||||
|
|
||||||
#ifndef MOZ_REPLACE_WEAK
|
#ifndef MOZ_REPLACE_WEAK
|
||||||
#define MOZ_REPLACE_WEAK
|
#define MOZ_REPLACE_WEAK
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Export replace_init.
|
// Replace-malloc library initialization function. See top of this file
|
||||||
#define MALLOC_DECL(name, return_type, ...) \
|
MOZ_EXPORT void
|
||||||
MOZ_EXPORT return_type replace_##name(__VA_ARGS__) MOZ_REPLACE_WEAK;
|
replace_init(malloc_table_t*, struct ReplaceMallocBridge**) MOZ_REPLACE_WEAK;
|
||||||
|
|
||||||
#define MALLOC_FUNCS MALLOC_FUNCS_INIT
|
// Define the replace_* functions as not exported.
|
||||||
#include "malloc_decls.h"
|
|
||||||
|
|
||||||
// Define the remaining replace_* functions as not exported.
|
|
||||||
#define MALLOC_DECL(name, return_type, ...) \
|
#define MALLOC_DECL(name, return_type, ...) \
|
||||||
return_type replace_##name(__VA_ARGS__);
|
return_type replace_##name(__VA_ARGS__);
|
||||||
#include "malloc_decls.h"
|
#include "malloc_decls.h"
|
||||||
|
|
||||||
#endif // MOZ_NO_REPLACE_FUNC_DECL
|
|
||||||
|
|
||||||
MOZ_END_EXTERN_C
|
MOZ_END_EXTERN_C
|
||||||
|
|
||||||
#endif // replace_malloc_h
|
#endif // replace_malloc_h
|
||||||
|
|
Загрузка…
Ссылка в новой задаче