bug 407459. hooking jemalloc up to the build system. r=various people
authorpavlov@pavlov.net
Mon, 04 Feb 2008 19:16:24 -0800
changeset 11227 ee3be8228f90aea7fb987f886ac4a7d1f62021fd
parent 11226 ff7eb6fc3d2c1ed11222914b6e77d5c93aa3ec57
child 11228 18c5a40be5f2c4209ba5227f2d08d8b32f919ecc
push id1
push userbsmedberg@mozilla.com
push dateThu, 20 Mar 2008 16:49:24 +0000
treeherdermozilla-central@61007906a1f8 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersvarious
bugs407459
milestone1.9b3pre
bug 407459. hooking jemalloc up to the build system. r=various people
Makefile.in
allmakefiles.sh
browser/app/Makefile.in
browser/installer/unix/packages-static
browser/installer/windows/packages-static
config/autoconf.mk.in
configure.in
toolkit/crashreporter/google-breakpad/src/common/windows/string_utils-inl.h
--- a/Makefile.in
+++ b/Makefile.in
@@ -56,16 +56,20 @@ TIERS += base
 # tier "base" - basic setup
 #
 tier_base_dirs = \
 	config \
 	build \
 	probes \
 	$(NULL)
 
+ifdef MOZ_MEMORY
+tier_base_dirs += memory/jemalloc
+endif
+
 include $(topsrcdir)/$(MOZ_BUILD_APP)/build.mk
 
 TIERS += testharness
 
 # test harnesses
 ifdef ENABLE_TESTS
 tier_testharness_dirs += tools/test-harness
 endif
--- a/allmakefiles.sh
+++ b/allmakefiles.sh
@@ -62,16 +62,22 @@ build/unix/Makefile
 config/Makefile
 config/autoconf.mk
 config/mkdepend/Makefile
 config/doxygen.cfg
 probes/Makefile
 extensions/Makefile
 "
 
+if [ "$MOZ_MEMORY" ]; then
+  add_makefiles "
+    memory/jemalloc/Makefile
+  "
+fi
+
 #
 # Application-specific makefiles
 #
 if test -f "${srcdir}/${MOZ_BUILD_APP}/makefiles.sh"; then
   . "${srcdir}/${MOZ_BUILD_APP}/makefiles.sh"
 fi
 
 #
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -67,16 +67,22 @@ DEFINES += -DAPP_UA_NAME="$(APP_UA_NAME)
 
 DIST_FILES = application.ini
 
 GRE_MILESTONE = $(shell $(PYTHON) $(topsrcdir)/config/printconfigsetting.py $(LIBXUL_DIST)/bin/platform.ini Build Milestone)
 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
+ifneq ($(OS_ARCH),WINNT)
+LIBS += -ljemalloc
+endif
+endif
+
 ifdef LIBXUL_SDK
 include $(topsrcdir)/config/rules.mk
 else
 # Build a binary bootstrapping with XRE_main
 
 ifeq ($(USE_SHORT_LIBNAME), 1)
 PROGRAM = $(MOZ_APP_NAME)$(BIN_SUFFIX)
 else
--- a/browser/installer/unix/packages-static
+++ b/browser/installer/unix/packages-static
@@ -50,16 +50,17 @@ bin/platform.ini
 bin/mozilla-xremote-client
 bin/run-mozilla.sh
 bin/plugins/libnullplugin.so
 bin/res/cmessage.txt
 bin/res/effective_tld_names.dat
 bin/xpicleanup
 bin/libsqlite3.so
 bin/README.txt
+bin/libjemalloc.so
 
 ; [Components]
 bin/components/alerts.xpt
 bin/components/accessibility.xpt
 bin/components/appshell.xpt
 bin/components/appstartup.xpt
 bin/components/autocomplete.xpt
 bin/components/autoconfig.xpt
--- a/browser/installer/windows/packages-static
+++ b/browser/installer/windows/packages-static
@@ -42,16 +42,17 @@ bin\xpcom_core.dll
 bin\xpistub.dll
 bin\components\xpinstal.dll
 bin\components\jar50.dll
 #endif
 bin\Microsoft.VC80.CRT.manifest
 bin\msvcm80.dll
 bin\msvcp80.dll
 bin\msvcr80.dll
+bin\mozcrt19.dll
 
 [browser]
 ; [Base Browser Files]
 bin\@MOZ_APP_NAME@.exe
 bin\application.ini
 bin\platform.ini
 bin\plugins\npnul32.dll
 bin\res\cmessage.txt
--- a/config/autoconf.mk.in
+++ b/config/autoconf.mk.in
@@ -95,16 +95,17 @@ MOZ_DEBUG_FLAGS	= @MOZ_DEBUG_FLAGS@
 MOZ_DEBUG_LDFLAGS=@MOZ_DEBUG_LDFLAGS@
 MOZ_DBGRINFO_MODULES	= @MOZ_DBGRINFO_MODULES@
 MOZ_EXTENSIONS  = @MOZ_EXTENSIONS@
 MOZ_IMG_DECODERS= @MOZ_IMG_DECODERS@
 MOZ_IMG_ENCODERS= @MOZ_IMG_ENCODERS@
 MOZ_JSDEBUGGER  = @MOZ_JSDEBUGGER@
 MOZ_PERF_METRICS = @MOZ_PERF_METRICS@
 MOZ_LEAKY	= @MOZ_LEAKY@
