From a696c7adae947d6f54d3e7c341d4e3ef7c559830 Mon Sep 17 00:00:00 2001 From: "ginn.chen@sun.com" Date: Wed, 30 Apr 2008 00:14:44 -0700 Subject: [PATCH] Bug 422055 Use jemalloc on OpenSolaris p=Jason Evans, Ginn Chen r=ted.mielczarek a=beltzner --- browser/app/Makefile.in | 3 + config/rules.mk | 8 +- configure.in | 1 + memory/jemalloc/Makefile.in | 6 ++ memory/jemalloc/jemalloc.c | 165 +++++++++++++++--------------------- 5 files changed, 81 insertions(+), 102 deletions(-) diff --git a/browser/app/Makefile.in b/browser/app/Makefile.in index e1c6d4b05128..0fc19f4740ee 100644 --- a/browser/app/Makefile.in +++ b/browser/app/Makefile.in @@ -76,6 +76,9 @@ ifdef MOZ_MEMORY ifeq ($(OS_ARCH),Darwin) LIBS += -ljemalloc endif +ifeq ($(OS_ARCH),SunOS) +SOLARIS_JEMALLOC_LDFLAGS = -L$(LIBXUL_DIST)/bin -lxul +endif endif ifdef LIBXUL_SDK diff --git a/config/rules.mk b/config/rules.mk index c783ce2a6fdd..bc10c19d659f 100644 --- a/config/rules.mk +++ b/config/rules.mk @@ -872,9 +872,9 @@ ifdef MSMANIFEST_TOOL endif # MSVC with manifest tool else ifeq ($(CPP_PROG_LINK),1) - $(CCC) -o $@ $(CXXFLAGS) $(WRAP_MALLOC_CFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(WRAP_MALLOC_LIB) $(PROFILER_LIBS) $(EXE_DEF_FILE) + $(CCC) -o $@ $(CXXFLAGS) $(WRAP_MALLOC_CFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(SOLARIS_JEMALLOC_LDFLAGS) $(LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(WRAP_MALLOC_LIB) $(PROFILER_LIBS) $(EXE_DEF_FILE) else # ! CPP_PROG_LINK - $(CC) -o $@ $(CFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(EXE_DEF_FILE) + $(CC) -o $@ $(CFLAGS) $(PROGOBJS) $(RESFILE) $(WIN32_EXE_LDFLAGS) $(SOLARIS_JEMALLOC_LDFLAGS) $(LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(BIN_FLAGS) $(EXE_DEF_FILE) endif # CPP_PROG_LINK endif # WINNT && !GNU_CC endif # OS2 @@ -943,9 +943,9 @@ ifdef MSMANIFEST_TOOL endif # MSVC with manifest tool else ifeq ($(CPP_PROG_LINK),1) - $(CCC) $(WRAP_MALLOC_CFLAGS) $(CXXFLAGS) -o $@ $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(WRAP_MALLOC_LIB) $(PROFILER_LIBS) $(BIN_FLAGS) + $(CCC) $(WRAP_MALLOC_CFLAGS) $(CXXFLAGS) -o $@ $< $(WIN32_EXE_LDFLAGS) $(SOLARIS_JEMALLOC_LDFLAGS) $(LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(WRAP_MALLOC_LIB) $(PROFILER_LIBS) $(BIN_FLAGS) else - $(CC) $(WRAP_MALLOC_CFLAGS) $(CFLAGS) $(OUTOPTION)$@ $< $(WIN32_EXE_LDFLAGS) $(LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(WRAP_MALLOC_LIB) $(PROFILER_LIBS) $(BIN_FLAGS) + $(CC) $(WRAP_MALLOC_CFLAGS) $(CFLAGS) $(OUTOPTION)$@ $< $(WIN32_EXE_LDFLAGS) $(SOLARIS_JEMALLOC_LDFLAGS) $(LDFLAGS) $(LIBS_DIR) $(LIBS) $(OS_LIBS) $(EXTRA_LIBS) $(WRAP_MALLOC_LIB) $(PROFILER_LIBS) $(BIN_FLAGS) endif # CPP_PROG_LINK endif # WINNT && !GNU_CC endif # OS/2 VACPP diff --git a/configure.in b/configure.in index 2a6728f4ab98..82796d7d6920 100644 --- a/configure.in +++ b/configure.in @@ -2402,6 +2402,7 @@ dnl the qsort routine under solaris is faulty # $ORIGIN/.. is for shared libraries under components/ to locate shared # libraries one level up (e.g. libnspr4.so) LDFLAGS="$LDFLAGS -z ignore -R '\$\$ORIGIN:\$\$ORIGIN/..'" + MOZ_MEMORY=1 if test -z "$GNU_CC"; then NS_USE_NATIVE=1 MOZ_FIX_LINK_PATHS='-R $(LIBXUL_DIST)/bin' diff --git a/memory/jemalloc/Makefile.in b/memory/jemalloc/Makefile.in index d565c7692873..ef677679f4fc 100644 --- a/memory/jemalloc/Makefile.in +++ b/memory/jemalloc/Makefile.in @@ -83,6 +83,12 @@ endif else MODULE_OPTIMIZE_FLAGS = -O2 +ifeq ($(OS_ARCH),SunOS) +ifndef GNU_CC +MODULE_OPTIMIZE_FLAGS = -xO5 +endif +endif + LIBRARY_NAME = jemalloc ifeq (Darwin,$(OS_TARGET)) diff --git a/memory/jemalloc/jemalloc.c b/memory/jemalloc/jemalloc.c index 6029e4d9c068..63eeffdd0aad 100644 --- a/memory/jemalloc/jemalloc.c +++ b/memory/jemalloc/jemalloc.c @@ -243,7 +243,9 @@ typedef unsigned long long uintmax_t; #endif #ifndef MOZ_MEMORY_WINDOWS +#ifndef MOZ_MEMORY_SOLARIS #include +#endif #ifndef __DECONST # define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) #endif @@ -266,7 +268,9 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.162 2008/02/06 02:59:54 jas #endif #include #include +#ifndef MOZ_MEMORY_SOLARIS #include +#endif #include "tree.h" #ifndef MOZ_MEMORY #include @@ -347,7 +351,7 @@ static const bool __isthreaded = true; # define inline #endif -#ifndef MOZ_MEMORY_WINDOWS +#ifdef __GNUC__ #define VISIBLE __attribute__((visibility("default"))) #else #define VISIBLE @@ -1029,6 +1033,8 @@ const char *_malloc_options = "AP10n" #elif (defined(MOZ_MEMORY_LINUX)) = "A10n2F" +#elif (defined(MOZ_MEMORY_SOLARIS)) += "A10n2F" #endif ; @@ -4984,53 +4990,11 @@ malloc_ncpus(void) return (n); } #elif (defined(MOZ_MEMORY_SOLARIS)) -#include static inline unsigned malloc_ncpus(void) { - unsigned ret; - kstat_ctl_t *ctl; - kstat_t *kstat; - kstat_named_t *named; - unsigned i; - - if ((ctl = kstat_open()) == NULL) - return (1); /* Error. */ - - if ((kstat = kstat_lookup(ctl, "unix", -1, "system_misc")) == NULL) - return (1); /* Error. */ - - if (kstat_read(ctl, kstat, NULL) == -1) - return (1); /* Error. */ - - named = KSTAT_NAMED_PTR(kstat); - - for (i = 0; i < kstat->ks_ndata; i++) { - if (strcmp(named[i].name, "ncpus") == 0) { - /* Figure out which one of these to actually use. */ - switch(named[i].data_type) { - case KSTAT_DATA_INT32: - ret = named[i].value.i32; - break; - case KSTAT_DATA_UINT32: - ret = named[i].value.ui32; - break; - case KSTAT_DATA_INT64: - ret = named[i].value.i64; - break; - case KSTAT_DATA_UINT64: - ret = named[i].value.ui64; - break; - default: - return (1); /* Error. */ - } - } - } - - kstat_close(ctl); /* Don't bother checking for an error. */ - - return (ret); + return sysconf(_SC_NPROCESSORS_ONLN); } #else static inline unsigned @@ -5797,6 +5761,51 @@ RETURN: return (ret); } +#ifdef MOZ_MEMORY_DARWIN +VISIBLE +inline void * +moz_memalign(size_t alignment, size_t size) +#elif (defined(MOZ_MEMORY_SOLARIS)) +# ifdef __SUNPRO_C +void * +memalign(size_t alignment, size_t size); +#pragma no_inline(memalign) +# elif (defined(__GNU_C__) +__attribute__((noinline)) +# endif +VISIBLE +void * +memalign(size_t alignment, size_t size) +#else +VISIBLE +inline void * +memalign(size_t alignment, size_t size) +#endif +{ + void *ret; + + assert(((alignment - 1) & alignment) == 0 && alignment >= + sizeof(void *)); + + if (malloc_init()) { + ret = NULL; + goto RETURN; + } + + ret = ipalloc(alignment, size); + +RETURN: +#ifdef MALLOC_XMALLOC + if (opt_xmalloc && ret == NULL) { + _malloc_message(_getprogname(), + ": (malloc) Error in memalign(): out of memory\n", "", ""); + abort(); + } +#endif + UTRACE(0, size, ret); + return (ret); +} + VISIBLE #ifdef MOZ_MEMORY_DARWIN inline int @@ -5806,71 +5815,31 @@ int posix_memalign(void **memptr, size_t alignment, size_t size) #endif { - int ret; void *result; - if (malloc_init()) - result = NULL; - else { - /* Make sure that alignment is a large enough power of 2. */ - if (((alignment - 1) & alignment) != 0 - || alignment < sizeof(void *)) { -#ifdef MALLOC_XMALLOC - if (opt_xmalloc) { - _malloc_message(_getprogname(), - ": (malloc) Error in posix_memalign(): " - "invalid alignment\n", "", ""); - abort(); - } -#endif - result = NULL; - ret = EINVAL; - goto RETURN; - } - - result = ipalloc(alignment, size); - } - - if (result == NULL) { + /* Make sure that alignment is a large enough power of 2. */ + if (((alignment - 1) & alignment) != 0 || alignment < sizeof(void *)) { #ifdef MALLOC_XMALLOC if (opt_xmalloc) { _malloc_message(_getprogname(), - ": (malloc) Error in posix_memalign(): out of memory\n", - "", ""); + ": (malloc) Error in posix_memalign(): " + "invalid alignment\n", "", ""); abort(); } #endif - ret = ENOMEM; - goto RETURN; + return (EINVAL); } +#ifdef MOZ_MEMORY_DARWIN + result = moz_memalign(alignment, size); +#else + result = memalign(alignment, size); +#endif + if (result == NULL) + return (ENOMEM); + *memptr = result; - ret = 0; - -RETURN: - UTRACE(0, size, result); - return (ret); -} - -VISIBLE -#ifdef MOZ_MEMORY_DARWIN -inline void * -moz_memalign(size_t alignment, size_t size) -#else -void * -memalign(size_t alignment, size_t size) -#endif -{ - void *ret; - -#ifdef MOZ_MEMORY_DARWIN - if (moz_posix_memalign(&ret, alignment, size) != 0) -#else - if (posix_memalign(&ret, alignment, size) != 0) -#endif - return (NULL); - - return ret; + return (0); } VISIBLE