memory.configure 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. # -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
  2. # This Source Code Form is subject to the terms of the Mozilla Public
  3. # License, v. 2.0. If a copy of the MPL was not distributed with this
  4. # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  5. @deprecated_option(env='MOZ_JEMALLOC4')
  6. def moz_jemalloc4(value):
  7. die('MOZ_JEMALLOC4 is no longer supported')
  8. option('--enable-jemalloc', env='MOZ_MEMORY',
  9. help='Replace system memory allocator with jemalloc')
  10. @depends('--enable-jemalloc', target, build_project, c_compiler)
  11. def jemalloc(value, target, build_project, c_compiler):
  12. if value.origin != 'default':
  13. return bool(value) or None
  14. if build_project == 'js':
  15. return True
  16. if target.kernel == 'Darwin' and target.cpu == 'x86_64':
  17. # Don't enable by default on 32-bits OSX. See bug 702250.
  18. return True
  19. if target.kernel == 'WINNT' and c_compiler.type in ('msvc', 'clang-cl'):
  20. return True
  21. if target.kernel == 'Linux':
  22. return True
  23. set_config('MOZ_MEMORY', jemalloc)
  24. set_define('MOZ_MEMORY', jemalloc)
  25. add_old_configure_assignment('MOZ_MEMORY', jemalloc)
  26. # Because --enable-jemalloc doesn't use a default because of the dependency
  27. # on the target, we can't use a js_option for it to propagate to js/src
  28. # through the old-configure.
  29. @depends(jemalloc)
  30. def jemalloc_for_old_configure(jemalloc):
  31. return '--%s-jemalloc' % ('enable' if jemalloc else 'disable')
  32. add_old_configure_arg(jemalloc_for_old_configure)
  33. @depends(jemalloc, target)
  34. def jemalloc_os_define(jemalloc, target):
  35. if jemalloc:
  36. if target.kernel == 'WINNT':
  37. return 'MOZ_MEMORY_WINDOWS'
  38. if target.kernel == 'Linux':
  39. return 'MOZ_MEMORY_LINUX'
  40. if target.kernel == 'Darwin':
  41. return 'MOZ_MEMORY_DARWIN'
  42. if target.kernel in ('kFreeBSD', 'FreeBSD', 'NetBSD'):
  43. return 'MOZ_MEMORY_BSD'
  44. if target.kernel == 'SunOS':
  45. return 'MOZ_MEMORY_SOLARIS'
  46. die('--enable-jemalloc is not supported on %s', target.kernel)
  47. set_define(jemalloc_os_define, '1')
  48. @depends(jemalloc, target)
  49. def jemalloc_os_define_android(jemalloc, target):
  50. if jemalloc and target.os == 'Android':
  51. return 'MOZ_MEMORY_ANDROID'
  52. set_define(jemalloc_os_define_android, '1')
  53. option('--enable-replace-malloc',
  54. help='Enable ability to dynamically replace the malloc implementation')
  55. @depends('--enable-replace-malloc', jemalloc, milestone, build_project)
  56. def replace_malloc(value, jemalloc, milestone, build_project):
  57. # Enable on central for the debugging opportunities it adds.
  58. if value and not jemalloc:
  59. die('--enable-replace-malloc requires --enable-jemalloc')
  60. if value.origin != 'default':
  61. return bool(value) or None
  62. if milestone.is_nightly and jemalloc and build_project != 'js':
  63. return True
  64. set_config('MOZ_REPLACE_MALLOC', replace_malloc)
  65. set_define('MOZ_REPLACE_MALLOC', replace_malloc)
  66. add_old_configure_assignment('MOZ_REPLACE_MALLOC', replace_malloc)