Add an option to use tcmalloc's debugallocation for Debug builds

to catch memory problems early, easily, and cleanly.

This is disabled by default.

Because of gyp limitations, the flag is to force-disable the feature, but there is no flag to force-enable it.

BUG=30715
TEST=none

Review URL: https://codereview.chromium.org/11266019

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@171063 0039d316-1c4b-4281-b951-d872f2087c98
parent b570fd45
...@@ -203,6 +203,7 @@ ...@@ -203,6 +203,7 @@
'allocator_shim.cc', 'allocator_shim.cc',
'allocator_shim.h', 'allocator_shim.h',
'debugallocation_shim.cc',
'generic_allocators.cc', 'generic_allocators.cc',
'win_allocator.cc', 'win_allocator.cc',
], ],
...@@ -212,6 +213,10 @@ ...@@ -212,6 +213,10 @@
'generic_allocators.cc', 'generic_allocators.cc',
'win_allocator.cc', 'win_allocator.cc',
# Included by debugallocation_shim.cc.
'<(tcmalloc_dir)/src/debugallocation.cc',
'<(tcmalloc_dir)/src/tcmalloc.cc',
# We simply don't use these, but list them above so that IDE # We simply don't use these, but list them above so that IDE
# users can view the full available source for reference, etc. # users can view the full available source for reference, etc.
'<(tcmalloc_dir)/src/addressmap-inl.h', '<(tcmalloc_dir)/src/addressmap-inl.h',
...@@ -300,6 +305,21 @@ ...@@ -300,6 +305,21 @@
'RuntimeLibrary': '0', 'RuntimeLibrary': '0',
}, },
}, },
'variables': {
# Provide a way to force disable debugallocation in Debug builds,
# e.g. for profiling (it's more rare to profile Debug builds,
# but people sometimes need to do that).
'disable_debugallocation%': 1,
},
'conditions': [
['disable_debugallocation==0', {
'defines': [
# Use debugallocation for Debug builds to catch problems early
# and cleanly, http://crbug.com/30715 .
'TCMALLOC_FOR_DEBUGALLOCATION',
],
}],
],
}, },
}, },
'conditions': [ 'conditions': [
...@@ -346,7 +366,7 @@ ...@@ -346,7 +366,7 @@
'<(tcmalloc_dir)/src/system-alloc.h', '<(tcmalloc_dir)/src/system-alloc.h',
# included by allocator_shim.cc # included by allocator_shim.cc
'<(tcmalloc_dir)/src/tcmalloc.cc', 'debugallocation_shim.cc',
# heap-profiler/checker/cpuprofiler # heap-profiler/checker/cpuprofiler
'<(tcmalloc_dir)/src/base/thread_lister.c', '<(tcmalloc_dir)/src/base/thread_lister.c',
...@@ -365,9 +385,6 @@ ...@@ -365,9 +385,6 @@
'<(tcmalloc_dir)/src/profile-handler.cc', '<(tcmalloc_dir)/src/profile-handler.cc',
'<(tcmalloc_dir)/src/profile-handler.h', '<(tcmalloc_dir)/src/profile-handler.h',
'<(tcmalloc_dir)/src/profiler.cc', '<(tcmalloc_dir)/src/profiler.cc',
# debugallocation
'<(tcmalloc_dir)/src/debugallocation.cc',
], ],
}], }],
['OS=="linux" or OS=="freebsd" or OS=="solaris"', { ['OS=="linux" or OS=="freebsd" or OS=="solaris"', {
...@@ -414,20 +431,6 @@ ...@@ -414,20 +431,6 @@
'-fvtable-verify=preinit', '-fvtable-verify=preinit',
], ],
}], }],
[ 'linux_use_debugallocation==1', {
'sources!': [
# debugallocation.cc #includes tcmalloc.cc,
# so only one of them should be used.
'<(tcmalloc_dir)/src/tcmalloc.cc',
],
'defines': [
'TCMALLOC_FOR_DEBUGALLOCATION',
],
}, { # linux_use_debugallocation != 1
'sources!': [
'<(tcmalloc_dir)/src/debugallocation.cc',
],
}],
[ 'linux_keep_shadow_stacks==1', { [ 'linux_keep_shadow_stacks==1', {
'sources': [ 'sources': [
'<(tcmalloc_dir)/src/linux_shadow_stacks.cc', '<(tcmalloc_dir)/src/linux_shadow_stacks.cc',
......
...@@ -56,7 +56,7 @@ static const char secondary_name[] = "CHROME_ALLOCATOR_2"; ...@@ -56,7 +56,7 @@ static const char secondary_name[] = "CHROME_ALLOCATOR_2";
// We include tcmalloc and the win_allocator to get as much inlining as // We include tcmalloc and the win_allocator to get as much inlining as
// possible. // possible.
#include "tcmalloc.cc" #include "debugallocation_shim.cc"
#include "win_allocator.cc" #include "win_allocator.cc"
// Forward declarations from jemalloc. // Forward declarations from jemalloc.
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#if defined(TCMALLOC_FOR_DEBUGALLOCATION)
#include "third_party/tcmalloc/chromium/src/debugallocation.cc"
#else
#include "third_party/tcmalloc/chromium/src/tcmalloc.cc"
#endif
...@@ -830,9 +830,6 @@ ...@@ -830,9 +830,6 @@
# Enable TCMalloc. # Enable TCMalloc.
'linux_use_tcmalloc%': 1, 'linux_use_tcmalloc%': 1,
# Disable TCMalloc's debugallocation.
'linux_use_debugallocation%': 0,
# Disable TCMalloc's heapchecker. # Disable TCMalloc's heapchecker.
'linux_use_heapchecker%': 0, 'linux_use_heapchecker%': 0,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment