Bug 1134039: Make SpiderMonkey standalone (JS_STANDALONE) builds use jemalloc and mozglue by default. r=glandium
authorJim Blandy <jimb@mozilla.com>
Thu, 19 Mar 2015 02:12:53 -0700
changeset 252257 5e45fba743aaa512910782fa01cd189ca15900ac
parent 252256 1d1f6f9ebaa17c66d5926344b4785b56efda3da9
child 252258 66e0cb4d7b9cb7382571c91a66e72fd6804f8671
push id1176
push userjlal@mozilla.com
push dateMon, 23 Mar 2015 03:02:54 +0000
reviewersglandium
bugs1134039
milestone39.0a1
Bug 1134039: Make SpiderMonkey standalone (JS_STANDALONE) builds use jemalloc and mozglue by default. r=glandium JS_STANDALONE builds don't need everything in mozglue; have mozglue omit the unneeded code for such builds. Since the SpiderMonkey binaries are now more like the other Gecko binaries, we can remove some special cases for JS_STANDALONE in GeckoSharedLibrary, GeckoProgram, etc. All Gecko binaries now use mozglue, which contains mfbt, so we no longer need mention mfbt explicitly. Add a property to the getBuildConfiguration testing function's result that indicates whether we're using jemalloc or not. Include the newly necessary source directories in the SpiderMonkey source package.
build/gecko_templates.mozbuild
configure.in
js/src/builtin/TestingFunctions.cpp
js/src/configure.in
js/src/make-source-package.sh
js/src/moz.build
moz.build
mozglue/build/moz.build
mozglue/moz.build
--- a/build/gecko_templates.mozbuild
+++ b/build/gecko_templates.mozbuild
@@ -50,19 +50,17 @@ def GeckoBinary(linkage='dependent', msv
 
         USE_LIBS += [
             xpcomglue,
         ]
     elif linkage != None:
         error('`linkage` must be "dependent", "standalone" or None')
 
     if mozglue:
-        if CONFIG['JS_STANDALONE']:
-            pass
-        elif CONFIG['MOZ_CRT']:
+        if CONFIG['MOZ_CRT']:
             if msvcrt == 'dynamic':
                 USE_LIBS += ['mozcrt']
             elif msvcrt == 'static':
                 USE_LIBS += ['mozglue']
             else:
                 error('`msvcrt` must be "dynamic" or "static"')
         else:
             LDFLAGS += CONFIG['MOZ_GLUE_WRAP_LDFLAGS']
--- a/configure.in
+++ b/configure.in
@@ -9214,19 +9214,16 @@ fi
 if test -n "$NSPR_CFLAGS" -o -n "$NSPR_LIBS"; then
     ac_configure_args="$ac_configure_args --with-nspr-cflags='$NSPR_CFLAGS'"
     ac_configure_args="$ac_configure_args --with-nspr-libs='$NSPR_LIBS'"
 fi
 ac_configure_args="$ac_configure_args --prefix=$dist"
 if test "$MOZ_MEMORY"; then
    ac_configure_args="$ac_configure_args --enable-jemalloc"
 fi
-if test -n "$MOZ_GLUE_IN_PROGRAM"; then
-   export MOZ_GLUE_IN_PROGRAM
-fi
 if test -n "$ZLIB_IN_MOZGLUE"; then
    MOZ_ZLIB_LIBS=
 fi
 export MOZ_NATIVE_ZLIB
 export MOZ_ZLIB_CFLAGS
 export MOZ_ZLIB_LIBS
 export MOZ_APP_NAME
 export MOZ_APP_REMOTINGNAME
--- a/js/src/builtin/TestingFunctions.cpp
+++ b/js/src/builtin/TestingFunctions.cpp
@@ -190,16 +190,24 @@ GetBuildConfiguration(JSContext *cx, uns
 #elif defined(XP_UNIX)
     value = BooleanValue(true);
 #else
     value = BooleanValue(false);
 #endif
     if (!JS_SetProperty(cx, info, "mapped-array-buffer", value))
         return false;
 
+#ifdef MOZ_MEMORY
+    value = BooleanValue(true);
+#else
+    value = BooleanValue(false);
+#endif
+    if (!JS_SetProperty(cx, info, "moz-memory", value))
+        return false;
+
     args.rval().setObject(*info);
     return true;
 }
 
 static bool
 GC(JSContext *cx, unsigned argc, jsval *vp)
 {
     CallArgs args = CallArgsFromVp(argc, vp);
--- a/js/src/configure.in
+++ b/js/src/configure.in
@@ -2988,21 +2988,31 @@ if test "$MOZ_DMD"; then
         CFLAGS="$CFLAGS -funwind-tables"
         CXXFLAGS="$CXXFLAGS -funwind-tables"
     fi
 fi
 
 dnl ========================================================
 dnl = Enable jemalloc
 dnl ========================================================
-MOZ_ARG_ENABLE_BOOL(jemalloc,
-[  --enable-jemalloc       Replace memory allocator with jemalloc],
-    MOZ_MEMORY=1,
+MOZ_MEMORY=1
+MOZ_ARG_DISABLE_BOOL(jemalloc,
+[  --disable-jemalloc       Don't replace memory allocator with jemalloc],
     MOZ_MEMORY=)
 
+case "${OS_TARGET}" in
+Android|WINNT|Darwin)
+  MOZ_GLUE_IN_PROGRAM=
+  ;;
+*)
+  dnl On !Android !Windows !OSX, we only want to link executables against mozglue
+  MOZ_GLUE_IN_PROGRAM=1
+  ;;
+esac
+
 if test "$MOZ_MEMORY"; then
   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.
--- a/js/src/make-source-package.sh
+++ b/js/src/make-source-package.sh
@@ -18,16 +18,18 @@ echo "    MOZJS_PATCH_VERSION = $MOZJS_P
 echo "    MOZJS_ALPHA = $MOZJS_ALPHA"
 
 cmd=${1:-build}
 pkg="mozjs-${MOZJS_MAJOR_VERSION}.${MOZJS_MINOR_VERSION}.${MOZJS_PATCH_VERSION:-${MOZJS_ALPHA:-0}}.tar.bz2"
 pkgpath=${pkg%.tar*}
 tgtpath=${DIST}/${pkgpath}
 taropts="-jcf"
 
+TOPSRCDIR=${SRCDIR}/../..
+
 case $cmd in
 "clean")
 	echo "Cleaning ${pkg} and ${tgtpath} ..."
 	rm -rf ${pkg} ${tgtpath}
 	;;
 "build")
         # Ensure that the configure script is newer than the configure.in script.
         if [ ${SRCDIR}/configure.in -nt ${SRCDIR}/configure ]; then
