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(milestone, build_project)
29 def replace_malloc_default(milestone, build_project):
30 if build_project == "memory":
32 if milestone.is_early_beta_or_earlier and build_project != "js":
37 "--enable-replace-malloc",
38 default=replace_malloc_default,
39 when="--enable-jemalloc",
40 help="{Enable|Disable} ability to dynamically replace the malloc implementation",
44 set_config("MOZ_REPLACE_MALLOC", True, when="--enable-replace-malloc")
45 set_define("MOZ_REPLACE_MALLOC", True, when="--enable-replace-malloc")
48 @depends(build_project, when="--enable-replace-malloc")
49 def replace_malloc_static(build_project):
50 # Default to statically linking replace-malloc libraries that can be
51 # statically linked, except when building with --enable-project=memory.
52 if build_project != "memory":
56 set_config("MOZ_REPLACE_MALLOC_STATIC", replace_malloc_static)
58 # PHC (Probabilistic Heap Checker)
59 # ==============================================================
62 # In general, it only makes sense for PHC to run on the platforms that have a
67 when="--enable-jemalloc",
69 def phc_default(build_project, target):
70 if build_project == "js":
73 # Both Linux32 and Win32 have frequent crashes when stack tracing (for
74 # unclear reasons), so PHC is enabled only on 64-bit only in both cases.
75 return (target.cpu in ("x86_64", "aarch64")) and (
76 (target.os == "GNU" and target.kernel == "Linux")
77 or (target.kernel == "WINNT")
78 or (target.os == "OSX")
86 when="--enable-jemalloc",
87 help="{Enable|Disable} PHC (Probabilistic Memory Checker). "
88 "Also enables frame pointers when needed",
91 set_config("MOZ_PHC", True, when="--enable-phc")
94 # PHC parses stacks using frame pointers on these systems.
95 @depends("--enable-phc", target, have_unwind, when="--enable-jemalloc")
96 def phc_implies_frame_pointers(phc, target, have_unwind):
100 # This should be kept in sync with the ifdefs in memory/build/PHC.cpp
101 # that control stack walking.
102 # This is true for the first two options in PHC.cpp
103 if (target.os == "WINNT" and target.cpu == "x86") or target.kernel == "Darwin":
106 # This should match the #defines in mozglue/misc/StackWalk.cpp
107 if (target.cpu in ("x86", "ppc")) and (target.kernel in ("Darwin", "Linux")):
108 return not have_unwind
113 imply_option("--enable-frame-pointers", True, when=phc_implies_frame_pointers)
116 with only_when(depends(target.os)(lambda os: os != "WINNT")):
117 set_define("HAVE_STRNDUP", check_symbol("strndup"))
118 set_define("HAVE_POSIX_MEMALIGN", check_symbol("posix_memalign"))
119 set_define("HAVE_MEMALIGN", check_symbol("memalign"))
120 set_define("HAVE_MALLOC_USABLE_SIZE", check_symbol("malloc_usable_size"))