1 # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
2 # vim: set filetype=python:
3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 @depends(target, js_package)
9 def jemalloc_default(target, js_package):
12 return target.kernel in ("Darwin", "Linux", "WINNT")
18 default=jemalloc_default,
19 help="{Replace|Do not replace} memory allocator with jemalloc",
23 set_config("MOZ_MEMORY", True, when="--enable-jemalloc")
24 set_define("MOZ_MEMORY", True, when="--enable-jemalloc")
25 add_old_configure_assignment("MOZ_MEMORY", True, when="--enable-jemalloc")
28 @depends("--enable-jemalloc", moz_debug, win32_redist_dir)
29 def check_redist(jemalloc, debug, win32_redist_dir):
30 if not jemalloc and not win32_redist_dir and not debug:
32 "When not building jemalloc, you need to build with --with-redist or set WIN32_REDIST_DIR."
36 @depends(milestone, build_project)
37 def replace_malloc_default(milestone, build_project):
38 if build_project == "memory":
40 if milestone.is_early_beta_or_earlier and build_project != "js":
45 "--enable-replace-malloc",
46 default=replace_malloc_default,
47 when="--enable-jemalloc",
48 help="{Enable|Disable} ability to dynamically replace the malloc implementation",
52 set_config("MOZ_REPLACE_MALLOC", True, when="--enable-replace-malloc")
53 set_define("MOZ_REPLACE_MALLOC", True, when="--enable-replace-malloc")
56 @depends(build_project, when="--enable-replace-malloc")
57 def replace_malloc_static(build_project):
58 # Default to statically linking replace-malloc libraries that can be
59 # statically linked, except when building with --enable-project=memory.
60 if build_project != "memory":
64 set_config("MOZ_REPLACE_MALLOC_STATIC", replace_malloc_static)
66 # PHC (Probabilistic Heap Checker)
67 # ==============================================================
70 # In general, it only makes sense for PHC to run on the platforms that have a
76 when="--enable-jemalloc",
78 def phc_default(build_project, milestone, target):
79 if build_project == "js":
82 # PHC has a performance bottleneck on aarch64 (Bug 1874022) it's okay
83 # for nightly but not for release yet. To support unified builds on
84 # MacOS the x86_64 and aarch64 builds must match, so we disable PHC for
85 # x86_64 on MacOS late beta and release.
86 cpu_support = ("x86_64",)
87 if milestone.is_early_beta_or_earlier:
88 cpu_support = ("x86_64", "aarch64")
89 elif target.os == "OSX":
92 # Both Linux32 and Win32 have frequent crashes when stack tracing (for
93 # unclear reasons), so PHC is enabled only on 64-bit only in both cases.
94 return (target.cpu in cpu_support) and (
95 (target.os == "GNU" and target.kernel == "Linux")
96 or (target.kernel == "WINNT")
97 or (target.os == "OSX")
105 when="--enable-jemalloc",
106 help="{Enable|Disable} PHC (Probabilistic Memory Checker). "
107 "Also enables frame pointers when needed",
110 set_config("MOZ_PHC", True, when="--enable-phc")
113 # PHC parses stacks using frame pointers on these systems.
114 @depends("--enable-phc", target, have_unwind, when="--enable-jemalloc")
115 def phc_implies_frame_pointers(phc, target, have_unwind):
119 # This should be kept in sync with the ifdefs in memory/build/PHC.cpp
120 # that control stack walking.
121 # This is true for the first two options in PHC.cpp
122 if (target.os == "WINNT" and target.cpu == "x86") or target.kernel == "Darwin":
125 # This should match the #defines in mozglue/misc/StackWalk.cpp
126 if (target.cpu in ("x86", "ppc")) and (target.kernel in ("Darwin", "Linux")):
127 return not have_unwind
132 imply_option("--enable-frame-pointers", True, when=phc_implies_frame_pointers)
135 with only_when(depends(target.os)(lambda os: os != "WINNT")):
136 set_define("HAVE_STRNDUP", check_symbol("strndup"))
137 set_define("HAVE_POSIX_MEMALIGN", check_symbol("posix_memalign"))
138 set_define("HAVE_MEMALIGN", check_symbol("memalign"))
139 set_define("HAVE_MALLOC_USABLE_SIZE", check_symbol("malloc_usable_size"))