bug 559263 - make jemalloc work with android, follow up patch r=ted
authorBrad Lassey <blassey@mozilla.com>
Sat, 05 Jun 2010 13:15:50 -0400
changeset 43127 098cf0d0c599fdcfedbc6ee5aadf01259e9dcd09
parent 43126 8bc975526c0fb0912701477a79f0b94789dce9c2
child 43128 21f0727c27a6ac4c49cb7c93fce8299491c60ec8
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersted
bugs559263
milestone1.9.3a5pre
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
bug 559263 - make jemalloc work with android, follow up patch r=ted
configure.in
js/src/configure.in
memory/jemalloc/jemalloc.c
memory/mozalloc/Makefile.in
memory/mozalloc/ld_malloc_wrappers.c
memory/mozalloc/mozalloc.cpp
memory/mozalloc/wraps.c
--- a/configure.in
+++ b/configure.in
@@ -7166,16 +7166,18 @@ if test "$MOZ_MEMORY"; then
     ;;
   *-*winmo)
     AC_DEFINE(MOZ_MEMORY_WINCE)
     AC_DEFINE(MOZ_MEMORY_WINDOWS)
     ;;
   *-android*)
     AC_DEFINE(MOZ_MEMORY_LINUX)
     AC_DEFINE(MOZ_MEMORY_ANDROID)
+    _WRAP_MALLOC=1
+    export WRAP_MALLOC_LIB="-L$_objdir/dist/lib -lmozalloc"
     ;;
   *)
     AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
     ;;
   esac
 
   if test "$OS_ARCH" != "Darwin"; then
     dnl NB: this must be kept in sync with jemalloc.h
@@ -7195,17 +7197,17 @@ dnl = Use malloc wrapper lib
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(wrap-malloc,
 [  --enable-wrap-malloc    Wrap malloc calls (gnu linker only)],
     _WRAP_MALLOC=1,
     _WRAP_MALLOC= )
 
 if test -n "$_WRAP_MALLOC"; then
     if test "$GNU_CC"; then
