Bug 1062473: Use mozalloc's moz_malloc_size_of in the JS shell, not our own custom copy. r=glandium
authorJim Blandy <jimb@mozilla.com>
Mon, 13 Apr 2015 16:11:32 -0700
changeset 257650 8fcb10ac4ee5b8e2630c7eae30a8054249f05f04
parent 257649 55db417e2e0927be2b0ca957283a1f3f4005cde1
child 257651 2be405299a3ab111a11110a3176c386b36a95759
push id1565
push usermartin.thomson@gmail.com
push dateThu, 16 Apr 2015 22:18:42 +0000
reviewersglandium
bugs1062473
milestone40.0a1
Bug 1062473: Use mozalloc's moz_malloc_size_of in the JS shell, not our own custom copy. r=glandium
config/check_spidermonkey_style.py
js/src/make-source-package.sh
js/src/shell/js.cpp
memory/moz.build
moz.build
--- a/config/check_spidermonkey_style.py
+++ b/config/check_spidermonkey_style.py
@@ -238,41 +238,46 @@ def check_style():
     #
     # Examples (filename -> inclname)
     # - "mfbt/Attributes.h"     -> "mozilla/Attributes.h"
     # - "mfbt/decimal/Decimal.h -> "mozilla/Decimal.h"
     # - "js/public/Vector.h"    -> "js/Vector.h"
     # - "js/src/vm/String.h"    -> "vm/String.h"
 
     mfbt_inclnames = set()      # type: set(inclname)
+    mozalloc_inclnames = set()  # type: set(inclname)
     js_names = dict()           # type: dict(filename, inclname)
 
     # Select the appropriate files.
     for filename in get_all_filenames():
         if filename.startswith('mfbt/') and filename.endswith('.h'):
             inclname = 'mozilla/' + filename.split('/')[-1]
             mfbt_inclnames.add(inclname)
 
+        if filename.startswith('memory/mozalloc/') and filename.endswith('.h'):
+            inclname = 'mozilla/' + filename.split('/')[-1]
+            mozalloc_inclnames.add(inclname)
+
         if filename.startswith('js/public/') and filename.endswith('.h'):
             inclname = 'js/' + filename[len('js/public/'):]
             js_names[filename] = inclname
 
         if filename.startswith('js/src/') and \
            not filename.startswith(tuple(ignored_js_src_dirs)) and \
            filename.endswith(('.c', '.cpp', '.h', '.tbl', '.msg')):
             inclname = filename[len('js/src/'):]
             js_names[filename] = inclname
 
-    all_inclnames = mfbt_inclnames | set(js_names.values())
+    all_inclnames = mfbt_inclnames | mozalloc_inclnames | set(js_names.values())
 
     edges = dict()      # type: dict(inclname, set(inclname))
 
-    # We don't care what's inside the MFBT files, but because they are
-    # #included from JS files we have to add them to the inclusion graph.
-    for inclname in mfbt_inclnames:
+    # We don't care what's inside the MFBT and MOZALLOC files, but because they
+    # are #included from JS files we have to add them to the inclusion graph.
+    for inclname in mfbt_inclnames | mozalloc_inclnames:
         edges[inclname] = set()
 
     # Process all the JS files.
     for filename in js_names.keys():
         inclname = js_names[filename]
         file_kind = FileKind.get(filename)
         if file_kind == FileKind.C or file_kind == FileKind.CPP or \
            file_kind == FileKind.H or file_kind == FileKind.INL_H:
--- a/js/src/make-source-package.sh
+++ b/js/src/make-source-package.sh
@@ -94,17 +94,19 @@ case $cmd in
 	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/fallible \
                 ${TOPSRCDIR}/memory/jemalloc \
