Bug 1399921 - Register zone allocator independently, and delay jemalloc initialization on mac. r=njn

In bug 1361258, we unified the initialization sequence on mac, and
chose to make the zone registration happen after jemalloc
initialization.

The order between jemalloc init and zone registration shouldn't actually
matter, because jemalloc initializes the first time the allocator is
actually used.

On the other hand, in some build setups (e.g. with light optimization),
the initialization of the thread_arena thread local variable can happen
after the forced jemalloc initialization because of the order the
corresponding static initializers run. In some levels of optimization,
the thread_arena initializer resets the value the jemalloc
initialization has set, which subsequently makes choose_arena() return
a bogus value (or hit an assertion in ThreadLocal.h on debug builds).

So instead of initializing jemalloc from a static initializer, which
then registers the zone, we instead register the zone and let jemalloc
initialize itself when used, which increases the chances of the
thread_arena initializer running first.

--HG--
extra : rebase_source : 4d9a5340d097ac8528dc4aaaf0c05bbef40b59bb
This commit is contained in:
Mike Hommey 2017-09-15 07:34:48 +09:00
parent 50182c9f53
commit 078c8d1896
2 changed files with 3 additions and 22 deletions

View File

@ -4375,7 +4375,7 @@ huge_dalloc(void *ptr)
* implementation has to take pains to avoid infinite recursion during
* initialization.
*/
#if (defined(XP_WIN) || defined(XP_DARWIN))
#if defined(XP_WIN)
#define malloc_init() false
#else
static inline bool
@ -4389,10 +4389,6 @@ malloc_init(void)
}
#endif
#if defined(XP_DARWIN)
extern "C" void register_zone(void);
#endif
static size_t
GetKernelPageSize()
{
@ -4657,10 +4653,6 @@ MALLOC_OUT:
pthread_atfork(_malloc_prefork, _malloc_postfork_parent, _malloc_postfork_child);
#endif
#if defined(XP_DARWIN)
register_zone();
#endif
#ifndef XP_WIN
malloc_mutex_unlock(&init_lock);
#endif
@ -5450,18 +5442,6 @@ replace_malloc_init_funcs()
# include <dlfcn.h>
#endif
#if defined(XP_DARWIN)
__attribute__((constructor))
void
jemalloc_darwin_init(void)
{
if (malloc_init_hard())
MOZ_CRASH();
}
#endif
#if defined(__GLIBC__) && !defined(__UCLIBC__)
/*
* glibc provides the RTLD_DEEPBIND flag for dlopen which can make it possible

View File

@ -345,7 +345,8 @@ static malloc_zone_t *get_default_zone()
}
void
__attribute__((constructor))
static void
register_zone(void)
{
malloc_zone_t *default_zone = get_default_zone();