Bug 1039197 - Always build js engine with zlib. r=luke
authorMike Hommey <mh+mozilla@glandium.org>
Thu, 17 Jul 2014 08:42:17 +0900
changeset 216447 63c52b7ddc282ca2b334eb51c8ec32702c60d5d1
parent 216446 64d4dcf940f1e7e635f6cc0a59ba2182b1d95228
child 216448 8cf3f3b925a362186c6cdf408a46aa539d895db2
push id515
push userraliiev@mozilla.com
push dateMon, 06 Oct 2014 12:51:51 +0000
treeherdermozilla-release@267c7a481bef [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersluke
bugs1039197
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1039197 - Always build js engine with zlib. r=luke
js/src/Makefile.in
js/src/builtin/embedjs.py
js/src/jsscript.cpp
js/src/make-source-package.sh
js/src/vm/Compression.cpp
js/src/vm/Compression.h
js/src/vm/SelfHosting.cpp
moz.build
--- a/js/src/Makefile.in
+++ b/js/src/Makefile.in
@@ -17,16 +17,19 @@ TOPLEVEL_BUILD := 1
 run_for_side_effects := $(shell echo 'MAKE: $(MAKE)')
 STATIC_LIBRARY_NAME = js_static
 LIBS		= $(NSPR_LIBS)
 
 DIST_INSTALL = 1
 
 ifdef JS_STANDALONE
 SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,mfbt,$(DEPTH)/mfbt)
+ifndef MOZ_NATIVE_ZLIB
+SHARED_LIBRARY_LIBS += $(call EXPAND_LIBNAME_PATH,mozz,$(DEPTH)/modules/zlib/src)
+endif
 endif
 
 ifdef JS_HAS_CTYPES
 ifdef MOZ_NATIVE_FFI
 LOCAL_INCLUDES = $(MOZ_FFI_CFLAGS)
 endif
 
 ifdef MOZ_NATIVE_FFI
@@ -214,22 +217,16 @@ endif
 
 # HP-UX does not require the extra linking of "-lm"
 ifeq (,$(filter HP-UX WINNT,$(OS_ARCH)))
 EXTRA_LIBS	+= -lm
 endif
 
 CFLAGS += $(MOZ_ZLIB_CFLAGS)
 EXTRA_LIBS += $(MOZ_ZLIB_LIBS)
-# Enable zlib usage if zlib has been located. When building the browser on
-# Windows, MOZ_ZLIB_LIBS is empty because zlib is part of libmozglue. We thus
-# also enable zlib if mozglue is present.
-ifneq (,$(MOZ_ZLIB_LIBS)$(MOZ_GLUE_LDFLAGS))
-DEFINES += -DUSE_ZLIB
-endif
 
 ifdef MOZ_SHARED_ICU
 EXTRA_DSO_LDOPTS += $(MOZ_ICU_LIBS)
 else
 SHARED_LIBRARY_LIBS += $(MOZ_ICU_LIBS)
 endif
 
 ifeq ($(OS_ARCH),FreeBSD)
