Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3)

Side by Side Diff: third_party/tcmalloc/chromium/src/debugallocation.cc

Issue 15100010: GTTF: Enable tcmalloc's debugallocation on Windows. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2000, Google Inc. 1 // Copyright (c) 2000, Google Inc.
2 // All rights reserved. 2 // All rights reserved.
3 // 3 //
4 // Redistribution and use in source and binary forms, with or without 4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are 5 // modification, are permitted provided that the following conditions are
6 // met: 6 // met:
7 // 7 //
8 // * Redistributions of source code must retain the above copyright 8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer. 9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above 10 // * Redistributions in binary form must reproduce the above
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 #ifdef HAVE_UNISTD_H 63 #ifdef HAVE_UNISTD_H
64 #include <unistd.h> 64 #include <unistd.h>
65 #endif 65 #endif
66 66
67 #include <gperftools/malloc_extension.h> 67 #include <gperftools/malloc_extension.h>
68 #include <gperftools/malloc_hook.h> 68 #include <gperftools/malloc_hook.h>
69 #include <gperftools/stacktrace.h> 69 #include <gperftools/stacktrace.h>
70 #include "addressmap-inl.h" 70 #include "addressmap-inl.h"
71 #include "base/abort.h" 71 #include "base/abort.h"
72 #include "base/commandlineflags.h" 72 #include "base/commandlineflags.h"
73 #include "base/compiler_specific.h"
jar (doing other things) 2013/05/15 00:56:14 per discussion: kill this line, and then use an if
Paweł Hajdan Jr. 2013/05/15 17:59:46 Done.
73 #include "base/googleinit.h" 74 #include "base/googleinit.h"
74 #include "base/logging.h" 75 #include "base/logging.h"
75 #include "base/spinlock.h" 76 #include "base/spinlock.h"
76 #include "malloc_hook-inl.h" 77 #include "malloc_hook-inl.h"
77 #include "symbolize.h" 78 #include "symbolize.h"
78 79
79 #define TCMALLOC_USING_DEBUGALLOCATION 80 #define TCMALLOC_USING_DEBUGALLOCATION
80 #include "tcmalloc.cc" 81 #include "tcmalloc.cc"
81 82
82 // __THROW is defined in glibc systems. It means, counter-intuitively, 83 // __THROW is defined in glibc systems. It means, counter-intuitively,
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 EnvToInt("TCMALLOC_MAX_FREE_QUEUE_SIZE", 10*1024*1024), 121 EnvToInt("TCMALLOC_MAX_FREE_QUEUE_SIZE", 10*1024*1024),
121 "If greater than 0, keep freed blocks in a queue instead of " 122 "If greater than 0, keep freed blocks in a queue instead of "
122 "releasing them to the allocator immediately. Release them when " 123 "releasing them to the allocator immediately. Release them when "
123 "the total size of all blocks in the queue would otherwise exceed " 124 "the total size of all blocks in the queue would otherwise exceed "
124 "this limit."); 125 "this limit.");
125 126
126 DEFINE_bool(symbolize_stacktrace, 127 DEFINE_bool(symbolize_stacktrace,
127 EnvToBool("TCMALLOC_SYMBOLIZE_STACKTRACE", true), 128 EnvToBool("TCMALLOC_SYMBOLIZE_STACKTRACE", true),
128 "Symbolize the stack trace when provided (on some error exits)"); 129 "Symbolize the stack trace when provided (on some error exits)");
129 130
130 // If we are LD_PRELOAD-ed against a non-pthreads app, then
131 // pthread_once won't be defined. We declare it here, for that
132 // case (with weak linkage) which will cause the non-definition to
133 // resolve to NULL. We can then check for NULL or not in Instance.
134 extern "C" int pthread_once(pthread_once_t *, void (*)(void))
135 ATTRIBUTE_WEAK;
136
137 // ========================================================================= // 131 // ========================================================================= //
138 132
139 // A safe version of printf() that does not do any allocation and 133 // A safe version of printf() that does not do any allocation and
140 // uses very little stack space. 134 // uses very little stack space.
141 static void TracePrintf(int fd, const char *fmt, ...) 135 static void TracePrintf(int fd, const char *fmt, ...) PRINTF_FORMAT(2, 3);
142 __attribute__ ((__format__ (__printf__, 2, 3)));
143 136
144 // The do_* functions are defined in tcmalloc/tcmalloc.cc, 137 // The do_* functions are defined in tcmalloc/tcmalloc.cc,
145 // which is included before this file 138 // which is included before this file
146 // when TCMALLOC_FOR_DEBUGALLOCATION is defined 139 // when TCMALLOC_FOR_DEBUGALLOCATION is defined
147 // TODO(csilvers): get rid of these now that we are tied to tcmalloc. 140 // TODO(csilvers): get rid of these now that we are tied to tcmalloc.
148 #define BASE_MALLOC_NEW do_malloc 141 #define BASE_MALLOC_NEW do_malloc
149 #define BASE_MALLOC do_malloc 142 #define BASE_MALLOC do_malloc
150 #define BASE_FREE do_free 143 #define BASE_FREE do_free
151 #define BASE_MALLOC_STATS do_malloc_stats 144 #define BASE_MALLOC_STATS do_malloc_stats
152 #define BASE_MALLOPT do_mallopt 145 #define BASE_MALLOPT do_mallopt
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 BASE_FREE(entries[i].block); 610 BASE_FREE(entries[i].block);
618 } 611 }
619 } 612 }
620 613
621 static void InitDeletedBuffer() { 614 static void InitDeletedBuffer() {
622 memset(kMagicDeletedBuffer, kMagicDeletedByte, sizeof(kMagicDeletedBuffer)); 615 memset(kMagicDeletedBuffer, kMagicDeletedByte, sizeof(kMagicDeletedBuffer));
623 deleted_buffer_initialized_no_pthreads_ = true; 616 deleted_buffer_initialized_no_pthreads_ = true;
624 } 617 }
625 618
626 static void CheckForDanglingWrites(const MallocBlockQueueEntry& queue_entry) { 619 static void CheckForDanglingWrites(const MallocBlockQueueEntry& queue_entry) {
627 // Initialize the buffer if necessary. 620 perftools_pthread_once(&deleted_buffer_initialized_, &InitDeletedBuffer);
628 if (pthread_once)
629 pthread_once(&deleted_buffer_initialized_, &InitDeletedBuffer);
630 if (!deleted_buffer_initialized_no_pthreads_) { 621 if (!deleted_buffer_initialized_no_pthreads_) {
631 // This will be the case on systems that don't link in pthreads, 622 // This will be the case on systems that don't link in pthreads,
632 // including on FreeBSD where pthread_once has a non-zero address 623 // including on FreeBSD where pthread_once has a non-zero address
633 // (but doesn't do anything) even when pthreads isn't linked in. 624 // (but doesn't do anything) even when pthreads isn't linked in.
634 InitDeletedBuffer(); 625 InitDeletedBuffer();
635 } 626 }
636 627
637 const unsigned char* p = 628 const unsigned char* p =
638 reinterpret_cast<unsigned char*>(queue_entry.block); 629 reinterpret_cast<unsigned char*>(queue_entry.block);
639 630
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 1419
1429 #ifdef HAVE_STRUCT_MALLINFO 1420 #ifdef HAVE_STRUCT_MALLINFO
1430 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW { 1421 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW {
1431 return BASE_MALLINFO(); 1422 return BASE_MALLINFO();
1432 } 1423 }
1433 #endif 1424 #endif
1434 1425
1435 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW { 1426 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW {
1436 return MallocExtension::instance()->GetAllocatedSize(ptr); 1427 return MallocExtension::instance()->GetAllocatedSize(ptr);
1437 } 1428 }
OLDNEW
« no previous file with comments | « third_party/tcmalloc/chromium/src/config_win.h ('k') | third_party/tcmalloc/chromium/src/windows/port.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698