-    WRAP_MALLOC_CFLAGS="${LDFLAGS} -Wl,--wrap -Wl,malloc -Wl,--wrap -Wl,calloc -Wl,--wrap -Wl,valloc -Wl,--wrap -Wl,free -Wl,--wrap -Wl,realloc -Wl,--wrap -Wl,memalign -Wl,--wrap -Wl,__builtin_new -Wl,--wrap -Wl,__builtin_vec_new -Wl,--wrap -Wl,__builtin_delete -Wl,--wrap -Wl,__builtin_vec_delete -Wl,--wrap -Wl,PR_Free -Wl,--wrap -Wl,PR_Malloc -Wl,--wrap -Wl,PR_Calloc -Wl,--wrap -Wl,PR_Realloc -Wl,--wrap -Wl,strdup -Wl,--wrap -Wl,strndup"
+    WRAP_MALLOC_CFLAGS="${LDFLAGS} -Wl,--wrap -Wl,malloc -Wl,--wrap -Wl,calloc -Wl,--wrap -Wl,valloc -Wl,--wrap -Wl,free -Wl,--wrap -Wl,realloc -Wl,--wrap -Wl,memalign -Wl,--wrap -Wl,__builtin_new -Wl,--wrap -Wl,__builtin_vec_new -Wl,--wrap -Wl,__builtin_delete -Wl,--wrap -Wl,__builtin_vec_delete -Wl,--wrap -Wl,PR_Free -Wl,--wrap -Wl,PR_Malloc -Wl,--wrap -Wl,PR_Calloc -Wl,--wrap -Wl,PR_Realloc -Wl,--wrap -Wl,strdup -Wl,--wrap -Wl,strndup -Wl,--wrap -Wl,posix_memalign"
     MKSHLIB='$(CXX) $(DSO_LDOPTS) $(WRAP_MALLOC_CFLAGS) $(WRAP_MALLOC_LIB) -o $@'
     fi
 fi
 
 dnl ========================================================
 dnl = Location of malloc wrapper lib
 dnl ========================================================
 MOZ_ARG_WITH_STRING(wrap-malloc,
@@ -9002,16 +9004,23 @@ HOST_LDFLAGS="$_SUBDIR_HOST_LDFLAGS"
 RC=
 
 unset MAKEFILES
 unset CONFIG_FILES
 
 # No need to run subconfigures when building with LIBXUL_SDK_DIR
 if test "$COMPILE_ENVIRONMENT" -a -z "$LIBXUL_SDK_DIR"; then
 
+if test -n "$MOZ_THUMB2"; then
+  _SUBDIR_CONFIG_ARGS="$_SUBDIR_CONFIG_ARGS --enable-thumb2"
+fi
+if test -n "$_WRAP_MALLOC"; then
+  _SUBDIR_CONFIG_ARGS="$_SUBDIR_CONFIG_ARGS --enable-wrap-malloc"
+fi
+
 if test -z "$MOZ_NATIVE_NSPR"; then
     ac_configure_args="$_SUBDIR_CONFIG_ARGS --with-dist-prefix=$MOZ_BUILD_ROOT/dist --with-mozilla"
     if test -z "$MOZ_DEBUG"; then
         ac_configure_args="$ac_configure_args --disable-debug"
     fi
     if test "$MOZ_OPTIMIZE" = "1"; then
         ac_configure_args="$ac_configure_args --enable-optimize"
     fi
@@ -9019,19 +9028,16 @@ if test -z "$MOZ_NATIVE_NSPR"; then
        ac_configure_args="$ac_configure_args --enable-debug --disable-optimize"
     fi
     if test -n "$HAVE_64BIT_OS"; then
         ac_configure_args="$ac_configure_args --enable-64bit"
     fi
     if test -n "$USE_ARM_KUSER"; then
         ac_configure_args="$ac_configure_args --with-arm-kuser"
     fi
-    if test -n "$MOZ_THUMB2"; then
-        ac_configure_args="$ac_configure_args --enable-thumb2"
-    fi
     AC_OUTPUT_SUBDIRS(nsprpub)
     ac_configure_args="$_SUBDIR_CONFIG_ARGS"
 fi
 
 if test -z "$MOZ_NATIVE_NSPR"; then
     # Hack to deal with the fact that we use NSPR_CFLAGS everywhere
     AC_MSG_WARN([Recreating autoconf.mk with updated nspr-config output])
     if test "$OS_ARCH" != "WINNT" && test "$OS_ARCH" != "WINCE"; then
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -4363,17 +4363,17 @@ dnl = Use malloc wrapper lib
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(wrap-malloc,
 [  --enable-wrap-malloc    Wrap malloc calls (gnu linker only)],
     _WRAP_MALLOC=1,
     _WRAP_MALLOC= )
 
 if test -n "$_WRAP_MALLOC"; then
     if test "$GNU_CC"; then
-    WRAP_MALLOC_CFLAGS="${LDFLAGS} -Wl,--wrap -Wl,malloc -Wl,--wrap -Wl,calloc -Wl,--wrap -Wl,valloc -Wl,--wrap -Wl,free -Wl,--wrap -Wl,realloc -Wl,--wrap -Wl,memalign -Wl,--wrap -Wl,__builtin_new -Wl,--wrap -Wl,__builtin_vec_new -Wl,--wrap -Wl,__builtin_delete -Wl,--wrap -Wl,__builtin_vec_delete -Wl,--wrap -Wl,PR_Free -Wl,--wrap -Wl,PR_Malloc -Wl,--wrap -Wl,PR_Calloc -Wl,--wrap -Wl,PR_Realloc -Wl,--wrap -Wl,strdup -Wl,--wrap -Wl,strndup"
+    WRAP_MALLOC_CFLAGS="${LDFLAGS} -Wl,--wrap -Wl,malloc -Wl,--wrap -Wl,calloc -Wl,--wrap -Wl,valloc -Wl,--wrap -Wl,free -Wl,--wrap -Wl,realloc -Wl,--wrap -Wl,memalign -Wl,--wrap -Wl,__builtin_new -Wl,--wrap -Wl,__builtin_vec_new -Wl,--wrap -Wl,__builtin_delete -Wl,--wrap -Wl,__builtin_vec_delete -Wl,--wrap -Wl,PR_Free -Wl,--wrap -Wl,PR_Malloc -Wl,--wrap -Wl,PR_Calloc -Wl,--wrap -Wl,PR_Realloc -Wl,--wrap -Wl,strdup -Wl,--wrap -Wl,strndup -Wl,--wrap -Wl,posix_memalign"
     MKSHLIB='$(CXX) $(DSO_LDOPTS) $(WRAP_MALLOC_CFLAGS) $(WRAP_MALLOC_LIB) -o $@'
     fi
 fi
 
 dnl ========================================================
 dnl = Location of malloc wrapper lib
 dnl ========================================================
 MOZ_ARG_WITH_STRING(wrap-malloc,
--- a/memory/jemalloc/jemalloc.c
+++ b/memory/jemalloc/jemalloc.c
@@ -5765,16 +5765,18 @@ malloc_shutdown()
 
 #if defined(MOZ_MEMORY_ANDROID) || defined(WRAP_MALLOC)
 inline void sys_free(void* ptr) {return free(ptr);}
 #define	malloc(a)	je_malloc(a)
 #define	valloc(a)	je_valloc(a)
 #define	calloc(a, b)	je_calloc(a, b)
 #define	realloc(a, b)	je_realloc(a, b)
 #define	free(a)		je_free(a)
+#define posix_memalign(a, b, c)  je_posix_memalign(a, b, c)
+
 char    *je_strndup(const char *src, size_t len) {
   char* dst = (char*)je_malloc(len + 1);
   if(dst)
     strncpy(dst, src, len + 1);
   return dst;
 }
 char    *je_strdup(const char *src) {
   size_t len = strlen(src);
--- a/memory/mozalloc/Makefile.in
+++ b/memory/mozalloc/Makefile.in
@@ -54,18 +54,18 @@ LIBRARY_NAME	= mozalloc
 FORCE_SHARED_LIB= 1
 DIST_INSTALL 	= 1
 
 ifdef MOZ_MEMORY
 ifneq (,$(findstring mozalloc,$(WRAP_MALLOC_LIB)))
 EXTRA_DSO_LDOPTS += $(DIST)/lib/libjemalloc.a
 WRAP_MALLOC_LIB=
 WRAP_MALLOC_CFLAGS=
-DEFINES += -DWRAP_MALLOC
-CSRCS = wraps.c
+DEFINES += -DWRAP_MALLOC_WITH_JEMALLOC
+CSRCS = ld_malloc_wrappers.c
 ifeq (,$(filter-out Linux,$(OS_TARGET)))
 EXTRA_DSO_LDOPTS += -lpthread
 endif
 endif
 endif
 
 ifeq (,$(filter-out WINCE,$(OS_ARCH)))
 # mozalloc gets its allocation methods from the shunt, which gets their 
new file mode 100644
--- /dev/null
+++ b/memory/mozalloc/ld_malloc_wrappers.c
@@ -0,0 +1,140 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2010
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *  Brad Lassey <blassey@mozilla.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+#include <stddef.h>             // for size_t
+#include <stdlib.h>             // for malloc, free
+#include "mozalloc.h"
+#include <malloc.h>
+     
+#ifdef __malloc_hook
+static void* moz_malloc_hook(size_t size, const void *caller)
+{
+  return moz_malloc(size);
+}
+
+static void* moz_realloc_hook(void *ptr, size_t size, const void *caller)
+{
+  return moz_realloc(ptr, size);
+}
+
+static void moz_free_hook(void *ptr, const void *caller)
+{
+  moz_free(ptr);
+}
+
+static void* moz_memalign_hook(size_t align, size_t size, const void *caller)
+{
+  return moz_memalign(align, size);
+}
+
+static void
+moz_malloc_init_hook (void)
+{
+  __malloc_hook = moz_malloc_hook;
+  __realloc_hook = moz_realloc_hook;
+  __free_hook = moz_free_hook;
+  __memalign_hook = moz_memalign_hook;
+}
+
+/* Override initializing hook from the C library. */
+void (*__malloc_initialize_hook) (void) = moz_malloc_init_hook;
+#endif
+
+inline void  __wrap_free(void* ptr)
+{
+  moz_free(ptr);
+}
+
+inline void* __wrap_malloc(size_t size)
+{
+  return moz_malloc(size);
+}
+
+inline void* __wrap_realloc(void* ptr, size_t size)
+{
+  return moz_realloc(ptr, size);
+}
+
+inline void* __wrap_calloc(size_t num, size_t size)
+{
+  return moz_calloc(num, size);
+}
+
+inline void* __wrap_valloc(size_t size)
+{
+  return moz_valloc(size);
+}
+
+inline void* __wrap_memalign(size_t align, size_t size)
+{
+  return moz_memalign(align, size);
+}
+
+inline char* __wrap_strdup(char* str)
+{
+  return moz_strdup(str);
+}
+
+inline char* __wrap_strndup(const char* str, size_t size) {
+  return moz_strndup(str, size);
+}
+
+
+inline void  __wrap_PR_Free(void* ptr)
+{
+  moz_free(ptr);
+}
+
+inline void* __wrap_PR_Malloc(size_t size)
+{
+  return moz_malloc(size);
+}
+
+inline void* __wrap_PR_Realloc(void* ptr, size_t size)
+{
+  return moz_realloc(ptr, size);
+}
+
+inline void* __wrap_PR_Calloc(size_t num, size_t size)
+{
+  return moz_calloc(num, size);
+}
+
+inline int __wrap_posix_memalign(void **memptr, size_t alignment, size_t size)
+{
+  return moz_posix_memalign(memptr, alignment, size);
+}
--- a/memory/mozalloc/mozalloc.cpp
+++ b/memory/mozalloc/mozalloc.cpp
@@ -69,25 +69,26 @@
 #if defined(__GNUC__) && (__GNUC__ > 2)
 #define LIKELY(x)    (__builtin_expect(!!(x), 1))
 #define UNLIKELY(x)  (__builtin_expect(!!(x), 0))
 #else
 #define LIKELY(x)    (x)
 #define UNLIKELY(x)  (x)
 #endif
 
-#if defined(MOZ_MEMORY_ANDROID) || defined(WRAP_MALLOC)
+#if defined(MOZ_MEMORY_ANDROID) || defined(WRAP_MALLOC_WITH_JEMALLOC)
 #include "jemalloc.h"
 #define malloc(a)     je_malloc(a)
 #define valloc(a)     je_valloc(a)
 #define calloc(a, b)  je_calloc(a, b)
 #define realloc(a, b) je_realloc(a, b)
 #define free(a)       je_free(a)
 #define strdup(a)     je_strdup(a)
 #define strndup(a, b) je_strndup(a, b)
+#define posix_memalign(a, b, c)  je_posix_memalign(a, b, c)
 #endif
 
 void
 moz_free(void* ptr)
 {
     free(ptr);
 }
 
deleted file mode 100644
--- a/memory/mozalloc/wraps.c
+++ /dev/null
@@ -1,102 +0,0 @@
-#include <stddef.h>             // for size_t
-#include <stdlib.h>             // for malloc, free
-#include "mozalloc.h"
-#ifdef MOZ_MEMORY_ANDROID
-#include <android/log.h>
-#define LOG(args...) __android_log_print(ANDROID_LOG_INFO, "wrap", args)
-#endif
-#include <malloc.h>
-     
-#ifdef __malloc_hook
-static void* moz_malloc_hook(size_t size, const void *caller)
-{
-  return moz_malloc(size);
-}
-
-static void* moz_realloc_hook(void *ptr, size_t size, const void *caller)
-{
-  return moz_realloc(ptr, size);
-}
-
-static void moz_free_hook(void *ptr, const void *caller)
-{
-  moz_free(ptr);
-}
-
-static void* moz_memalign_hook(size_t align, size_t size, const void *caller)
-{
-  return moz_memalign(align, size);
-}
-
-static void
-moz_malloc_init_hook (void)
-{
-  __malloc_hook = moz_malloc_hook;
-  __realloc_hook = moz_realloc_hook;
-  __free_hook = moz_free_hook;
-  __memalign_hook = moz_memalign_hook;
-}
-
-/* Override initializing hook from the C library. */
-void (*__malloc_initialize_hook) (void) = moz_malloc_init_hook;
-#endif
-
-inline void  __wrap_free(void* ptr)
-{
-  moz_free(ptr);
-}
-
-inline void* __wrap_malloc(size_t size)
-{
-  return moz_malloc(size);
-}
-
-inline void* __wrap_realloc(void* ptr, size_t size)
-{
-  return moz_realloc(ptr, size);
-}
-
-inline void* __wrap_calloc(size_t num, size_t size)
-{
-  return moz_calloc(num, size);
-}
-
-inline void* __wrap_valloc(size_t size)
-{
-  return moz_valloc(size);
-}
-
-inline void* __wrap_memalign(size_t align, size_t size)
-{
-  return moz_memalign(align, size);
-}
-
-inline char* __wrap_strdup(char* str)
-{
-  return moz_strdup(str);
-}
-
-inline char* __wrap_strndup(const char* str, size_t size) {
-  return moz_strndup(str, size);
-}
-
-
-inline void  __wrap_PR_Free(void* ptr)
-{
-  moz_free(ptr);
-}
-
-inline void* __wrap_PR_Malloc(size_t size)
-{
-  return moz_malloc(size);
-}
-
-inline void* __wrap_PR_Realloc(void* ptr, size_t size)
-{
-  return moz_realloc(ptr, size);
-}
-
-inline void* __wrap_PR_Calloc(size_t num, size_t size)
-{
-  return moz_calloc(num, size);
-}