--- a/js/src/builtin/embedjs.py
+++ b/js/src/builtin/embedjs.py
@@ -91,36 +91,26 @@ def embed(cxx, preprocessorOption, msgs,
   args = ['-D%(k)s=%(v)s' % { 'k': k, 'v': env[k] } for k in env]
   preprocessed = preprocess(cxx, preprocessorOption, combinedSources, args)
   processed = '\n'.join([line for line in preprocessed.splitlines() if \
                          (line.strip() and not line.startswith('#'))])
 
   with open(js_out, 'w') as output:
     output.write(processed)
   with open(c_out, 'w') as output:
-    if 'USE_ZLIB' in env:
-      import zlib
-      compressed = zlib.compress(processed)
-      data = ToCArray(compressed)
-      output.write(HEADER_TEMPLATE % {
-          'sources_type': 'unsigned char',
-          'sources_data': data,
-          'sources_name': 'compressedSources',
-          'compressed_total_length': len(compressed),
-          'raw_total_length': len(processed)
-      })
-    else:
-      data = ToCAsciiArray(processed)
-      output.write(HEADER_TEMPLATE % {
-          'sources_type': 'char',
-          'sources_data': data,
-          'sources_name': 'rawSources',
-          'compressed_total_length': 0,
-          'raw_total_length': len(processed)
-      })
+    import zlib
+    compressed = zlib.compress(processed)
+    data = ToCArray(compressed)
+    output.write(HEADER_TEMPLATE % {
+        'sources_type': 'unsigned char',
+        'sources_data': data,
+        'sources_name': 'compressedSources',
+        'compressed_total_length': len(compressed),
+        'raw_total_length': len(processed)
+    })
 
 def preprocess(cxx, preprocessorOption, source, args = []):
   if (not os.path.exists(cxx[0])):
     cxx[0] = which.which(cxx[0])
   # Clang seems to complain and not output anything if the extension of the
   # input is not something it recognizes, so just fake a .cpp here.
   tmpIn = 'self-hosting-cpp-input.cpp';
   tmpOut = 'self-hosting-preprocessed.pp';
--- a/js/src/jsscript.cpp
+++ b/js/src/jsscript.cpp
@@ -1490,17 +1490,16 @@ UncompressedSourceCache::sizeOfExcluding
 const jschar *
 ScriptSource::chars(JSContext *cx, UncompressedSourceCache::AutoHoldEntry &holder)
 {
     switch (dataType) {
       case DataUncompressed:
         return uncompressedChars();
 
       case DataCompressed: {
-#ifdef USE_ZLIB
         if (const jschar *decompressed = cx->runtime()->uncompressedSourceCache.lookup(this, holder))
             return decompressed;
 
         const size_t nbytes = sizeof(jschar) * (length_ + 1);
         jschar *decompressed = static_cast<jschar *>(js_malloc(nbytes));
         if (!decompressed)
             return nullptr;
 
@@ -1515,19 +1514,16 @@ ScriptSource::chars(JSContext *cx, Uncom
 
         if (!cx->runtime()->uncompressedSourceCache.put(this, decompressed, holder)) {
             JS_ReportOutOfMemory(cx);
             js_free(decompressed);
             return nullptr;
         }
 
         return decompressed;
-#else
-        MOZ_CRASH();
-#endif
       }
 
       case DataParent:
         return parent()->chars(cx, holder);
 
       default:
         MOZ_CRASH();
     }
@@ -1649,17 +1645,17 @@ ScriptSource::setSourceCopy(ExclusiveCon
     // helper threads:
     //  - If we are on a helper thread, there must be another helper thread to
     //    execute our compression task.
     //  - If we are on the main thread, there must be at least two helper
     //    threads since at most one helper thread can be blocking on the main
     //    thread (see HelperThreadState::canStartParseTask) which would cause a
     //    deadlock if there wasn't a second helper thread that could make
     //    progress on our compression task.
-#if defined(JS_THREADSAFE) && defined(USE_ZLIB)
+#if defined(JS_THREADSAFE)
     bool canCompressOffThread =
         HelperThreadState().cpuCount > 1 &&
         HelperThreadState().threadCount >= 2;
 #else
     bool canCompressOffThread = false;
 #endif
     const size_t TINY_SCRIPT = 256;
     const size_t HUGE_SCRIPT = 5 * 1024 * 1024;
@@ -1672,17 +1668,16 @@ ScriptSource::setSourceCopy(ExclusiveCon
     }
 
     return true;
 }
 
 SourceCompressionTask::ResultType
 SourceCompressionTask::work()
 {
-#ifdef USE_ZLIB
     // Try to keep the maximum memory usage down by only allocating half the
     // size of the string, first.
     size_t inputBytes = ss->length() * sizeof(jschar);
     size_t firstSize = inputBytes / 2;
     compressed = js_malloc(firstSize);
     if (!compressed)
         return OOM;
 
@@ -1718,19 +1713,16 @@ SourceCompressionTask::work()
             cont = false;
             break;
           case Compressor::OOM:
             return OOM;
         }
     }
     compressedBytes = comp.outWritten();
     compressedHash = CompressedSourceHasher::computeHash(compressed, compressedBytes);
-#else
-    MOZ_CRASH();
-#endif
 
     // Shrink the buffer to the size of the compressed data.
     if (void *newCompressed = js_realloc(compressed, compressedBytes))
         compressed = newCompressed;
 
     return Success;
 }
 
--- a/js/src/make-source-package.sh
+++ b/js/src/make-source-package.sh
@@ -68,16 +68,19 @@ case $cmd in
 	cp -t ${tgtpath}/dom/bindings -dRp \
 		${SRCDIR}/../../dom/bindings/mozwebidlcodegen
 	${MKDIR} -p ${tgtpath}/media/webrtc/trunk/tools
 	cp -t ${tgtpath}/media/webrtc/trunk/tools -dRp \
 		${SRCDIR}/../../media/webrtc/trunk/tools/gyp
 	${MKDIR} -p ${tgtpath}/testing
 	cp -t ${tgtpath}/testing -dRp \
 		${SRCDIR}/../../testing/mozbase
+	${MKDIR} -p ${tgtpath}/modules/zlib
+	cp -t ${tgtpath}/modules/zlib -dRp \
+		${SRCDIR}/../../modules/zlib/src
 
 	# 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
--- a/js/src/vm/Compression.cpp
+++ b/js/src/vm/Compression.cpp
@@ -5,17 +5,16 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "vm/Compression.h"
 
 #include "js/Utility.h"
 
 using namespace js;
 
-#if USE_ZLIB
 static void *
 zlib_alloc(void *cx, uInt items, uInt size)
 {
     return js_calloc(items, size);
 }
 
 static void
 zlib_free(void *cx, void *addr)
@@ -122,10 +121,8 @@ js::DecompressString(const unsigned char
         return false;
     }
     ret = inflate(&zs, Z_FINISH);
     JS_ASSERT(ret == Z_STREAM_END);
     ret = inflateEnd(&zs);
     JS_ASSERT(ret == Z_OK);
     return true;
 }
-#endif /* USE_ZLIB */
-
--- a/js/src/vm/Compression.h
+++ b/js/src/vm/Compression.h
@@ -2,18 +2,16 @@
  * vim: set ts=8 sts=4 et sw=4 tw=99:
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef vm_Compression_h
 #define vm_Compression_h
 
-#ifdef USE_ZLIB
-
 #include <zlib.h>
 
 #include "jstypes.h"
 
 namespace js {
 
 class Compressor
 {
@@ -46,10 +44,9 @@ class Compressor
  * Decompress a string. The caller must know the length of the output and
  * allocate |out| to a string of that length.
  */
 bool DecompressString(const unsigned char *inp, size_t inplen,
                       unsigned char *out, size_t outlen);
 
 } /* namespace js */
 
-#endif /* USE_ZLIB */
 #endif /* vm_Compression_h */
--- a/js/src/vm/SelfHosting.cpp
+++ b/js/src/vm/SelfHosting.cpp
@@ -1010,28 +1010,24 @@ JSRuntime::initSelfHosting(JSContext *cx
     char *filename = getenv("MOZ_SELFHOSTEDJS");
     if (filename) {
         RootedScript script(cx);
         if (Compile(cx, shg, options, filename, &script))
             ok = Execute(cx, script, *shg.get(), rv.address());
     } else {
         uint32_t srcLen = GetRawScriptsSize();
 
-#ifdef USE_ZLIB
         const unsigned char *compressed = compressedSources;
         uint32_t compressedLen = GetCompressedSize();
         ScopedJSFreePtr<char> src(reinterpret_cast<char *>(cx->malloc_(srcLen)));
         if (!src || !DecompressString(compressed, compressedLen,
                                       reinterpret_cast<unsigned char *>(src.get()), srcLen))
         {
             return false;
         }
-#else
-        const char *src = rawSources;
-#endif
 
         ok = Evaluate(cx, shg, options, src, srcLen, &rv);
     }
     JS_SetErrorReporter(cx, oldReporter);
     if (receivesDefaultObject)
         js::SetDefaultObjectForContext(cx, savedGlobal);
     return ok;
 }
--- a/moz.build
+++ b/moz.build
@@ -19,27 +19,28 @@ if not CONFIG['JS_STANDALONE']:
         'tools/update-packaging/Makefile',
     ]
 
     add_tier_dir('base', ['build', 'probes'])
 
 if not CONFIG['LIBXUL_SDK']:
     add_tier_dir('base', ['mfbt'])
 
+    if not CONFIG['MOZ_NATIVE_ZLIB']:
+        add_tier_dir('base', ['modules/zlib'])
+
     if not CONFIG['JS_STANDALONE']:
         if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
             add_tier_dir('base', ['other-licenses/android'])
 
         if CONFIG['MOZ_MEMORY']:
             add_tier_dir('base', ['memory'])
 
-        if not CONFIG['MOZ_NATIVE_ZLIB']:
-            add_tier_dir('base', ['modules/zlib'])
+        add_tier_dir('base', ['mozglue', 'memory/mozalloc'])
 
-        add_tier_dir('base', ['mozglue', 'memory/mozalloc'])
 
 if not CONFIG['JS_STANDALONE']:
     add_tier_dir('precompile', 'xpcom/xpidl')
 
     if CONFIG['COMPILE_ENVIRONMENT'] and not CONFIG['LIBXUL_SDK']:
         if not CONFIG['MOZ_NATIVE_NSPR']:
             add_tier_dir('nspr', 'config/nspr')