Bug 422055 Use jemalloc on OpenSolaris p=Jason Evans, Ginn Chen r=ted.mielczarek a=beltzner

This commit is contained in:
ginn.chen@sun.com 2008-04-30 00:14:44 -07:00
parent 4870aec3be
commit a696c7adae
5 changed files with 81 additions and 102 deletions

View file

@ -76,6 +76,9 @@ ifdef MOZ_MEMORY
ifeq ($(OS_ARCH),Darwin) ifeq ($(OS_ARCH),Darwin)
LIBS += -ljemalloc LIBS += -ljemalloc
endif endif
ifeq ($(OS_ARCH),SunOS)
SOLARIS_JEMALLOC_LDFLAGS = -L$(LIBXUL_DIST)/bin -lxul
endif
endif endif
ifdef LIBXUL_SDK ifdef LIBXUL_SDK

View file

@ -872,9 +872,9 @@ ifdef MSMANIFEST_TOOL
endif # MSVC with manifest tool endif # MSVC with manifest tool
else else
ifeq ($(CPP_PROG_LINK),1) 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 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 # CPP_PROG_LINK
endif # WINNT && !GNU_CC endif # WINNT && !GNU_CC
endif # OS2 endif # OS2
@ -943,9 +943,9 @@ ifdef MSMANIFEST_TOOL
endif # MSVC with manifest tool endif # MSVC with manifest tool
else else
ifeq ($(CPP_PROG_LINK),1) 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 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 # CPP_PROG_LINK
endif # WINNT && !GNU_CC endif # WINNT && !GNU_CC
endif # OS/2 VACPP endif # OS/2 VACPP

View file

@ -2402,6 +2402,7 @@ dnl the qsort routine under solaris is faulty
# $ORIGIN/.. is for shared libraries under components/ to locate shared # $ORIGIN/.. is for shared libraries under components/ to locate shared
# libraries one level up (e.g. libnspr4.so) # libraries one level up (e.g. libnspr4.so)
LDFLAGS="$LDFLAGS -z ignore -R '\$\$ORIGIN:\$\$ORIGIN/..'" LDFLAGS="$LDFLAGS -z ignore -R '\$\$ORIGIN:\$\$ORIGIN/..'"
MOZ_MEMORY=1
if test -z "$GNU_CC"; then if test -z "$GNU_CC"; then
NS_USE_NATIVE=1 NS_USE_NATIVE=1
MOZ_FIX_LINK_PATHS='-R $(LIBXUL_DIST)/bin' MOZ_FIX_LINK_PATHS='-R $(LIBXUL_DIST)/bin'

View file

@ -83,6 +83,12 @@ endif
else else
MODULE_OPTIMIZE_FLAGS = -O2 MODULE_OPTIMIZE_FLAGS = -O2
ifeq ($(OS_ARCH),SunOS)
ifndef GNU_CC
MODULE_OPTIMIZE_FLAGS = -xO5
endif
endif
LIBRARY_NAME = jemalloc LIBRARY_NAME = jemalloc
ifeq (Darwin,$(OS_TARGET)) ifeq (Darwin,$(OS_TARGET))

View file

@ -243,7 +243,9 @@ typedef unsigned long long uintmax_t;
#endif #endif
#ifndef MOZ_MEMORY_WINDOWS #ifndef MOZ_MEMORY_WINDOWS
#ifndef MOZ_MEMORY_SOLARIS
#include <sys/cdefs.h> #include <sys/cdefs.h>
#endif
#ifndef __DECONST #ifndef __DECONST
# define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var)) # define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
#endif #endif
@ -266,7 +268,9 @@ __FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.162 2008/02/06 02:59:54 jas
#endif #endif
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#ifndef MOZ_MEMORY_SOLARIS
#include <sys/sysctl.h> #include <sys/sysctl.h>
#endif
#include "tree.h" #include "tree.h"
#ifndef MOZ_MEMORY #ifndef MOZ_MEMORY
#include <sys/tree.h> #include <sys/tree.h>
@ -347,7 +351,7 @@ static const bool __isthreaded = true;
# define inline # define inline
#endif #endif
#ifndef MOZ_MEMORY_WINDOWS #ifdef __GNUC__
#define VISIBLE __attribute__((visibility("default"))) #define VISIBLE __attribute__((visibility("default")))
#else #else
#define VISIBLE #define VISIBLE
@ -1029,6 +1033,8 @@ const char *_malloc_options
= "AP10n" = "AP10n"
#elif (defined(MOZ_MEMORY_LINUX)) #elif (defined(MOZ_MEMORY_LINUX))
= "A10n2F" = "A10n2F"
#elif (defined(MOZ_MEMORY_SOLARIS))
= "A10n2F"
#endif #endif
; ;
@ -4984,53 +4990,11 @@ malloc_ncpus(void)
return (n); return (n);
} }
#elif (defined(MOZ_MEMORY_SOLARIS)) #elif (defined(MOZ_MEMORY_SOLARIS))
#include <kstat.h>
static inline unsigned static inline unsigned
malloc_ncpus(void) malloc_ncpus(void)
{ {
unsigned ret; return sysconf(_SC_NPROCESSORS_ONLN);
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);
} }
#else #else
static inline unsigned static inline unsigned
@ -5797,6 +5761,51 @@ RETURN:
return (ret); 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 VISIBLE
#ifdef MOZ_MEMORY_DARWIN #ifdef MOZ_MEMORY_DARWIN
inline int inline int
@ -5806,71 +5815,31 @@ int
posix_memalign(void **memptr, size_t alignment, size_t size) posix_memalign(void **memptr, size_t alignment, size_t size)
#endif #endif
{ {
int ret;
void *result; void *result;
if (malloc_init()) /* Make sure that alignment is a large enough power of 2. */
result = NULL; if (((alignment - 1) & alignment) != 0 || alignment < sizeof(void *)) {
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) {
#ifdef MALLOC_XMALLOC #ifdef MALLOC_XMALLOC
if (opt_xmalloc) { if (opt_xmalloc) {
_malloc_message(_getprogname(), _malloc_message(_getprogname(),
": (malloc) Error in posix_memalign(): out of memory\n", ": (malloc) Error in posix_memalign(): "
"", ""); "invalid alignment\n", "", "");
abort(); abort();
} }
#endif #endif
ret = ENOMEM; return (EINVAL);
goto RETURN;
} }
#ifdef MOZ_MEMORY_DARWIN
result = moz_memalign(alignment, size);
#else
result = memalign(alignment, size);
#endif
if (result == NULL)
return (ENOMEM);
*memptr = result; *memptr = result;
ret = 0; return (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;
} }
VISIBLE VISIBLE