@@ -38,61 +40,72 @@ case $cmd in
 	echo "Packaging source tarball ${pkg}..."
 	if [ -d ${tgtpath} ]; then
 		echo "WARNING - dist tree ${tgtpath} already exists!"
 	fi
 	${MKDIR} -p ${tgtpath}/js/src
 
 	# copy the embedded icu
 	${MKDIR} -p ${tgtpath}/intl
-	cp -t ${tgtpath}/intl -dRp ${SRCDIR}/../../intl/icu
+	cp -t ${tgtpath}/intl -dRp ${TOPSRCDIR}/intl/icu
 
 	# copy main moz.build and Makefile.in
-	cp -t ${tgtpath} -dRp ${SRCDIR}/../../Makefile.in ${SRCDIR}/../../moz.build
+	cp -t ${tgtpath} -dRp ${TOPSRCDIR}/Makefile.in ${TOPSRCDIR}/moz.build
 
 	# copy a nspr file used by the build system
 	${MKDIR} -p ${tgtpath}/nsprpub/config
 	cp -t ${tgtpath}/nsprpub/config -dRp \
-		${SRCDIR}/../../nsprpub/config/make-system-wrappers.pl
+		${TOPSRCDIR}/nsprpub/config/make-system-wrappers.pl
 
 	# copy build and config directory.
