summaryrefslogtreecommitdiff
path: root/www/firefox/files/patch-bug788955
blob: 39a8cd7ff70d816dd130a06211e96071558fce67 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
diff --git Makefile.in Makefile.in
index e341462..f75bd55 100644
--- Makefile.in
+++ Makefile.in
@@ -48,8 +48,10 @@ 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
diff --git allmakefiles.sh allmakefiles.sh
index 6a9be4b..d2e49e3 100755
--- allmakefiles.sh
+++ allmakefiles.sh
@@ -59,7 +59,7 @@ if [ ! "$LIBXUL_SDK" ]; then
     mozglue/Makefile
     mozglue/build/Makefile
   "
-  if [ "$MOZ_JEMALLOC" ]; then
+  if [ "$MOZ_JEMALLOC" -a -z "$MOZ_NATIVE_JEMALLOC" ]; then
     add_makefiles "
       memory/jemalloc/Makefile
     "
--- config/autoconf.mk.in
+++ config/autoconf.mk.in
@@ -74,6 +74,7 @@ MOZ_JSDEBUGGER  = @MOZ_JSDEBUGGER@
 MOZ_IPDL_TESTS 	= @MOZ_IPDL_TESTS@
 MOZ_MEMORY      = @MOZ_MEMORY@
 MOZ_JEMALLOC    = @MOZ_JEMALLOC@
+MOZ_NATIVE_JEMALLOC    = @MOZ_NATIVE_JEMALLOC@
 MOZ_PROFILING   = @MOZ_PROFILING@
 MOZ_ENABLE_PROFILER_SPS = @MOZ_ENABLE_PROFILER_SPS@
 MOZ_JPROF       = @MOZ_JPROF@
diff --git configure.in configure.in
index bb05782..2f32516 100644
--- configure.in
+++ configure.in
@@ -3711,21 +3711,22 @@ fi
 
 dnl Check for the existence of various allocation headers/functions
 
+MALLOC_HEADERS="malloc.h malloc_np.h malloc/malloc.h sys/malloc.h"
 MALLOC_H=
-MOZ_CHECK_HEADER(malloc.h,        [MALLOC_H=malloc.h])
-if test "$MALLOC_H" = ""; then
-  MOZ_CHECK_HEADER(malloc/malloc.h, [MALLOC_H=malloc/malloc.h])
-  if test "$MALLOC_H" = ""; then
-    MOZ_CHECK_HEADER(sys/malloc.h,    [MALLOC_H=sys/malloc.h])
+
+for file in $MALLOC_HEADERS; do
+  MOZ_CHECK_HEADER($file, [MALLOC_H=$file])
+  if test "$MALLOC_H" != ""; then
+    AC_DEFINE_UNQUOTED(MALLOC_H, <$MALLOC_H>)
+    break
   fi
-fi
-if test "$MALLOC_H" != ""; then
-   AC_DEFINE_UNQUOTED(MALLOC_H, <$MALLOC_H>)
-fi
+done
 
 MOZ_ALLOCATING_FUNCS="strndup posix_memalign memalign valloc"
 AC_CHECK_FUNCS(strndup posix_memalign memalign valloc)
 
+AC_CHECK_FUNCS(malloc_usable_size)
+
 dnl See if compiler supports some gcc-style attributes
 
 AC_CACHE_CHECK(for __attribute__((always_inline)),
@@ -6939,6 +6940,18 @@ else
 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
@@ -7033,6 +7046,7 @@ else
 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)
@@ -8820,10 +8834,22 @@ 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"
+  case "$OS_ARCH" in
+    Linux|DragonFly|FreeBSD|NetBSD|OpenBSD)
+      MANGLE="malloc calloc valloc free realloc posix_memalign"
+      case "$OS_ARCH" in
+        Linux)
+          MANGLE="$MANGLE memalign malloc_usable_size"
+          ;;
+        FreeBSD)
+          MANGLE="$MANGLE malloc_usable_size"
+          ;;
+      esac
+      ;;
+  esac
+  if test -n "$MANGLE"; then
     MANGLED=
     JEMALLOC_WRAPPER=
     if test -n "$_WRAP_MALLOC"; then
