From b7ad8602fc561e0ef706a0ddf724b0f5628b3461 Mon Sep 17 00:00:00 2001 From: Jim Blandy Date: Mon, 13 Apr 2015 16:11:32 -0700 Subject: [PATCH] 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 | 13 +++++++++---- js/src/make-source-package.sh | 2 ++ js/src/shell/js.cpp | 23 ++--------------------- memory/moz.build | 24 +++++++++++++++++------- moz.build | 19 +++++-------------- 5 files changed, 35 insertions(+), 46 deletions(-) diff --git a/config/check_spidermonkey_style.py b/config/check_spidermonkey_style.py index 90b1c596c0a..36b0511ba1e 100644 --- a/config/check_spidermonkey_style.py +++ b/config/check_spidermonkey_style.py @@ -243,6 +243,7 @@ def check_style(): # - "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. @@ -251,6 +252,10 @@ def check_style(): 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 @@ -261,13 +266,13 @@ def check_style(): 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. diff --git a/js/src/make-source-package.sh b/js/src/make-source-package.sh index a3cc1d947fd..cb79da66695 100755 --- a/js/src/make-source-package.sh +++ b/js/src/make-source-package.sh @@ -99,7 +99,9 @@ case $cmd in 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 diff --git a/js/src/shell/js.cpp b/js/src/shell/js.cpp index b48d454ebff..d8b7b6511dd 100644 --- a/js/src/shell/js.cpp +++ b/js/src/shell/js.cpp @@ -10,6 +10,7 @@ #include "mozilla/Atomics.h" #include "mozilla/DebugOnly.h" #include "mozilla/GuardObjects.h" +#include "mozilla/mozalloc.h" #include "mozilla/PodOperations.h" #ifdef XP_WIN @@ -6088,26 +6089,6 @@ 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) { @@ -6362,7 +6343,7 @@ main(int argc, char** argv, char** envp) JS_SetNativeStackQuota(rt, gMaxStackSize); - JS::dbg::SetDebuggerMallocSizeOf(rt, ShellMallocSizeOf); + JS::dbg::SetDebuggerMallocSizeOf(rt, moz_malloc_size_of); if (!offThreadState.init()) return 1; diff --git a/memory/moz.build b/memory/moz.build index d3fa652156e..cb3f0efc2e9 100644 --- a/memory/moz.build +++ b/memory/moz.build @@ -4,13 +4,23 @@ # 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 CONFIG['MOZ_JEMALLOC3'] or CONFIG['MOZ_REPLACE_MALLOC']: - if not CONFIG['MOZ_NATIVE_JEMALLOC']: - DIRS += ['jemalloc'] +if not CONFIG['JS_STANDALONE']: + DIRS += ['volatile'] -DIRS += ['build'] +if CONFIG['MOZ_MEMORY']: + DIRS += [ + 'build', + 'mozjemalloc', + ] -if CONFIG['MOZ_REPLACE_MALLOC']: - DIRS += ['replace'] + if CONFIG['MOZ_JEMALLOC3'] or CONFIG['MOZ_REPLACE_MALLOC']: + if not CONFIG['MOZ_NATIVE_JEMALLOC']: + DIRS += ['jemalloc'] + + if CONFIG['MOZ_REPLACE_MALLOC']: + DIRS += ['replace'] diff --git a/moz.build b/moz.build index 7df9f4a5060..81c563fe417 100644 --- a/moz.build +++ b/moz.build @@ -34,23 +34,14 @@ if not CONFIG['JS_STANDALONE']: if not CONFIG['LIBXUL_SDK']: DIRS += [ - 'mozglue', - 'mfbt', 'config/external/zlib', + 'memory', + 'mfbt', + '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']