-	cp -t ${tgtpath} -dRp ${SRCDIR}/../../build ${SRCDIR}/../../config
+	cp -t ${tgtpath} -dRp ${TOPSRCDIR}/build ${TOPSRCDIR}/config
 
 	# put in js itself
-	cp -t ${tgtpath} -dRp ${SRCDIR}/../../mfbt
+	cp -t ${tgtpath} -dRp ${TOPSRCDIR}/mfbt
 	cp -t ${tgtpath}/js -dRp ${SRCDIR}/../public
 	find ${SRCDIR} -mindepth 1 -maxdepth 1 -not -path ${DIST} -a -not -name ${pkg} \
 		-exec cp -t ${tgtpath}/js/src -dRp {} +
 
 	# distclean if necessary
 	if [ -e ${tgtpath}/js/src/Makefile ]; then
 		${MAKE} -C ${tgtpath}/js/src distclean
 	fi
 
 	cp -t ${tgtpath} -dRp \
-		${SRCDIR}/../../python
+		${TOPSRCDIR}/python
 	${MKDIR} -p ${tgtpath}/dom/bindings
 	cp -t ${tgtpath}/dom/bindings -dRp \
-		${SRCDIR}/../../dom/bindings/mozwebidlcodegen
+		${TOPSRCDIR}/dom/bindings/mozwebidlcodegen
 	${MKDIR} -p ${tgtpath}/media/webrtc/trunk/tools
 	cp -t ${tgtpath}/media/webrtc/trunk/tools -dRp \
-		${SRCDIR}/../../media/webrtc/trunk/tools/gyp
+		${TOPSRCDIR}/media/webrtc/trunk/tools/gyp
 	${MKDIR} -p ${tgtpath}/testing
 	cp -t ${tgtpath}/testing -dRp \
-		${SRCDIR}/../../testing/mozbase
+		${TOPSRCDIR}/testing/mozbase
 	${MKDIR} -p ${tgtpath}/modules/zlib
 	cp -t ${tgtpath}/modules/zlib -dRp \
-		${SRCDIR}/../../modules/zlib/src
+		${TOPSRCDIR}/modules/zlib/src
 	${MKDIR} -p ${tgtpath}/layout/tools/reftest
 	cp -t ${tgtpath}/layout/tools/reftest -dRp \
-	        ${SRCDIR}/../../layout/tools/reftest/reftest
+	        ${TOPSRCDIR}/layout/tools/reftest/reftest
 	${MKDIR} -p ${tgtpath}/toolkit/mozapps/installer
 	cp -t ${tgtpath}/toolkit/mozapps/installer -dRp \
-	        ${SRCDIR}/../../toolkit/mozapps/installer/package-name.mk \
-	        ${SRCDIR}/../../toolkit/mozapps/installer/upload-files.mk \
+	        ${TOPSRCDIR}/toolkit/mozapps/installer/package-name.mk \
+	        ${TOPSRCDIR}/toolkit/mozapps/installer/upload-files.mk
+	${MKDIR} -p ${tgtpath}/mozglue
+	cp -t ${tgtpath}/mozglue -dRp \
+	        ${TOPSRCDIR}/mozglue/build \
+	        ${TOPSRCDIR}/mozglue/crt \
+	        ${TOPSRCDIR}/mozglue/moz.build
+        ${MKDIR} -p ${tgtpath}/memory
+        cp -t ${tgtpath}/memory -dRp \
+                ${TOPSRCDIR}/memory/moz.build \
+                ${TOPSRCDIR}/memory/build \
+                ${TOPSRCDIR}/memory/jemalloc \
+                ${TOPSRCDIR}/memory/mozjemalloc
 
 	# remove *.pyc and *.pyo files if any
 	find ${tgtpath} -type f -name "*.pyc" -o -name "*.pyo" |xargs rm -f
 
 	# copy or create INSTALL
 	if [ -e {DIST}/INSTALL ]; then
 		cp -t ${tgtpath} ${DIST}/INSTALL
 	else