+MOZ_MEMORY      = @MOZ_MEMORY@
 MOZ_JPROF       = @MOZ_JPROF@
 MOZ_SHARK       = @MOZ_SHARK@
 MOZ_XPCTOOLS    = @MOZ_XPCTOOLS@
 ENABLE_EAZEL_PROFILER=@ENABLE_EAZEL_PROFILER@
 EAZEL_PROFILER_CFLAGS=@EAZEL_PROFILER_CFLAGS@
 EAZEL_PROFILER_LIBS=@EAZEL_PROFILER_LIBS@
 GC_LEAK_DETECTOR = @GC_LEAK_DETECTOR@
 NS_TRACE_MALLOC = @NS_TRACE_MALLOC@
@@ -548,17 +549,23 @@ MOZ_MILESTONE_RELEASE = @MOZ_MILESTONE_R
 # Win32 options
 MOZ_PROFILE	= @MOZ_PROFILE@
 MOZ_BROWSE_INFO	= @MOZ_BROWSE_INFO@
 MOZ_TOOLS_DIR	= @MOZ_TOOLS_DIR@
 MOZ_DEBUG_SYMBOLS = @MOZ_DEBUG_SYMBOLS@
 MOZ_QUANTIFY	= @MOZ_QUANTIFY@
 MSMANIFEST_TOOL = @MSMANIFEST_TOOL@
 WIN32_REDIST_DIR = @WIN32_REDIST_DIR@
-
+WIN32_CRT_SRC_DIR = @WIN32_CRT_SRC_DIR@
+WIN32_CUSTOM_CRT_DIR = @WIN32_CUSTOM_CRT_DIR@
+# These are for custom CRT building
+ifneq (,$(WIN32_CRT_SRC_DIR)$(WIN32_CUSTOM_CRT_DIR))
+export LIB = @MOZ_LIB@
+export PATH = @MOZ_PATH@
+endif
 # python options.
 MOZ_PYTHON_EXTENSIONS = @MOZ_PYTHON_EXTENSIONS@
 MOZ_PYTHON = @MOZ_PYTHON@
 MOZ_PYTHON_PREFIX = @MOZ_PYTHON_PREFIX@
 MOZ_PYTHON_INCLUDES = @MOZ_PYTHON_INCLUDES@
 MOZ_PYTHON_LIBS = @MOZ_PYTHON_LIBS@
 MOZ_PYTHON_DEBUG_SUFFIX = @MOZ_PYTHON_DEBUG_SUFFIX@
 MOZ_PYTHON_DLL_SUFFIX = @MOZ_PYTHON_DLL_SUFFIX@
--- a/configure.in
+++ b/configure.in
@@ -5988,16 +5988,113 @@ MOZ_ARG_ENABLE_BOOL(logrefcnt,
     _ENABLE_LOGREFCNT= )
 if test "$_ENABLE_LOGREFCNT" = "1"; then
     AC_DEFINE(FORCE_BUILD_REFCNT_LOGGING)
 elif test -z "$_ENABLE_LOGREFCNT"; then
     AC_DEFINE(NO_BUILD_REFCNT_LOGGING)
 fi
 
 dnl ========================================================