+                ${TOPSRCDIR}/memory/mozalloc \
                 ${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
--- a/js/src/shell/js.cpp
+++ b/js/src/shell/js.cpp
@@ -5,16 +5,17 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 /* JS shell. */
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Atomics.h"
 #include "mozilla/DebugOnly.h"
 #include "mozilla/GuardObjects.h"
+#include "mozilla/mozalloc.h"
 #include "mozilla/PodOperations.h"
 
 #ifdef XP_WIN
 # include <direct.h>
 # include <process.h>
 #endif
 #include <errno.h>
 #include <fcntl.h>
@@ -6083,36 +6084,16 @@ MaybeOverrideOutFileFromEnv(const char* 
 
 /* Pretend we can always preserve wrappers for dummy DOM objects. */
 static bool
 DummyPreserveWrapperCallback(JSContext* cx, JSObject* obj)
 {
     return true;
 }
 
-size_t
-ShellMallocSizeOf(const void* constPtr)
-{
-    // Match the type that all the library functions we might use here expect.
-    void* ptr = (void*) constPtr;
-
-    if (!ptr)
-        return 0;
-
-#if defined(HAVE_MALLOC_USABLE_SIZE)
-    return malloc_usable_size(ptr);
-#elif defined(HAVE_MALLOC_SIZE)
-    return malloc_size(ptr);
-#elif HAVE__MSIZE
-    return _msize(ptr);
-#else
-    return 0;
-#endif
-}
-
 int
 main(int argc, char** argv, char** envp)
 {
     sArgc = argc;
     sArgv = argv;
 
     JSRuntime* rt;
     JSContext* cx;
@@ -6357,17 +6338,17 @@ main(int argc, char** argv, char** envp)
     JS_SetSecurityCallbacks(rt, &ShellPrincipals::securityCallbacks);
     JS_InitDestroyPrincipalsCallback(rt, ShellPrincipals::destroy);
 
     JS_SetInterruptCallback(rt, ShellInterruptCallback);
     JS::SetAsmJSCacheOps(rt, &asmJSCacheOps);
 
     JS_SetNativeStackQuota(rt, gMaxStackSize);
 
-    JS::dbg::SetDebuggerMallocSizeOf(rt, ShellMallocSizeOf);
+    JS::dbg::SetDebuggerMallocSizeOf(rt, moz_malloc_size_of);
 
     if (!offThreadState.init())
         return 1;
 
     if (!InitWatchdog(rt))
         return 1;
 
     cx = NewContext(rt);
--- a/memory/moz.build
+++ b/memory/moz.build
@@ -1,16 +1,26 @@
 # -*- Mode: python; c-basic-offset: 4; indent-tabs-mode: nil; tab-width: 40 -*-
 # vim: set filetype=python:
 # 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/.
 
-DIRS += ['mozjemalloc']
+DIRS += [
+    'mozalloc',
+    'fallible',
+]
+
+if not CONFIG['JS_STANDALONE']:
+    DIRS += ['volatile']
 
-if CONFIG['MOZ_JEMALLOC3'] or CONFIG['MOZ_REPLACE_MALLOC']:
-    if not CONFIG['MOZ_NATIVE_JEMALLOC']:
-        DIRS += ['jemalloc']
+if CONFIG['MOZ_MEMORY']:
+    DIRS += [
+        'build',
+        'mozjemalloc',
+    ]
 
-DIRS += ['build']
+    if CONFIG['MOZ_JEMALLOC3'] or CONFIG['MOZ_REPLACE_MALLOC']:
+        if not CONFIG['MOZ_NATIVE_JEMALLOC']:
+            DIRS += ['jemalloc']
 
-if CONFIG['MOZ_REPLACE_MALLOC']:
-    DIRS += ['replace']
+    if CONFIG['MOZ_REPLACE_MALLOC']:
+        DIRS += ['replace']
--- a/moz.build
+++ b/moz.build
@@ -29,33 +29,24 @@ if not CONFIG['JS_STANDALONE']:
 
     DIRS += [
         'build',
         'probes',
     ]
 
 if not CONFIG['LIBXUL_SDK']:
     DIRS += [
-        'mozglue',
+        'config/external/zlib',
+        'memory',
         'mfbt',
-        'config/external/zlib',
+        'mozglue',
     ]
 
-    if CONFIG['MOZ_MEMORY']:
-        DIRS += ['memory']
-
-    if not CONFIG['JS_STANDALONE']:
-        if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
-            DIRS += ['other-licenses/android']
-
-        DIRS += [
-            'memory/fallible',
-            'memory/mozalloc',
-            'memory/volatile',
-        ]
+    if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'android':
+        DIRS += ['other-licenses/android']
 
 if not CONFIG['JS_STANDALONE']:
     DIRS += ['xpcom/xpidl']
 
 if CONFIG['COMPILE_ENVIRONMENT'] and not CONFIG['LIBXUL_SDK']:
     DIRS += ['config/external/nspr']
 
     if not CONFIG['JS_STANDALONE']: