Bug 1368932 - Fill the replace-malloc malloc_table_t with the real allocator as a fallback. r=njn
authorMike Hommey <mh+mozilla@glandium.org>
Tue, 30 May 2017 15:57:28 +0900
changeset 412185 13a1349fb675560c774b9c8157f0e86c37e620e8
parent 412184 ff2a02c2733bcb2280baf75911861321bb53d810
child 412186 4753d3677cbe1780928b7b9844700539604c3218
push id1490
push usermtabara@mozilla.com
push dateMon, 31 Jul 2017 14:08:16 +0000
treeherdermozilla-release@70e32e6bf15e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersnjn
bugs1368932
milestone55.0a1
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 1368932 - Fill the replace-malloc malloc_table_t with the real allocator as a fallback. r=njn Until now, the malloc implementation functions would call the replace-malloc functions if they exist, and fallback to the real allocator in no such function exists. Instead of doing this, we now fill the empty slots in the malloc_table_t with the real allocator functions.
memory/build/replace_malloc.c
--- a/memory/build/replace_malloc.c
+++ b/memory/build/replace_malloc.c
@@ -124,16 +124,22 @@ replace_malloc_init_funcs()
 #  define MALLOC_FUNCS (MALLOC_FUNCS_INIT | MALLOC_FUNCS_BRIDGE)
 #  include "malloc_decls.h"
 #endif
 
 #define MALLOC_DECL(name, ...) \
   replace_malloc_table.name = REPLACE_MALLOC_GET_FUNC(handle, name);
 #include "malloc_decls.h"
   }
+
+#define MALLOC_DECL(name, ...) \
+  if (!replace_malloc_table.name) { \
+    replace_malloc_table.name = je_ ## name; \
+  }
+#include "malloc_decls.h"
 }
 
 /*
  * Below is the malloc implementation overriding jemalloc and calling the
  * replacement functions if they exist.
  */
 
 static int replace_malloc_initialized = 0;
@@ -169,21 +175,17 @@ init()
 #define ARGS2(t1, t2) ARGS1(t1), arg2
 #define ARGS3(t1, t2, t3) ARGS2(t1, t2), arg3
 
 #define GENERIC_MALLOC_DECL_HELPER(name, return, return_type, ...) \
   return_type name ## _impl(ARGS_HELPER(TYPED_ARGS, ##__VA_ARGS__)) \
   { \
     if (MOZ_UNLIKELY(!replace_malloc_initialized)) \
       init(); \
-    if (MOZ_LIKELY(!replace_malloc_table.name)) { \
-      return je_ ## name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
-    } else { \
-      return replace_malloc_table.name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
-    } \
+    return replace_malloc_table.name(ARGS_HELPER(ARGS, ##__VA_ARGS__)); \
   }
 
 #define GENERIC_MALLOC_DECL(name, return_type, ...) \
   GENERIC_MALLOC_DECL_HELPER(name, return, return_type, ##__VA_ARGS__)
 #define GENERIC_MALLOC_DECL_VOID(name, ...) \
   GENERIC_MALLOC_DECL_HELPER(name, , void, ##__VA_ARGS__)
 
 #define MALLOC_DECL(...) MOZ_MEMORY_API MACRO_CALL(GENERIC_MALLOC_DECL, (__VA_ARGS__))