Bug 680190 - Notify jemalloc when forking on Android; r=cjones

This commit is contained in:
Jim Chen 2011-08-30 17:11:36 -07:00
parent 1ac33bf7e2
commit 1214bdb110
2 changed files with 32 additions and 0 deletions

View File

@ -19,6 +19,13 @@
#include "base/string_tokenizer.h"
#include "base/string_util.h"
#ifdef MOZ_MEMORY_ANDROID
extern "C" {
extern void _malloc_prefork(void);
extern void _malloc_postfork(void);
}
#endif
namespace {
enum ParsingState {
@ -44,7 +51,17 @@ bool LaunchApp(const std::vector<std::string>& argv,
const environment_map& env_vars_to_set,
bool wait, ProcessHandle* process_handle,
ProcessArchitecture arch) {
#ifdef MOZ_MEMORY_ANDROID
/* We specifically don't call pthread_atfork in jemalloc because it is not
available in bionic until 2.3. However without it, jemalloc could
potentially deadlock, when stl allocates memory through jemalloc, after
fork and before execvp. Therefore, we must manually inform jemalloc here */
::_malloc_prefork();
#endif
pid_t pid = fork();
#ifdef MOZ_MEMORY_ANDROID
::_malloc_postfork();
#endif
if (pid < 0)
return false;

View File

@ -1266,8 +1266,13 @@ static
#endif
bool malloc_init_hard(void);
#ifdef MOZ_MEMORY_ANDROID
void _malloc_prefork(void);
void _malloc_postfork(void);
#else
static void _malloc_prefork(void);
static void _malloc_postfork(void);
#endif
#ifdef MOZ_MEMORY_DARWIN
/*
@ -5606,6 +5611,8 @@ MALLOC_OUT:
#if (!defined(MOZ_MEMORY_WINDOWS) && !defined(MOZ_MEMORY_DARWIN) && !defined(MOZ_MEMORY_ANDROID))
/* Prevent potential deadlock on malloc locks after fork. */
/* XXX on Android there is no pthread_atfork, so we specifically
call _malloc_prefork and _malloc_postfork in process_util_linux.cc */
pthread_atfork(_malloc_prefork, _malloc_postfork, _malloc_postfork);
#endif
@ -6436,7 +6443,11 @@ _msize(const void *ptr)
* is threaded here.
*/
#ifdef MOZ_MEMORY_ANDROID
void
#else
static void
#endif
_malloc_prefork(void)
{
unsigned i;
@ -6454,7 +6465,11 @@ _malloc_prefork(void)
malloc_mutex_lock(&huge_mtx);
}
#ifdef MOZ_MEMORY_ANDROID
void
#else
static void
#endif
_malloc_postfork(void)
{
unsigned i;