Bug 422055 Use jemalloc on OpenSolaris p=Jason Evans, Ginn Chen r=ted.mielczarek a=beltzner
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -71,16 +71,19 @@ GRE_MILESTONE = $(shell $(PYTHON) $(tops
GRE_BUILDID = $(shell $(PYTHON) $(topsrcdir)/config/printconfigsetting.py $(LIBXUL_DIST)/bin/platform.ini Build BuildID)
DEFINES += -DGRE_MILESTONE=$(GRE_MILESTONE) -DGRE_BUILDID=$(GRE_BUILDID)
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
include $(topsrcdir)/config/rules.mk
else
# Build a binary bootstrapping with XRE_main
ifeq ($(USE_SHORT_LIBNAME), 1)
--- a/config/rules.mk
+++ b/config/rules.mk
@@ -867,19 +867,19 @@ ifdef MSMANIFEST_TOOL
else \
mt.exe -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
fi; \
rm -f $@.manifest; \
fi
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
endif # WINCE
ifdef ENABLE_STRIP
$(STRIP) $@
endif
@@ -938,19 +938,19 @@ ifeq (_WINNT,$(GNU_CC)_$(OS_ARCH))
ifdef MSMANIFEST_TOOL
@if test -f $@.manifest; then \
mt.exe -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
rm -f $@.manifest; \
fi
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
endif # WINCE
ifdef ENABLE_STRIP
$(STRIP) $@
endif
--- a/configure.in
+++ b/configure.in
@@ -2397,16 +2397,17 @@ alpha*-*-osf*)
dnl the qsort routine under solaris is faulty
*-solaris*)
AC_DEFINE(SOLARIS)
TARGET_NSPR_MDCPUCFG='\"md/_solaris.cfg\"'
SYSTEM_MAKEDEPEND=
# $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'
AC_DEFINE(NSCAP_DISABLE_DEBUG_PTR_TYPES)
if test "$CPU_ARCH" != "sparc"; then
CFLAGS="$CFLAGS -xstrconst -xbuiltin=%all"
CXXFLAGS="$CXXFLAGS -xbuiltin=%all -features=tmplife -norunpath"
--- a/memory/jemalloc/Makefile.in
+++ b/memory/jemalloc/Makefile.in
@@ -78,16 +78,22 @@ else
# Using a pre-built DLL, so just install it.
libs:: $(WIN32_CUSTOM_CRT_DIR)/mozcrt19.dll
$(INSTALL) $< $(FINAL_TARGET)
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))
# Build jemalloc as a shared lib, so that the library init function is executed.
FORCE_SHARED_LIB= 1
else
# Make jemalloc part of libxul, in order to reduce dynamic loading overhead.
MODULE = jemalloc
--- a/memory/jemalloc/jemalloc.c
+++ b/memory/jemalloc/jemalloc.c
@@ -238,17 +238,19 @@ typedef unsigned char uint8_t;
typedef unsigned uint32_t;
typedef unsigned long long uint64_t;
typedef unsigned long long uintmax_t;
#define MALLOC_DECOMMIT
#endif
#ifndef MOZ_MEMORY_WINDOWS
+#ifndef MOZ_MEMORY_SOLARIS
#include <sys/cdefs.h>
+#endif
#ifndef __DECONST
# define __DECONST(type, var) ((type)(uintptr_t)(const void *)(var))
#endif
#ifndef MOZ_MEMORY
__FBSDID("$FreeBSD: src/lib/libc/stdlib/malloc.c,v 1.162 2008/02/06 02:59:54 jasone Exp $");
#include "libc_private.h"
#ifdef MALLOC_DEBUG
# define _LOCK_DEBUG
@@ -261,17 +263,19 @@ typedef unsigned long long uintmax_t;
# define MADV_FREE MADV_DONTNEED
#endif
#include <sys/param.h>
#ifndef MOZ_MEMORY
#include <sys/stddef.h>
#endif
#include <sys/time.h>
#include <sys/types.h>
+#ifndef MOZ_MEMORY_SOLARIS
#include <sys/sysctl.h>
+#endif
#include "tree.h"
#ifndef MOZ_MEMORY
#include <sys/tree.h>
#endif
#include <sys/uio.h>
#ifndef MOZ_MEMORY
#include <sys/ktrace.h> /* Must come after several other sys/ includes. */
@@ -342,17 +346,17 @@ static const bool __isthreaded = true;
/* Disable inlining to make debugging easier. */
#ifdef inline
#undef inline
#endif
# define inline
#endif
-#ifndef MOZ_MEMORY_WINDOWS
+#ifdef __GNUC__
#define VISIBLE __attribute__((visibility("default")))
#else
#define VISIBLE
#endif
/* Size of stack-allocated buffer passed to strerror_r(). */
#define STRERROR_BUF 64
@@ -1024,16 +1028,18 @@ static chunk_stats_t stats_chunks;
*/
const char *_malloc_options
#ifdef MOZ_MEMORY_WINDOWS
= "A10n2F"
#elif (defined(MOZ_MEMORY_DARWIN))
= "AP10n"
#elif (defined(MOZ_MEMORY_LINUX))
= "A10n2F"
+#elif (defined(MOZ_MEMORY_SOLARIS))
+= "A10n2F"
#endif
;
#ifndef MALLOC_PRODUCTION
static bool opt_abort = true;
#ifdef MALLOC_FILL
static bool opt_junk = true;
#endif
@@ -4979,63 +4985,21 @@ malloc_ncpus(void)
error = host_processor_info(mach_host_self(), PROCESSOR_BASIC_INFO,
&n, &pinfo, &pinfocnt);
if (error != KERN_SUCCESS)
return (1); /* Error. */
else
return (n);
}
#elif (defined(MOZ_MEMORY_SOLARIS))
-#include <kstat.h>
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
malloc_ncpus(void)
{
/*
* We lack a way to determine the number of CPUs on this platform, so
@@ -5792,90 +5756,95 @@ RETURN:
#endif
errno = ENOMEM;
}
UTRACE(0, size, 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
#ifdef MOZ_MEMORY_DARWIN
inline int
moz_posix_memalign(void **memptr, size_t alignment, size_t size)
#else
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
#ifdef MOZ_MEMORY_DARWIN
inline void *
moz_valloc(size_t size)
#else
void *