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/.
9 def jemalloc_default(target):
10 return target.kernel in ('Darwin', 'Linux', 'WINNT')
13 js_option('--enable-jemalloc', env='MOZ_MEMORY', default=jemalloc_default,
14 help='{Replace|Do not replace} memory allocator with jemalloc')
17 set_config('MOZ_MEMORY', True, when='--enable-jemalloc')
18 set_define('MOZ_MEMORY', True, when='--enable-jemalloc')
19 add_old_configure_assignment('MOZ_MEMORY', True, when='--enable-jemalloc')
22 @depends(milestone, build_project)
23 def replace_malloc_default(milestone, build_project):
24 if build_project == 'memory':
26 if milestone.is_nightly and build_project != 'js':
30 js_option('--enable-replace-malloc', default=replace_malloc_default,
31 when='--enable-jemalloc',
32 help='{Enable|Disable} ability to dynamically replace the malloc implementation')
35 set_config('MOZ_REPLACE_MALLOC', True, when='--enable-replace-malloc')
36 set_define('MOZ_REPLACE_MALLOC', True, when='--enable-replace-malloc')
39 @depends(build_project, when='--enable-replace-malloc')
40 def replace_malloc_static(build_project):
41 # Default to statically linking replace-malloc libraries that can be
42 # statically linked, except when building with --enable-project=memory.
43 if build_project != 'memory':
47 set_config('MOZ_REPLACE_MALLOC_STATIC', replace_malloc_static)
49 # PHC (Probabilistic Heap Checker)
50 # ==============================================================
52 # In general, it only makes sense for PHC to run on the platforms that have a
54 @depends(milestone, target, replace_malloc_default, '--enable-replace-malloc',
55 when='--enable-jemalloc')
56 def phc_default(milestone, target, replace_malloc_default, replace_malloc):
57 if not replace_malloc_default or \
58 (replace_malloc.origin != 'default' and not replace_malloc):
60 # Nightly only because PHC has a non-negligible performance cost.
61 if not milestone.is_nightly:
63 # Both Linux32 and Win32 have frequent crashes when stack tracing (for
64 # unclear reasons), so PHC is enabled only on 64-bit only in both cases.
66 # XXX: PHC is implemented but not yet enabled on Mac. Bug 1576515 is about
67 # enabling it on Mac, but it is blocked by bug 1035892.
68 return (target.os == 'GNU' and target.kernel == 'Linux' and
69 target.bitness == 64) or \
70 (target.kernel == 'WINNT' and target.bitness == 64)
73 option('--enable-phc', env='MOZ_PHC', default=phc_default,
74 when='--enable-jemalloc',
75 help='{Enable|Disable} PHC (Probabilistic Memory Checker). '
76 'Also enables replace-malloc and frame pointers')
77 imply_option('--enable-replace-malloc', True, when='--enable-phc')
78 imply_option('--enable-frame-pointers', True, when='--enable-phc')
81 set_config('MOZ_PHC', True, when='--enable-phc')