@@ -123,27 +136,27 @@ This release is based on a revision of M
 The changes in the patches/ directory were applied.
 
 MDN hosts the latest SpiderMonkey ${MOZJS_MAJOR_VERSION} release notes:
   https://developer.mozilla.org/en-US/docs/SpiderMonkey/${MOZJS_MAJOR_VERSION}
 README_EOF
 	fi
 
 	# copy LICENSE
-	if [ -e ${SRCDIR}/../../b2g/LICENSE ]; then
-		cp ${SRCDIR}/../../b2g/LICENSE ${tgtpath}/
+	if [ -e ${TOPSRCDIR}/b2g/LICENSE ]; then
+		cp ${TOPSRCDIR}/b2g/LICENSE ${tgtpath}/
 	else
-		cp ${SRCDIR}/../../LICENSE ${tgtpath}/
+		cp ${TOPSRCDIR}/LICENSE ${tgtpath}/
 	fi
 
 	# copy patches dir, if it currently exists in DIST
 	if [ -d ${DIST}/patches ]; then
 		cp -t ${tgtpath} -dRp ${DIST}/patches
-	elif [ -d ${SRCDIR}/../../patches ]; then
-		cp -t ${tgtpath} -dRp ${SRCDIR}/../../patches
+	elif [ -d ${TOPSRCDIR}/patches ]; then
+		cp -t ${tgtpath} -dRp ${TOPSRCDIR}/patches
 	fi
 
 	# Roll the tarball
 	${TAR} $taropts ${DIST}/../${pkg} -C ${DIST} ${pkgpath}
 	echo "done."
 	;;
 *)
 	echo "Unrecognized command: $cmd"
--- a/js/src/moz.build
+++ b/js/src/moz.build
@@ -62,22 +62,17 @@ TEST_DIRS += ['jsapi-tests', 'tests', 'g
 
 CONFIGURE_SUBST_FILES += [
     'devtools/rootAnalysis/Makefile',
     'js-confdefs.h',
     'js-config',
     'js.pc',
 ]
 
-if CONFIG['JS_STANDALONE']:
-    DEFINES['IMPL_MFBT'] = True
-    USE_LIBS += [
-        'mfbt',
-    ]
-else:
+if not CONFIG['JS_STANDALONE']:
     CONFIGURE_SUBST_FILES += [
         '../../config/autoconf-js.mk',
         '../../config/emptyvars-js.mk',
     ]
 
 CONFIGURE_DEFINE_FILES += [
     'js-config.h',
 ]
--- a/moz.build
+++ b/moz.build
@@ -29,29 +29,29 @@ if not CONFIG['JS_STANDALONE']:
 
     DIRS += [
         'build',
         'probes',
     ]
 
 if not CONFIG['LIBXUL_SDK']:
     DIRS += [
+        'mozglue',
         'mfbt',
         'config/external/zlib',
     ]
 
+    if CONFIG['MOZ_MEMORY']:
+        DIRS += ['memory']
+
     if not CONFIG['JS_STANDALONE']:
         if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
             DIRS += ['other-licenses/android']
 
-        if CONFIG['MOZ_MEMORY']:
-            DIRS += ['memory']
-
         DIRS += [
-            'mozglue',
             'memory/fallible',
             'memory/mozalloc',
             'memory/volatile',
         ]
 
 if not CONFIG['JS_STANDALONE']:
     DIRS += ['xpcom/xpidl']
 
--- a/mozglue/build/moz.build
+++ b/mozglue/build/moz.build
@@ -8,85 +8,88 @@
 # If this is ever changed, update MOZ_SHARED_MOZGLUE in browser/installer/Makefile.in
 if CONFIG['OS_TARGET'] in ('WINNT', 'Darwin', 'Android'):
     SharedLibrary('mozglue')
 else:
     Library('mozglue')
 
 SDK_LIBRARY = True
 
-if CONFIG['MOZ_MEMORY'] and (CONFIG['MOZ_NATIVE_JEMALLOC'] or FORCE_SHARED_LIB):
-    pass
-    # TODO: SHARED_LIBRARY_LIBS go here
-else:
-    # Temporary, until bug 662814 lands
-    NO_VISIBILITY_FLAGS = True
-    SOURCES += [
-        'dummy.cpp',
-    ]
-
 if CONFIG['OS_TARGET'] == 'Android':
     SOURCES += [
         'BionicGlue.cpp',
     ]
 
-if CONFIG['OS_TARGET'] == 'WINNT':
-    SOURCES += [
-        'WindowsDllBlocklist.cpp',
-    ]
-    DEFFILE = 'mozglue.def'
-    DISABLE_STL_WRAPPING = True
-    OS_LIBS += [
-        'version',
-    ]
-
-if CONFIG['MOZ_NUWA_PROCESS']:
-    EXPORTS.ipc += [
-        'Nuwa.h',
-    ]
-    SOURCES += [
-        'Nuwa.cpp',
-    ]
-
-EXPORTS.mozilla += [
-    'arm.h',
-    'SSE.h',
-    'WindowsDllBlocklist.h',
-]
-
-if CONFIG['CPU_ARCH'].startswith('x86'):
-    SOURCES += [
-        'SSE.cpp',
-    ]
-
-if CONFIG['CPU_ARCH'] == 'arm':
-    SOURCES += [
-        'arm.cpp',
-    ]
-
 if CONFIG['MOZ_ASAN']:
     SOURCES += [
         'AsanOptions.cpp',
     ]
 
+if CONFIG['OS_TARGET'] == 'WINNT':
+    DEFFILE = 'mozglue.def'
+
+if not CONFIG['JS_STANDALONE']:
+
+    if CONFIG['MOZ_MEMORY'] and (CONFIG['MOZ_NATIVE_JEMALLOC'] or FORCE_SHARED_LIB):
+        pass
+        # TODO: SHARED_LIBRARY_LIBS go here
+    else:
+        # Temporary, until bug 662814 lands
+        NO_VISIBILITY_FLAGS = True
+        SOURCES += [
+            'dummy.cpp',
+        ]
+
+    if CONFIG['OS_TARGET'] == 'WINNT':
+        SOURCES += [
+            'WindowsDllBlocklist.cpp',
+        ]
+        DISABLE_STL_WRAPPING = True
+        OS_LIBS += [
+            'version',
+        ]
+
+    if CONFIG['MOZ_NUWA_PROCESS']:
+        EXPORTS.ipc += [
+            'Nuwa.h',
+        ]
+        SOURCES += [
+            'Nuwa.cpp',
+        ]
+
+    EXPORTS.mozilla += [
+        'arm.h',
+        'SSE.h',
+        'WindowsDllBlocklist.h',
+    ]
+
+    if CONFIG['CPU_ARCH'].startswith('x86'):
+        SOURCES += [
+            'SSE.cpp',
+        ]
+
+    if CONFIG['CPU_ARCH'] == 'arm':
+        SOURCES += [
+            'arm.cpp',
+        ]
+
+    if CONFIG['MOZ_LINKER']:
+        USE_LIBS += [
+            'zlib',
+        ]
+
+    if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
+        SOURCES += [
+            'cpuacct.c',
+        ]
 
 USE_LIBS += [
     'mfbt',
 ]
 
-if CONFIG['MOZ_LINKER']:
-    USE_LIBS += [
-        'zlib',
-    ]
-
-if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'gonk':
-    SOURCES += [
-        'cpuacct.c',
-    ]
-
 DEFINES['IMPL_MFBT'] = True
 
 LDFLAGS += CONFIG['MOZ_GLUE_WRAP_LDFLAGS']
 
 if not CONFIG['_MSC_VER']:
     FAIL_ON_WARNINGS = True
 
 if CONFIG['OS_TARGET'] == 'Darwin':
--- a/mozglue/moz.build
+++ b/mozglue/moz.build
@@ -10,9 +10,10 @@ if CONFIG['MOZ_LINKER']:
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
     DIRS += ['android']
 
 DIRS += ['build']
 
 if CONFIG['MOZ_CRT']:
     DIRS += ['crt']
 
-TEST_DIRS += ['tests']
+if not CONFIG['JS_STANDALONE']:
+    TEST_DIRS += ['tests']