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

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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 EnvToInt("TCMALLOC_MAX_FREE_QUEUE_SIZE", 10*1024*1024), 120 EnvToInt("TCMALLOC_MAX_FREE_QUEUE_SIZE", 10*1024*1024),
121 "If greater than 0, keep freed blocks in a queue instead of " 121 "If greater than 0, keep freed blocks in a queue instead of "
122 "releasing them to the allocator immediately. Release them when " 122 "releasing them to the allocator immediately. Release them when "
123 "the total size of all blocks in the queue would otherwise exceed " 123 "the total size of all blocks in the queue would otherwise exceed "
124 "this limit."); 124 "this limit.");
125 125
126 DEFINE_bool(symbolize_stacktrace, 126 DEFINE_bool(symbolize_stacktrace,
127 EnvToBool("TCMALLOC_SYMBOLIZE_STACKTRACE", true), 127 EnvToBool("TCMALLOC_SYMBOLIZE_STACKTRACE", true),
128 "Symbolize the stack trace when provided (on some error exits)"); 128 "Symbolize the stack trace when provided (on some error exits)");
129 129
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 // ========================================================================= // 130 // ========================================================================= //
138 131
139 // A safe version of printf() that does not do any allocation and 132 // A safe version of printf() that does not do any allocation and
140 // uses very little stack space. 133 // uses very little stack space.
141 static void TracePrintf(int fd, const char *fmt, ...) 134 static void TracePrintf(int fd, const char *fmt, ...)
135 #ifdef __GNUC__
142 __attribute__ ((__format__ (__printf__, 2, 3))); 136 __attribute__ ((__format__ (__printf__, 2, 3)));
137 #else
138 ;
139 #endif
143 140
144 // The do_* functions are defined in tcmalloc/tcmalloc.cc, 141 // The do_* functions are defined in tcmalloc/tcmalloc.cc,
145 // which is included before this file 142 // which is included before this file
146 // when TCMALLOC_FOR_DEBUGALLOCATION is defined 143 // when TCMALLOC_FOR_DEBUGALLOCATION is defined
147 // TODO(csilvers): get rid of these now that we are tied to tcmalloc. 144 // TODO(csilvers): get rid of these now that we are tied to tcmalloc.
148 #define BASE_MALLOC_NEW do_malloc 145 #define BASE_MALLOC_NEW do_malloc
149 #define BASE_MALLOC do_malloc 146 #define BASE_MALLOC do_malloc
150 #define BASE_FREE do_free 147 #define BASE_FREE do_free
151 #define BASE_MALLOC_STATS do_malloc_stats 148 #define BASE_MALLOC_STATS do_malloc_stats
152 #define BASE_MALLOPT do_mallopt 149 #define BASE_MALLOPT do_mallopt
(...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after
617 BASE_FREE(entries[i].block); 614 BASE_FREE(entries[i].block);
618 } 615 }
619 } 616 }
620 617
621 static void InitDeletedBuffer() { 618 static void InitDeletedBuffer() {
622 memset(kMagicDeletedBuffer, kMagicDeletedByte, sizeof(kMagicDeletedBuffer)); 619 memset(kMagicDeletedBuffer, kMagicDeletedByte, sizeof(kMagicDeletedBuffer));
623 deleted_buffer_initialized_no_pthreads_ = true; 620 deleted_buffer_initialized_no_pthreads_ = true;
624 } 621 }
625 622
626 static void CheckForDanglingWrites(const MallocBlockQueueEntry& queue_entry) { 623 static void CheckForDanglingWrites(const MallocBlockQueueEntry& queue_entry) {
627 // Initialize the buffer if necessary. 624 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_) { 625 if (!deleted_buffer_initialized_no_pthreads_) {
631 // This will be the case on systems that don't link in pthreads, 626 // 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 627 // including on FreeBSD where pthread_once has a non-zero address
633 // (but doesn't do anything) even when pthreads isn't linked in. 628 // (but doesn't do anything) even when pthreads isn't linked in.
634 InitDeletedBuffer(); 629 InitDeletedBuffer();
635 } 630 }
636 631
637 const unsigned char* p = 632 const unsigned char* p =
638 reinterpret_cast<unsigned char*>(queue_entry.block); 633 reinterpret_cast<unsigned char*>(queue_entry.block);
639 634
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after
1428 1423
1429 #ifdef HAVE_STRUCT_MALLINFO 1424 #ifdef HAVE_STRUCT_MALLINFO
1430 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW { 1425 extern "C" PERFTOOLS_DLL_DECL struct mallinfo tc_mallinfo(void) __THROW {
1431 return BASE_MALLINFO(); 1426 return BASE_MALLINFO();
1432 } 1427 }
1433 #endif 1428 #endif
1434 1429
1435 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW { 1430 extern "C" PERFTOOLS_DLL_DECL size_t tc_malloc_size(void* ptr) __THROW {
1436 return MallocExtension::instance()->GetAllocatedSize(ptr); 1431 return MallocExtension::instance()->GetAllocatedSize(ptr);
1437 } 1432 }
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