Bug 804303 - Part 3: Build jemalloc3 as a replace-malloc library when building with mozjemalloc. r=khuey, a=jlebar

This commit is contained in:
Mike Hommey 2012-12-07 09:32:24 +01:00
Родитель e491911755
Коммит fc4650b1ca
8 изменённых файлов: 110 добавлений и 14 удалений

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

@ -59,7 +59,7 @@ if [ ! "$LIBXUL_SDK" ]; then
mozglue/Makefile
mozglue/build/Makefile
"
if [ "$MOZ_JEMALLOC3" -a -z "$MOZ_NATIVE_JEMALLOC" ]; then
if [ "$MOZ_JEMALLOC3" -o "$MOZ_REPLACE_MALLOC" ] && [ -z "$MOZ_NATIVE_JEMALLOC" ]; then
add_makefiles "
memory/jemalloc/Makefile
"
@ -71,6 +71,16 @@ if [ ! "$LIBXUL_SDK" ]; then
memory/build/Makefile
"
fi
if [ "$MOZ_REPLACE_MALLOC" ]; then
add_makefiles "
memory/replace/Makefile
"
if [ -z "$MOZ_JEMALLOC3" ]; then
add_makefiles "
memory/replace/jemalloc/Makefile
"
fi
fi
if [ "$MOZ_REPLACE_MALLOC_LINKAGE" = "dummy library" ]; then
add_makefiles "
memory/replace/dummy/Makefile

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

@ -9072,31 +9072,41 @@ fi
# Run jemalloc configure script
if test -z "$MOZ_NATIVE_JEMALLOC" -a "$MOZ_MEMORY" -a "$MOZ_JEMALLOC3"; then
if test -z "$MOZ_NATIVE_JEMALLOC" -a "$MOZ_MEMORY" && test -n "$MOZ_JEMALLOC3" -o -n "$MOZ_REPLACE_MALLOC"; then
ac_configure_args="$_SUBDIR_CONFIG_ARGS --build=$build --host=$target --enable-stats --with-jemalloc-prefix=je_"
if test -n "$MOZ_REPLACE_MALLOC"; then
# When using replace_malloc, we always want memalign and valloc exported from jemalloc.
ac_configure_args="$ac_configure_args ac_cv_func_memalign=yes"
ac_configure_args="$ac_configure_args ac_cv_func_valloc=yes"
fi
case "${OS_ARCH}" in
WINNT|Darwin)
# We want jemalloc functions to be kept hidden on both Mac and Windows
# See memory/build/mozmemory_wrap.h for details.
ac_configure_args="$ac_configure_args --without-export"
;;
esac
if test -n "$MOZ_JEMALLOC3"; then
case "${OS_ARCH}" in
WINNT|Darwin)
# We want jemalloc functions to be kept hidden on both Mac and Windows
# See memory/build/mozmemory_wrap.h for details.
ac_configure_args="$ac_configure_args --without-export"
;;
esac
elif test "${OS_ARCH}" = Darwin; then
# When building as a replace-malloc lib, disabling the zone allocator
# forces to use pthread_atfork.
ac_configure_args="$ac_configure_args --disable-zone-allocator"
fi
_MANGLE="malloc posix_memalign aligned_alloc calloc realloc free memalign valloc malloc_usable_size"
JEMALLOC_WRAPPER=
if test -z "$MOZ_REPLACE_MALLOC"; then
case "$OS_ARCH" in
Linux|DragonFly|FreeBSD|NetBSD|OpenBSD)
MANGLE="malloc posix_memalign aligned_alloc calloc realloc free memalign valloc malloc_usable_size"
MANGLE=$_MANGLE
;;
esac
elif test -z "$MOZ_JEMALLOC3"; then
MANGLE=$_MANGLE
JEMALLOC_WRAPPER=replace_
fi
if test -n "$MANGLE"; then
MANGLED=
JEMALLOC_WRAPPER=
if test -n "$_WRAP_MALLOC"; then
if test -n "$_WRAP_MALLOC" -a -z "$JEMALLOC_WRAPPER"; then
JEMALLOC_WRAPPER=__wrap_
fi
for mangle in ${MANGLE}; do

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

@ -11,7 +11,7 @@ include $(DEPTH)/config/autoconf.mk
DIRS += mozjemalloc
ifdef MOZ_JEMALLOC3
ifneq (,$(MOZ_JEMALLOC3)$(MOZ_REPLACE_MALLOC))
ifndef MOZ_NATIVE_JEMALLOC
DIRS += jemalloc
endif

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

@ -135,7 +135,11 @@
# define mozmem_jemalloc_impl(a) je_ ## a
# else
# define MOZ_JEMALLOC_API MFBT_API
# if (defined(XP_WIN) || defined(XP_DARWIN))
# ifdef MOZ_REPLACE_JEMALLOC
# define MOZ_MEMORY_API MFBT_API
# define mozmem_malloc_impl(a) replace_ ## a
# define mozmem_jemalloc_impl(a) replace_ ## a
# elif (defined(XP_WIN) || defined(XP_DARWIN))
# if defined(MOZ_REPLACE_MALLOC)
# define mozmem_malloc_impl(a) a ## _impl
# else

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

@ -0,0 +1,17 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# 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/.
DEPTH = @DEPTH@
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
# Build jemalloc3 as a replace-malloc lib when building with mozjemalloc
ifndef MOZ_JEMALLOC
DIRS += jemalloc
endif
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,41 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# 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/.
DEPTH = @DEPTH@
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = memory
LIBRARY_NAME = replace_jemalloc
FORCE_SHARED_LIB = 1
NO_DIST_INSTALL = 1
SHARED_LIBRARY_LIBS = $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/jemalloc)
DEFINES += -DMOZ_JEMALLOC3 -DMOZ_REPLACE_JEMALLOC
LOCAL_INCLUDES += -I../../jemalloc/src/include
ifdef _MSC_VER
LOCAL_INCLUDES += -I$(topsrcdir)/memory/jemalloc/src/include/msvc_compat
endif
VPATH += $(topsrcdir)/memory/build
CSRCS = \
mozjemalloc_compat.c \
jemalloc_config.c \
$(NULL)
MOZ_GLUE_LDFLAGS = # Don't link against mozglue
WRAP_LDFLAGS = # Never wrap malloc function calls with -Wl,--wrap
# Android doesn't have pthread_atfork, so just implement a dummy function.
# It shouldn't make much problem, as the use of fork is pretty limited on
# Android.
ifeq ($(MOZ_WIDGET_TOOLKIT),android)
CSRCS += pthread_atfork.c
endif
include $(topsrcdir)/config/rules.mk

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

@ -0,0 +1,10 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
int pthread_atfork(void (*prefork)(void),
void (*postfork_parent)(void),
void (*postfork_child)(void))
{
return 0;
}

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

@ -266,6 +266,10 @@ tier_platform_dirs += toolkit/library
tier_platform_dirs += xpcom/stub
ifdef MOZ_REPLACE_MALLOC
tier_platform_dirs += memory/replace
endif
ifdef NS_TRACE_MALLOC
tier_platform_dirs += tools/trace-malloc
endif