Bug 788955 - Without --enable-jemalloc detect and use jemalloc3 in libc. r=glandium
--- a/Makefile.in
+++ b/Makefile.in
@@ -43,18 +43,20 @@ ifeq (gonk,$(MOZ_WIDGET_TOOLKIT))
tier_base_dirs += \
other-licenses/android \
$(NULL)
endif
ifdef MOZ_MEMORY
tier_base_dirs += memory/mozjemalloc
ifdef MOZ_JEMALLOC
+ifndef MOZ_NATIVE_JEMALLOC
tier_base_dirs += memory/jemalloc
endif
+endif
tier_base_dirs += memory/build
endif
ifndef MOZ_NATIVE_ZLIB
tier_base_dirs += modules/zlib
endif
tier_base_dirs += \
mozglue \
memory/mozalloc \
--- a/allmakefiles.sh
+++ b/allmakefiles.sh
@@ -54,17 +54,17 @@ if [ ! "$LIBXUL_SDK" ]; then
build/stlport/stl/config/_android.h
"
fi
add_makefiles "
memory/mozalloc/Makefile
mozglue/Makefile
mozglue/build/Makefile
"
- if [ "$MOZ_JEMALLOC" ]; then
+ if [ "$MOZ_JEMALLOC" -a -z "$MOZ_NATIVE_JEMALLOC" ]; then
add_makefiles "
memory/jemalloc/Makefile
"
fi
if [ "$MOZ_MEMORY" ]; then
add_makefiles "
memory/mozjemalloc/Makefile
memory/build/Makefile
--- a/configure.in
+++ b/configure.in
@@ -7020,16 +7020,28 @@ else
MOZ_GLUE_PROGRAM_LDFLAGS="$MOZ_GLUE_PROGRAM_LDFLAGS -rdynamic"
fi
if test "$MOZ_LINKER" = 1; then
MOZ_GLUE_PROGRAM_LDFLAGS="$MOZ_GLUE_PROGRAM_LDFLAGS $ZLIB_LIBS"
fi
fi
if test -z "$MOZ_MEMORY"; then
+ if test -n "$MOZ_JEMALLOC"; then
+ MOZ_NATIVE_JEMALLOC=1
+ AC_CHECK_FUNCS(mallctl nallocm,,
+ [MOZ_NATIVE_JEMALLOC=
+ break])
+ if test -n "$MOZ_NATIVE_JEMALLOC"; then
+ MOZ_MEMORY=1
+ AC_DEFINE(MOZ_MEMORY)
+ AC_DEFINE(MOZ_JEMALLOC)
+ AC_DEFINE(MOZ_NATIVE_JEMALLOC)
+ fi
+ fi
case "${target}" in
*-mingw*)
if test -z "$WIN32_REDIST_DIR" -a -z "$MOZ_DEBUG"; then
AC_MSG_WARN([When not building jemalloc, you need to set WIN32_REDIST_DIR to the path to the Visual C++ Redist (usually VCINSTALLDIR\redist\x86\Microsoft.VC80.CRT, for VC++ v8) if you intend to distribute your build.])
fi
;;
esac
else
@@ -7114,16 +7126,17 @@ else
;;
*)
AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
;;
esac
fi # MOZ_MEMORY
AC_SUBST(MOZ_MEMORY)
AC_SUBST(MOZ_JEMALLOC)
+AC_SUBST(MOZ_NATIVE_JEMALLOC)
AC_SUBST(MOZ_GLUE_LDFLAGS)
AC_SUBST(MOZ_GLUE_PROGRAM_LDFLAGS)
AC_SUBST(WIN32_CRT_LIBS)
dnl Need to set this for make because NSS doesn't have configure
AC_SUBST(DLLFLAGS)
dnl We need to wrap dlopen and related functions on Android because we use
dnl our own linker.
@@ -8947,17 +8960,17 @@ MOZ_CRASHREPORTER=${MOZ_CRASHREPORTER} \
if cmp -s ./mozinfo.json.tmp ./mozinfo.json; then
rm ./mozinfo.json.tmp
else
mv -f ./mozinfo.json.tmp ./mozinfo.json
fi
# Run jemalloc configure script
-if test "$MOZ_JEMALLOC" -a "$MOZ_MEMORY"; then
+if test -z "$MOZ_NATIVE_JEMALLOC" -a "$MOZ_JEMALLOC" -a "$MOZ_MEMORY" ; then
ac_configure_args="$_SUBDIR_CONFIG_ARGS --build=$build --host=$target --enable-stats --with-jemalloc-prefix=je_"
if test "$OS_ARCH" = "Linux"; then
MANGLE="malloc calloc valloc free realloc memalign posix_memalign malloc_usable_size"
MANGLED=
JEMALLOC_WRAPPER=
if test -n "$_WRAP_MALLOC"; then
JEMALLOC_WRAPPER=__wrap_
fi
--- a/memory/build/Makefile.in
+++ b/memory/build/Makefile.in
@@ -17,14 +17,16 @@ ifdef MOZ_GLUE_PROGRAM_LDFLAGS
SDK_LIBRARY = $(REAL_LIBRARY)
DIST_INSTALL = 1
endif
CSRCS = extraMallocFuncs.c
ifdef MOZ_JEMALLOC
CSRCS += mozjemalloc_compat.c
+ifndef MOZ_NATIVE_JEMALLOC
SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/jemalloc)
+endif
else
SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,jemalloc,$(DEPTH)/memory/mozjemalloc)
endif
include $(topsrcdir)/config/rules.mk
--- a/memory/build/extraMallocFuncs.c
+++ b/memory/build/extraMallocFuncs.c
@@ -113,18 +113,26 @@ wrap(wcsdup)(const wchar_t *src)
wcsncpy(dst, src, len + 1);
return dst;
}
#endif /* XP_WIN */
#endif
#ifdef MOZ_JEMALLOC
+
+#undef wrap
+#if defined(MOZ_NATIVE_JEMALLOC)
+#define wrap(a) a
+#else
+#define wrap(a) je_ ## a
+#endif
+
/* Override some jemalloc defaults */
-const char *je_malloc_conf = "narenas:1,lg_chunk:20";
+MOZ_EXPORT_DATA(const char *) wrap(malloc_conf) = "narenas:1,lg_chunk:20";
#ifdef ANDROID
#include <android/log.h>
static void
_je_malloc_message(void *cbopaque, const char *s)
{
__android_log_print(ANDROID_LOG_INFO, "GeckoJemalloc", "%s", s);
--- a/memory/build/mozjemalloc_compat.c
+++ b/memory/build/mozjemalloc_compat.c
@@ -1,18 +1,25 @@
/* 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/. */
#include "mozilla/Types.h"
#include "jemalloc_types.h"
-extern int je_mallctl(const char*, void*, size_t*, void*, size_t);
+#if defined(MOZ_NATIVE_JEMALLOC)
+#define wrap(a) a
+#else
+#define wrap(a) je_ ## a
+#endif
-MOZ_EXPORT_API (void)
+extern MOZ_IMPORT_API(int)
+wrap(mallctl)(const char*, void*, size_t*, void*, size_t);
+
+MOZ_EXPORT_API(void)
jemalloc_stats(jemalloc_stats_t *stats)
{
size_t size = sizeof(stats->mapped);
- je_mallctl("stats.mapped", &stats->mapped, &size, NULL, 0);
- je_mallctl("stats.allocated", &stats->allocated, &size, NULL, 0);
+ wrap(mallctl)("stats.mapped", &stats->mapped, &size, NULL, 0);
+ wrap(mallctl)("stats.allocated", &stats->allocated, &size, NULL, 0);
stats->committed = -1;
stats->dirty = -1;
}
--- a/memory/mozjemalloc/jemalloc.h
+++ b/memory/mozjemalloc/jemalloc.h
@@ -32,46 +32,52 @@
#ifndef _JEMALLOC_H_
#define _JEMALLOC_H_
#if defined(MOZ_MEMORY_DARWIN)
#include <malloc/malloc.h>
#endif
#include "jemalloc_types.h"
+#if defined(MOZ_NATIVE_JEMALLOC)
+#define wrap(a) a
+#else
+#define wrap(a) je_ ## a
+#endif
+
#ifdef __cplusplus
extern "C" {
#endif
-#if defined(MOZ_MEMORY_LINUX)
+#if defined(MOZ_NATIVE_JEMALLOC) || defined(MOZ_MEMORY_LINUX)
__attribute__((weak))
#endif
void jemalloc_stats(jemalloc_stats_t *stats);
/* Computes the usable size in advance. */
#if !defined(MOZ_MEMORY_DARWIN)
#if defined(MOZ_MEMORY_LINUX)
__attribute__((weak))
#endif
#if defined(MOZ_JEMALLOC)
-int je_nallocm(size_t *rsize, size_t size, int flags);
+MOZ_IMPORT_API(int) wrap(nallocm)(size_t *rsize, size_t size, int flags);
#else
size_t je_malloc_good_size(size_t size);
#endif
#endif
static inline size_t je_malloc_usable_size_in_advance(size_t size) {
#if defined(MOZ_MEMORY_DARWIN)
return malloc_good_size(size);
#elif defined(MOZ_JEMALLOC)
- if (je_nallocm) {
+ if (wrap(nallocm)) {
size_t ret;
if (size == 0)
size = 1;
- if (!je_nallocm(&ret, size, 0))
+ if (!wrap(nallocm)(&ret, size, 0))
return ret;
}
return size;
#else
if (je_malloc_good_size)
return je_malloc_good_size(size);
else
return size;
@@ -108,9 +114,11 @@ static inline void jemalloc_purge_freed_
#else
void jemalloc_purge_freed_pages();
#endif
#ifdef __cplusplus
} /* extern "C" */
#endif
+#undef wrap
+
#endif /* _JEMALLOC_H_ */
--- a/mozglue/build/Makefile.in
+++ b/mozglue/build/Makefile.in
@@ -18,17 +18,17 @@ DIST_INSTALL = 1
# If this is ever changed, update MOZ_SHARED_MOZGLUE in browser/installer/Makefile.in
ifneq (,$(filter WINNT Darwin Android,$(OS_TARGET)))
FORCE_SHARED_LIB = 1
else
FORCE_STATIC_LIB = 1
endif
# Keep jemalloc separated when mozglue is statically linked
-ifeq (1_1,$(MOZ_MEMORY)_$(FORCE_SHARED_LIB))
+ifeq (1_1,$(MOZ_MEMORY)_$(or $(MOZ_NATIVE_JEMALLOC),$(FORCE_SHARED_LIB)))
SHARED_LIBRARY_LIBS = $(call EXPAND_LIBNAME_PATH,memory,$(DEPTH)/memory/build)
else
# Temporary, until bug 662814 lands
VISIBILITY_FLAGS =
CPPSRCS = dummy.cpp
ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
SDK_LIBRARY = $(IMPORT_LIBRARY)