Bug 738176 - Completely disable jemalloc when it's supposed to be disabled on OSX, and cleanup exposed APIs. r=jlebar,r=khuey

This commit is contained in:
Mike Hommey 2012-04-05 09:20:53 +02:00
parent 161176956a
commit 46646a522a
14 changed files with 54 additions and 122 deletions

View File

@ -7214,13 +7214,6 @@ else
AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
;;
esac
if test "$OS_ARCH" != "WINNT"; then
dnl NB: this must be kept in sync with jemalloc.h
AC_DEFINE(HAVE_JEMALLOC_VALLOC)
fi
AC_DEFINE(HAVE_JEMALLOC_POSIX_MEMALIGN)
AC_DEFINE(HAVE_JEMALLOC_MEMALIGN)
fi # MOZ_MEMORY
AC_SUBST(MOZ_MEMORY)
AC_SUBST(MOZ_GLUE_LDFLAGS)

View File

@ -109,7 +109,7 @@ static void*
TryAllocAlignedBytes(size_t aSize)
{
// Use fallible allocators here
#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
#if defined(HAVE_POSIX_MEMALIGN)
void* ptr;
// Try to align for fast alpha recovery. This should only help
// cairo too, can't hurt.

View File

@ -19,10 +19,6 @@
#include "base/string_tokenizer.h"
#include "base/string_util.h"
#ifdef MOZ_MEMORY_ANDROID
#include "jemalloc.h"
#endif
namespace {
enum ParsingState {

View File

@ -4088,13 +4088,6 @@ if test "$MOZ_MEMORY"; then
AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
;;
esac
if test "$OS_ARCH" != "Darwin"; then
dnl NB: this must be kept in sync with jemalloc.h
AC_DEFINE(HAVE_JEMALLOC_VALLOC)
AC_DEFINE(HAVE_JEMALLOC_POSIX_MEMALIGN)
AC_DEFINE(HAVE_JEMALLOC_MEMALIGN)
fi
fi
AC_SUBST(MOZ_MEMORY)
AC_SUBST(MOZ_GLUE_LDFLAGS)

View File

@ -123,6 +123,8 @@
* jemalloc_purge_freed_pages(), which will force the OS to release those
* MADV_FREE'd pages, making the process's RSS reflect its true memory usage.
*
* The jemalloc_purge_freed_pages definition in jemalloc.h needs to be
* adjusted if MALLOC_DOUBLE_PURGE is ever enabled on Linux.
*/
#ifdef MOZ_MEMORY_DARWIN
#define MALLOC_DOUBLE_PURGE
@ -374,7 +376,7 @@ __FBSDID("$FreeBSD: head/lib/libc/stdlib/malloc.c 180599 2008-07-18 19:35:44Z ja
#endif
#include "jemalloc.h"
#include "jemalloc_types.h"
#include "linkedlist.h"
/* Some tools, such as /dev/dsp wrappers, LD_PRELOAD libraries that
@ -6550,8 +6552,11 @@ free(void *ptr)
*/
/* This was added by Mozilla for use by SQLite. */
#ifdef MOZ_MEMORY_DARWIN
static
#endif
size_t
je_malloc_usable_size_in_advance(size_t size)
je_malloc_good_size(size_t size)
{
/*
* This duplicates the logic in imalloc(), arena_malloc() and
@ -6581,7 +6586,7 @@ je_malloc_usable_size_in_advance(size_t size)
* Huge. We use PAGE_CEILING to get psize, instead of using
* CHUNK_CEILING to get csize. This ensures that this
* malloc_usable_size(malloc(n)) always matches
* je_malloc_usable_size_in_advance(n).
* je_malloc_good_size(n).
*/
size = PAGE_CEILING(size);
}
@ -6915,7 +6920,7 @@ zone_destroy(malloc_zone_t *zone)
static size_t
zone_good_size(malloc_zone_t *zone, size_t size)
{
return je_malloc_usable_size_in_advance(size);
return je_malloc_good_size(size);
}
static size_t

View File

@ -32,52 +32,38 @@
#ifndef _JEMALLOC_H_
#define _JEMALLOC_H_
#if defined(MOZ_MEMORY_DARWIN)
#include <malloc/malloc.h>
#endif
#include "jemalloc_types.h"
#ifdef __cplusplus
extern "C" {
#endif
extern const char *_malloc_options;
/* Darwin and Linux already have memory allocation functions */
#if (!defined(MOZ_MEMORY_DARWIN) && !defined(MOZ_MEMORY_LINUX))
void *malloc(size_t size);
void *valloc(size_t size);
void *calloc(size_t num, size_t size);
void *realloc(void *ptr, size_t size);
void free(void *ptr);
int posix_memalign(void **memptr, size_t alignment, size_t size);
#endif /* MOZ_MEMORY_DARWIN, MOZ_MEMORY_LINUX */
/* Android doesn't have posix_memalign */
#ifdef MOZ_MEMORY_ANDROID
int posix_memalign(void **memptr, size_t alignment, size_t size);
#if defined(MOZ_MEMORY_LINUX)
__attribute__((weak))
#endif
#if defined(MOZ_MEMORY_DARWIN) || defined(MOZ_MEMORY_WINDOWS)
void *je_malloc(size_t size);
void *je_valloc(size_t size);
void *je_calloc(size_t num, size_t size);
void *je_realloc(void *ptr, size_t size);
void je_free(void *ptr);
void *je_memalign(size_t alignment, size_t size);
int je_posix_memalign(void **memptr, size_t alignment, size_t size);
char *je_strndup(const char *src, size_t len);
char *je_strdup(const char *src);
size_t je_malloc_usable_size(const void *ptr);
#endif
/* Linux has memalign and malloc_usable_size */
#if !defined(MOZ_MEMORY_LINUX)
void *memalign(size_t alignment, size_t size);
size_t malloc_usable_size(const void *ptr);
#endif /* MOZ_MEMORY_LINUX */
void jemalloc_stats(jemalloc_stats_t *stats);
/* Computes the usable size in advance. */
size_t je_malloc_usable_size_in_advance(size_t size);
#if !defined(MOZ_MEMORY_DARWIN)
#if defined(MOZ_MEMORY_LINUX)
__attribute__((weak))
#endif
size_t je_malloc_good_size(size_t size);
#endif
static inline size_t je_malloc_usable_size_in_advance(size_t size) {
#if defined(MOZ_MEMORY_DARWIN)
return malloc_good_size(size);
#else
if (je_malloc_good_size)
return je_malloc_good_size(size);
else
return size;
#endif
}
/*
* On some operating systems (Mac), we use madvise(MADV_FREE) to hand pages
@ -104,7 +90,11 @@ size_t je_malloc_usable_size_in_advance(size_t size);
*
* If MALLOC_DOUBLE_PURGE is not defined, this function does nothing.
*/
#if defined(MOZ_MEMORY_LINUX)
static inline void jemalloc_purge_freed_pages() { }
#else
void jemalloc_purge_freed_pages();
#endif
#ifdef __cplusplus
} /* extern "C" */

View File

@ -53,11 +53,6 @@
# include <unistd.h> // for valloc on *BSD
#endif //if defined(XP_UNIX)
#if defined(MOZ_MEMORY)
// jemalloc.h doesn't redeclare symbols if they're provided by the OS
# include "jemalloc.h"
#endif
#if defined(XP_WIN) || (defined(XP_OS2) && defined(__declspec))
# define MOZALLOC_EXPORT __declspec(dllexport)
#endif
@ -67,6 +62,10 @@
#include "mozilla/mozalloc.h"
#include "mozilla/mozalloc_oom.h" // for mozalloc_handle_oom
/* Windows doesn't have malloc_usable_size, but jemalloc has */
#if defined(MOZ_MEMORY_WINDOWS)
extern "C" size_t malloc_usable_size(const void *ptr);
#endif
#if defined(__GNUC__) && (__GNUC__ > 2)
#define LIKELY(x) (__builtin_expect(!!(x), 1))
@ -76,21 +75,6 @@
#define UNLIKELY(x) (x)
#endif
#ifdef MOZ_MEMORY_DARWIN
#include "jemalloc.h"
#define malloc(a) je_malloc(a)
#define posix_memalign(a, b, c) je_posix_memalign(a, b, c)
#define valloc(a) je_valloc(a)
#define calloc(a, b) je_calloc(a, b)
#define memalign(a, b) je_memalign(a, b)
#define strdup(a) je_strdup(a)
#define strndup(a, b) je_strndup(a, b)
/* We omit functions which could be passed a memory region that was not
* allocated by jemalloc (realloc, free and malloc_usable_size). Instead,
* we use the system-provided functions, which will in turn call the
* jemalloc versions when appropriate */
#endif
void
moz_free(void* ptr)
{
@ -179,7 +163,7 @@ moz_strndup(const char* str, size_t strsize)
}
#endif // if defined(HAVE_STRNDUP)
#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
#if defined(HAVE_POSIX_MEMALIGN)
int
moz_xposix_memalign(void **ptr, size_t alignment, size_t size)
{
@ -214,7 +198,7 @@ moz_posix_memalign(void **ptr, size_t alignment, size_t size)
}
#endif // if defined(HAVE_POSIX_MEMALIGN)
#if defined(HAVE_MEMALIGN) || defined(HAVE_JEMALLOC_MEMALIGN)
#if defined(HAVE_MEMALIGN)
void*
moz_xmemalign(size_t boundary, size_t size)
{
@ -233,7 +217,7 @@ moz_memalign(size_t boundary, size_t size)
}
#endif // if defined(HAVE_MEMALIGN)
#if defined(HAVE_VALLOC) || defined(HAVE_JEMALLOC_VALLOC)
#if defined(HAVE_VALLOC)
void*
moz_xvalloc(size_t size)
{

View File

@ -146,7 +146,7 @@ MOZALLOC_EXPORT char* moz_strndup(const char* str, size_t strsize)
#endif /* if defined(HAVE_STRNDUP) */
#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
#if defined(HAVE_POSIX_MEMALIGN)
MOZALLOC_EXPORT int moz_xposix_memalign(void **ptr, size_t alignment, size_t size)
NS_WARN_UNUSED_RESULT;
@ -155,7 +155,7 @@ MOZALLOC_EXPORT int moz_posix_memalign(void **ptr, size_t alignment, size_t size
#endif /* if defined(HAVE_POSIX_MEMALIGN) */
#if defined(HAVE_MEMALIGN) || defined(HAVE_JEMALLOC_MEMALIGN)
#if defined(HAVE_MEMALIGN)
MOZALLOC_EXPORT void* moz_xmemalign(size_t boundary, size_t size)
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;
@ -164,7 +164,7 @@ MOZALLOC_EXPORT void* moz_memalign(size_t boundary, size_t size)
#endif /* if defined(HAVE_MEMALIGN) */
#if defined(HAVE_VALLOC) || defined(HAVE_JEMALLOC_VALLOC)
#if defined(HAVE_VALLOC)
MOZALLOC_EXPORT void* moz_xvalloc(size_t size)
NS_ATTR_MALLOC NS_WARN_UNUSED_RESULT;

View File

@ -63,11 +63,11 @@
#define strndup(_, __) moz_strndup(_, __)
#endif
#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
#if defined(HAVE_POSIX_MEMALIGN)
#define posix_memalign(_, __, ___) moz_posix_memalign(_, __, ___)
#endif
#if defined(HAVE_MEMALIGN) || defined(HAVE_JEMALLOC_MEMALIGN)
#if defined(HAVE_MEMALIGN)
#define memalign(_, __) moz_memalign(_, __)
#endif

View File

@ -64,11 +64,11 @@
# undef strndup
#endif
#if defined(HAVE_POSIX_MEMALIGN) || defined(HAVE_JEMALLOC_POSIX_MEMALIGN)
#if defined(HAVE_POSIX_MEMALIGN)
# undef posix_memalign
#endif
#if defined(HAVE_MEMALIGN) || defined(HAVE_JEMALLOC_MEMALIGN)
#if defined(HAVE_MEMALIGN)
# undef memalign
#endif

View File

@ -119,10 +119,6 @@ endif
include $(topsrcdir)/config/rules.mk
ifdef MOZ_MEMORY
ifeq (Darwin,$(OS_TARGET))
LDFLAGS += -init _jemalloc_darwin_init
endif
ifeq (WINNT,$(OS_TARGET))
# Roll our own custom logic here for the import library

View File

@ -51,7 +51,7 @@ EXPORTS
wcsdup=je_wcsdup
_wcsdup=je_wcsdup
malloc_usable_size=je_malloc_usable_size
je_malloc_usable_size_in_advance
je_malloc_good_size
jemalloc_stats
; A hack to work around the CRT (see giant comment in Makefile.in)
frex=je_dumb_free_thunk

View File

@ -530,19 +530,7 @@ Service::shutdown()
sqlite3_vfs *ConstructTelemetryVFS();
#ifdef MOZ_MEMORY
# if defined(XP_WIN) || defined(SOLARIS) || defined(ANDROID) || defined(XP_MACOSX)
# include "jemalloc.h"
# elif defined(XP_LINUX)
// jemalloc is directly linked into firefox-bin; libxul doesn't link
// with it. So if we tried to use je_malloc_usable_size_in_advance directly
// here, it wouldn't be defined. Instead, we don't include the jemalloc header
// and weakly link against je_malloc_usable_size_in_advance.
extern "C" {
extern size_t je_malloc_usable_size_in_advance(size_t size)
NS_VISIBILITY_DEFAULT __attribute__((weak));
}
# endif // XP_LINUX
# include "jemalloc.h"
namespace {

View File

@ -62,21 +62,8 @@ static PRInt64 GetExplicit()
}
#if defined(MOZ_MEMORY)
# if defined(XP_WIN) || defined(SOLARIS) || defined(ANDROID) || defined(XP_MACOSX)
# define HAVE_JEMALLOC_STATS 1
# include "jemalloc.h"
# elif defined(XP_LINUX)
# define HAVE_JEMALLOC_STATS 1
# include "jemalloc_types.h"
// jemalloc is directly linked into firefox-bin; libxul doesn't link
// with it. So if we tried to use jemalloc_stats directly here, it
// wouldn't be defined. Instead, we don't include the jemalloc header
// and weakly link against jemalloc_stats.
extern "C" {
extern void jemalloc_stats(jemalloc_stats_t* stats)
NS_VISIBILITY_DEFAULT __attribute__((weak));
}
# endif // XP_LINUX
# define HAVE_JEMALLOC_STATS 1
# include "jemalloc.h"
#endif // MOZ_MEMORY
#if defined(XP_LINUX) || defined(XP_MACOSX) || defined(SOLARIS)