components/desktop/firefox/patches/firefox-32-solaris_jemalloc_linkage.patch
changeset 5527 611b2d6efdfe
parent 5255 cea0e462549a
child 6919 7972aae0fb03
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/desktop/firefox/patches/firefox-32-solaris_jemalloc_linkage.patch	Tue Mar 01 12:56:53 2016 -0800
@@ -0,0 +1,124 @@
+This patch makes it so jemalloc is not included in firefox. Not accepted by 
+the upstream community. 
+Put jemalloc inside libxul. Then need firefox to depend on libxul
+and build jemalloc library.
+Remove lines - do not include memory for every program
+Need to create/add our own versions of the functions malloc_usable, jemalloc_stats, etc.
+Remove mozalloc library
+Check if we have jemalloc; if not, skip it.
+Build libxul and use flags -Wl,-z,interpose, needed to build the library.
+
+diff --git a/config/jemalloc_solaris.map b/config/jemalloc_solaris.map
+new file mode 100644
+--- /dev/null
++++ b/config/jemalloc_solaris.map
+@@ -0,0 +1,12 @@
++{
++    global:
++        calloc             = NODIRECT;
++        free               = NODIRECT;
++        jemalloc_stats     = NODIRECT;
++        malloc             = NODIRECT;
++        malloc_usable_size = NODIRECT;
++        memalign           = NODIRECT;
++        posix_memalign     = NODIRECT;
++        realloc            = NODIRECT;
++        valloc             = NODIRECT;
++};
+diff --git a/memory/mozalloc/mozalloc.cpp b/memory/mozalloc/mozalloc.cpp
+--- a/memory/mozalloc/mozalloc.cpp
++++ b/memory/mozalloc/mozalloc.cpp
+@@ -200,6 +200,14 @@
+ }
+ #endif // if defined(HAVE_VALLOC)
+ 
++#if defined(MOZ_MEMORY_SOLARIS)
++#include "jemalloc_types.h"
++extern "C" {
++extern size_t malloc_usable_size(const void *ptr);
++extern void jemalloc_stats(jemalloc_stats_t* stats);
++}
++#endif
++
+ size_t
+ moz_malloc_usable_size(void *ptr)
+ {
+@@ -209,7 +217,22 @@
+ #if defined(XP_MACOSX)
+     return malloc_size(ptr);
+ #elif defined(HAVE_MALLOC_USABLE_SIZE) || defined(MOZ_MEMORY)
++#if defined(SOLARIS)
++    static bool checked = false;
++    static bool using_jemalloc = false;
++    if (!checked) {
++        checked = true;
++        jemalloc_stats_t stats;
++        jemalloc_stats(&stats);
++        using_jemalloc = stats.allocated;
++    }
++    if (using_jemalloc)
++        return malloc_usable_size(ptr);
++    else
++        return 0;
++#else
+     return malloc_usable_size(ptr);
++#endif
+ #elif defined(XP_WIN)
+     return _msize(ptr);
+ #else
+diff --git a/storage/src/mozStorageService.cpp b/storage/src/mozStorageService.cpp
+--- a/storage/src/mozStorageService.cpp
++++ b/storage/src/mozStorageService.cpp
+@@ -514,9 +514,14 @@
+   int rc;
+ 
+ #ifdef MOZ_STORAGE_MEMORY
+-  rc = ::sqlite3_config(SQLITE_CONFIG_MALLOC, &memMethods);
+-  if (rc != SQLITE_OK)
+-    return convertResultCode(rc);
++  // in case other malloc library is PRELOAD-ed
++  void *test_jemalloc = malloc(4);
++  if (::moz_malloc_usable_size(test_jemalloc)) {
++    rc = ::sqlite3_config(SQLITE_CONFIG_MALLOC, &memMethods);
++    if (rc != SQLITE_OK)
++      return convertResultCode(rc);
++  }
++  free(test_jemalloc);
+ #endif
+ 
+   // Explicitly initialize sqlite3.  Although this is implicitly called by
+diff --git a/memory/jemalloc/src/include/jemalloc/internal/jemalloc_internal.h.in b/memory/jemalloc/src/include/jemalloc/internal/jemalloc_internal.h.in
+--- a/memory/jemalloc/src/include/jemalloc/internal/jemalloc_internal.h.in
++++ b/memory/jemalloc/src/include/jemalloc/internal/jemalloc_internal.h.in
+@@ -165,16 +165,19 @@ static const bool config_ivsalloc =
+  *   JEMALLOC_H_INLINES : Inline functions.
+  */
+ /******************************************************************************/
+ #define	JEMALLOC_H_TYPES
+ 
+ #include "jemalloc/internal/jemalloc_internal_macros.h"
+ 
+ /* Size class index type. */
++#ifdef __sun
++#define index_t je_index_t
++#endif
+ typedef unsigned index_t;
+ 
+ #define	MALLOCX_ARENA_MASK	((int)~0xff)
+ #define	MALLOCX_LG_ALIGN_MASK	((int)0x3f)
+ /* Use MALLOCX_ALIGN_GET() if alignment may not be specified in flags. */
+ #define	MALLOCX_ALIGN_GET_SPECIFIED(flags)				\
+     (ZU(1) << (flags & MALLOCX_LG_ALIGN_MASK))
+ #define	MALLOCX_ALIGN_GET(flags)					\
+--- a/memory/jemalloc/src/include/jemalloc/internal/jemalloc_internal.h.in	2015-09-15 13:37:17.326056000 +0800
++++ b/memory/jemalloc/src/include/jemalloc/internal/jemalloc_internal.h.in	2015-09-15 13:37:51.959830000 +0800
+@@ -204,6 +204,9 @@
+ #  ifdef __alpha__
+ #    define LG_QUANTUM		4
+ #  endif
++#  ifdef __sparc__
++#    define LG_QUANTUM		4
++#  endif
+ #  ifdef __sparc64__
+ #    define LG_QUANTUM		4
+ #  endif