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:
Mike Hommey 2017-11-24 16:36:29 +09:00
Родитель 32ecc64ada
Коммит feda5d4e15
3 изменённых файлов: 23 добавлений и 42 удалений

Просмотреть файл

@ -20,25 +20,19 @@
#define MALLOC_FUNCS_MALLOC \
(MALLOC_FUNCS_MALLOC_BASE | MALLOC_FUNCS_MALLOC_EXTRA)
#define MALLOC_FUNCS_JEMALLOC 4
#define MALLOC_FUNCS_INIT 8
#define MALLOC_FUNCS_ARENA_BASE 16
#define MALLOC_FUNCS_ARENA_ALLOC 32
#define MALLOC_FUNCS_ARENA_BASE 8
#define MALLOC_FUNCS_ARENA_ALLOC 16
#define MALLOC_FUNCS_ARENA (MALLOC_FUNCS_ARENA_BASE | MALLOC_FUNCS_ARENA_ALLOC)
#define MALLOC_FUNCS_ALL \
(MALLOC_FUNCS_INIT | MALLOC_FUNCS_MALLOC | MALLOC_FUNCS_JEMALLOC | \
MALLOC_FUNCS_ARENA)
(MALLOC_FUNCS_MALLOC | MALLOC_FUNCS_JEMALLOC | MALLOC_FUNCS_ARENA)
#endif // malloc_decls_h
#ifndef MALLOC_FUNCS
#define MALLOC_FUNCS \
(MALLOC_FUNCS_MALLOC | MALLOC_FUNCS_JEMALLOC | MALLOC_FUNCS_ARENA)
#define MALLOC_FUNCS MALLOC_FUNCS_ALL
#endif
#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
MALLOC_DECL(malloc, void*, size_t)
MALLOC_DECL(calloc, void*, size_t, size_t)

Просмотреть файл

@ -4812,8 +4812,9 @@ static
// the zygote.
#ifdef XP_DARWIN
#define MOZ_REPLACE_WEAK __attribute__((weak_import))
#elif defined(XP_WIN) || defined(MOZ_WIDGET_ANDROID)
#define MOZ_NO_REPLACE_FUNC_DECL
#elif defined(XP_WIN) || defined(ANDROID)
#define MOZ_DYNAMIC_REPLACE_INIT
#define replace_init replace_init_decl
#elif defined(__GNUC__)
#define MOZ_REPLACE_WEAK __attribute__((weak))
#endif
@ -4826,12 +4827,10 @@ static malloc_table_t gReplaceMallocTable = {
#include "malloc_decls.h"
};
#ifdef MOZ_NO_REPLACE_FUNC_DECL
#define MALLOC_DECL(name, return_type, ...) \
typedef return_type(name##_impl_t)(__VA_ARGS__); \
name##_impl_t* replace_##name = nullptr;
#define MALLOC_FUNCS MALLOC_FUNCS_INIT
#include "malloc_decls.h"
#ifdef MOZ_DYNAMIC_REPLACE_INIT
#undef replace_init
typedef decltype(replace_init_decl) replace_init_impl_t;
static replace_init_impl_t* replace_init = nullptr;
#endif
#ifdef XP_WIN
@ -4849,8 +4848,8 @@ replace_malloc_handle()
return nullptr;
}
#define REPLACE_MALLOC_GET_FUNC(handle, name) \
(name##_impl_t*)GetProcAddress(handle, "replace_" #name)
#define REPLACE_MALLOC_GET_INIT_FUNC(handle) \
(replace_init_impl_t*)GetProcAddress(handle, "replace_init")
#elif defined(ANDROID)
#include <dlfcn.h>
@ -4867,8 +4866,8 @@ replace_malloc_handle()
return nullptr;
}
#define REPLACE_MALLOC_GET_FUNC(handle, name) \
(name##_impl_t*)dlsym(handle, "replace_" #name)
#define REPLACE_MALLOC_GET_INIT_FUNC(handle) \
(replace_init_impl_t*)dlsym(handle, "replace_init")
#endif
@ -4882,14 +4881,10 @@ static ReplaceMallocBridge* gReplaceMallocBridge = nullptr;
static void
init()
{
#ifdef MOZ_NO_REPLACE_FUNC_DECL
#ifdef MOZ_DYNAMIC_REPLACE_INIT
replace_malloc_handle_t handle = replace_malloc_handle();
if (handle) {
#define MALLOC_DECL(name, ...) \
replace_##name = REPLACE_MALLOC_GET_FUNC(handle, name);
#define MALLOC_FUNCS MALLOC_FUNCS_INIT
#include "malloc_decls.h"
replace_init = REPLACE_MALLOC_GET_INIT_FUNC(handle);
}
#endif

Просмотреть файл

@ -80,29 +80,21 @@
MOZ_BEGIN_EXTERN_C
// MOZ_NO_REPLACE_FUNC_DECL and MOZ_REPLACE_WEAK are only defined in
// replace_malloc.c. Normally including this header will add function
// definitions.
#ifndef MOZ_NO_REPLACE_FUNC_DECL
// MOZ_REPLACE_WEAK is only defined in mozjemalloc.cpp. Normally including
// this header will add function definitions.
#ifndef MOZ_REPLACE_WEAK
#define MOZ_REPLACE_WEAK
#endif
// Export replace_init.
#define MALLOC_DECL(name, return_type, ...) \
MOZ_EXPORT return_type replace_##name(__VA_ARGS__) MOZ_REPLACE_WEAK;
// Replace-malloc library initialization function. See top of this file
MOZ_EXPORT void
replace_init(malloc_table_t*, struct ReplaceMallocBridge**) MOZ_REPLACE_WEAK;
#define MALLOC_FUNCS MALLOC_FUNCS_INIT
#include "malloc_decls.h"
// Define the remaining replace_* functions as not exported.
// Define the replace_* functions as not exported.
#define MALLOC_DECL(name, return_type, ...) \
return_type replace_##name(__VA_ARGS__);
#include "malloc_decls.h"
#endif // MOZ_NO_REPLACE_FUNC_DECL
MOZ_END_EXTERN_C
#endif // replace_malloc_h