diff --git memory/build/Makefile.in memory/build/Makefile.in
index dca0f48..af93ee0 100644
--- memory/build/Makefile.in
+++ memory/build/Makefile.in
@@ -22,7 +22,9 @@ 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
diff --git memory/build/extraMallocFuncs.c memory/build/extraMallocFuncs.c
index 9d87629..03c8320 100644
--- memory/build/extraMallocFuncs.c
+++ memory/build/extraMallocFuncs.c
@@ -94,8 +94,16 @@ wrap(wcsdup)(const wchar_t *src)
 #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>
diff --git memory/build/mozjemalloc_compat.c memory/build/mozjemalloc_compat.c
index 10a845a..94ad96e 100644
--- memory/build/mozjemalloc_compat.c
+++ memory/build/mozjemalloc_compat.c
@@ -5,14 +5,21 @@
 #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;
 }
diff --git memory/jemalloc/src/src/mutex.c memory/jemalloc/src/src/mutex.c
index 37a843e..55e18c2 100644
--- memory/jemalloc/src/src/mutex.c
+++ memory/jemalloc/src/src/mutex.c
@@ -64,7 +64,7 @@ pthread_create(pthread_t *__restrict thread,
 /******************************************************************************/
 
 #ifdef JEMALLOC_MUTEX_INIT_CB
-int	_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
+JEMALLOC_EXPORT int	_pthread_mutex_init_calloc_cb(pthread_mutex_t *mutex,
     void *(calloc_cb)(size_t, size_t));
 #endif
 
diff --git memory/mozalloc/mozalloc.cpp memory/mozalloc/mozalloc.cpp
index 5b61050b..5b3399a 100644
--- memory/mozalloc/mozalloc.cpp
+++ memory/mozalloc/mozalloc.cpp
@@ -12,16 +12,13 @@
 #include <sys/types.h>
 
 #if defined(MALLOC_H)
-#  include MALLOC_H             // for memalign, valloc where available
+#  include MALLOC_H             // for memalign, valloc, malloc_size, malloc_usable_size
 #endif // if defined(MALLOC_H)
 #include <stddef.h>             // for size_t
 #include <stdlib.h>             // for malloc, free
 #if defined(XP_UNIX)
 #  include <unistd.h>           // for valloc on *BSD
 #endif //if defined(XP_UNIX)
-#if defined(__FreeBSD__)
-#  include <malloc_np.h>        // for malloc_usable_size
-#endif // if defined(__FreeBSD__)
 
 #if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec))
 #  define MOZALLOC_EXPORT __declspec(dllexport)
@@ -213,8 +210,7 @@ moz_malloc_usable_size(void *ptr)
 
 #if defined(XP_MACOSX)
     return malloc_size(ptr);
-#elif defined(MOZ_MEMORY) || (defined(XP_LINUX) && !defined(ANDROID)) || defined(__FreeBSD__)
-    // Android bionic libc doesn't have malloc_usable_size.
+#elif defined(HAVE_MALLOC_USABLE_SIZE) || defined(MOZ_MEMORY)
     return malloc_usable_size(ptr);
 #elif defined(XP_WIN)
     return _msize(ptr);
diff --git memory/mozjemalloc/jemalloc.h memory/mozjemalloc/jemalloc.h
index f0e0878..2486e83 100644
--- memory/mozjemalloc/jemalloc.h
+++ memory/mozjemalloc/jemalloc.h
@@ -37,22 +37,29 @@
 #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) || defined(MOZ_MEMORY_BSD)
 __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)
+#if defined(MOZ_MEMORY_LINUX) || defined(MOZ_MEMORY_BSD)
 __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
@@ -62,11 +69,11 @@ 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;
@@ -113,4 +120,6 @@ void    jemalloc_purge_freed_pages();
 } /* extern "C" */
 #endif
 
+#undef wrap
+
 #endif /* _JEMALLOC_H_ */
diff --git mozglue/build/Makefile.in mozglue/build/Makefile.in
index c333647..15ba505 100644
--- mozglue/build/Makefile.in
+++ mozglue/build/Makefile.in
@@ -23,7 +23,7 @@ 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