+dnl = memory
+dnl ========================================================
+MOZ_ARG_ENABLE_BOOL(jemalloc,
+[  --enable-jemalloc         Replace memory allocator with jemalloc],
+    MOZ_MEMORY=1,
+    MOZ_MEMORY=)
+if test "$MOZ_MEMORY"; then
+
+  dnl Don't try to run compiler tests on Windows  
+  if test "$OS_ARCH" = "WINNT"; then
+    if test -z "$HAVE_64BIT_OS"; then
+      AC_DEFINE_UNQUOTED([MOZ_MEMORY_SIZEOF_PTR_2POW], 2)
+    else
+      AC_DEFINE_UNQUOTED([MOZ_MEMORY_SIZEOF_PTR_2POW], 3)
+    fi
+  else
+    AC_CHECK_SIZEOF([int *], [4])
+    case "${ac_cv_sizeof_int_p}" in
+    4)
+      AC_DEFINE_UNQUOTED([MOZ_MEMORY_SIZEOF_PTR_2POW], 2)
+      ;;
+    8)
+      AC_DEFINE_UNQUOTED([MOZ_MEMORY_SIZEOF_PTR_2POW], 3)
+      ;;
+    *)
+      AC_MSG_ERROR([Unexpected pointer size])
+      ;;
+    esac
+  fi
+
+  AC_DEFINE(MOZ_MEMORY)
+  if test "x$MOZ_DEBUG" = "x1"; then
+    AC_DEFINE(MOZ_MEMORY_DEBUG)
+  fi
+  dnl The generic feature tests that determine how to compute ncpus are long and
+  dnl complicated.  Therefore, simply define special cpp variables for the
+  dnl platforms we have special knowledge of.
+  case "${target_os}" in
+  darwin*)
+    AC_DEFINE(MOZ_MEMORY_DARWIN)
+    ;;
+  *-freebsd*)
+    AC_DEFINE(MOZ_MEMORY_BSD)
+    ;;
+  *linux*)
+    AC_DEFINE(MOZ_MEMORY_LINUX)
+    ;;
+  netbsd*)
+    AC_DEFINE(MOZ_MEMORY_BSD)
+    ;;
+  solaris*)
+    AC_DEFINE(MOZ_MEMORY_SOLARIS)
+    ;;
+  msvc*|mks*|cygwin*|mingw*)
+    AC_DEFINE(MOZ_MEMORY_WINDOWS)
+    dnl XXX: should test for vc8sp1 here, otherwise patching the crt src
+    dnl will fail miserably
+    if test "$_CC_SUITE" -lt "8"; then
+        AC_MSG_ERROR([Building jemalloc requires Visual C++ 2005 or better])
+    fi
+    if test -z "$WIN32_CRT_SRC_DIR" -a -z "$WIN32_CUSTOM_CRT_DIR"; then
+      if test -z "$VCINSTALLDIR" -o ! -d "$VCINSTALLDIR"; then
+        AC_MSG_ERROR([When building jemalloc, either set WIN32_CRT_SRC_DIR to the path to the Visual C++ CRT source (usually VCINSTALLDIR\crt\src), or set WIN32_CUSTOM_CRT_DIR to the path to a folder containing a pre-built CRT DLL.])
+      else
+        WIN32_CRT_SRC_DIR="$VCINSTALLDIR\crt\src"
+      fi
+    fi
+    if test -z "$WIN32_CRT_SRC_DIR"; then
+      # pre-built dll
+      WIN32_CUSTOM_CRT_DIR=`cd "$WIN32_CUSTOM_CRT_DIR" && pwd`
+      _WIN_UNIX_CRT_PATH="$WIN32_CUSTOM_CRT_DIR"
+    else
+      # CRT source directory
+      WIN32_CRT_SRC_DIR=`cd "$WIN32_CRT_SRC_DIR" && pwd`
+      _CRT_BASE_DIR=`basename "$WIN32_CRT_SRC_DIR"`
+      _WIN_UNIX_CRT_PATH="$_objdir/memory/jemalloc/$_CRT_BASE_DIR/build/intel"
+    fi
+    dnl need win32 paths in LIB, hence this python abuse.  extra brackets
+    dnl are to avoid m4
+    _WIN_CRT_PATH=[`$PYTHON -c 'import sys, os.path; print os.path.normpath(sys.argv[1])' "$_WIN_UNIX_CRT_PATH"`]
+    MOZ_LIB="$_WIN_CRT_PATH;$LIB"
+    dnl Needs to be in PATH too, since our tools will wind up linked against it.
+    dnl This needs to be unix style.
+    MOZ_PATH="$PATH:$_WIN_UNIX_CRT_PATH"
+    ;;
+  *)
+    AC_MSG_ERROR([--enable-jemalloc not supported on ${target}])
+    ;;
+  esac
+fi
+AC_SUBST(MOZ_MEMORY)
+AC_SUBST(WIN32_CRT_SRC_DIR)
+AC_SUBST(WIN32_CUSTOM_CRT_DIR)
+AC_SUBST(MOZ_LIB)
+AC_SUBST(MOZ_PATH)
+
+dnl ========================================================
 dnl = Use malloc wrapper lib
 dnl ========================================================
 MOZ_ARG_ENABLE_BOOL(wrap-malloc,
 [  --enable-wrap-malloc    Wrap malloc calls (gnu linker only)],
     _WRAP_MALLOC=1,
     _WRAP_MALLOC= )
 
 if test -n "$_WRAP_MALLOC"; then
--- a/toolkit/crashreporter/google-breakpad/src/common/windows/string_utils-inl.h
+++ b/toolkit/crashreporter/google-breakpad/src/common/windows/string_utils-inl.h
@@ -51,16 +51,20 @@
 
 // A nonconforming version of swprintf, without the length argument, was
 // included with the CRT prior to MSVC8.  Although a conforming version was
 // also available via an overload, it is not reliably chosen.  _snwprintf
 // behaves as a standards-confirming swprintf should, so force the use of
 // _snwprintf when using older CRTs.
 #if _MSC_VER < 1400  // MSVC 2005/8
 #define swprintf _snwprintf
+#else
+// For MSVC8 and newer, swprintf_s is the recommended method. Conveniently,
+// it takes the same argument list as swprintf.
+#define swprintf swprintf_s
 #endif  // MSC_VER < 1400
 
 namespace google_breakpad {
 
 using std::string;
 using std::wstring;
 
 class WindowsStringUtils {