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

Side by Side Diff: third_party/tcmalloc/vendor/src/libc_override_osx.h

Issue 9316021: Update the tcmalloc vendor branch to r144 (gperftools 2.0). (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Reuploading Created 8 years, 9 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) 2011, Google Inc. 1 // Copyright (c) 2011, 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 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 // punt and don't implement our own posix_memalign. Apps that really 68 // punt and don't implement our own posix_memalign. Apps that really
69 // care can use tc_posix_memalign directly. 69 // care can use tc_posix_memalign directly.
70 70
71 #ifndef TCMALLOC_LIBC_OVERRIDE_OSX_INL_H_ 71 #ifndef TCMALLOC_LIBC_OVERRIDE_OSX_INL_H_
72 #define TCMALLOC_LIBC_OVERRIDE_OSX_INL_H_ 72 #define TCMALLOC_LIBC_OVERRIDE_OSX_INL_H_
73 73
74 #include <config.h> 74 #include <config.h>
75 #ifdef HAVE_FEATURES_H 75 #ifdef HAVE_FEATURES_H
76 #include <features.h> 76 #include <features.h>
77 #endif 77 #endif
78 #include <google/tcmalloc.h> 78 #include <gperftools/tcmalloc.h>
79 79
80 #if !defined(__APPLE__) 80 #if !defined(__APPLE__)
81 # error libc_override_glibc-osx.h is for OS X distributions only. 81 # error libc_override_glibc-osx.h is for OS X distributions only.
82 #endif 82 #endif
83 83
84 #include <AvailabilityMacros.h> 84 #include <AvailabilityMacros.h>
85 #include <malloc/malloc.h> 85 #include <malloc/malloc.h>
86 86
87 // from AvailabilityMacros.h
88 #if defined(MAC_OS_X_VERSION_10_6) && \
89 MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
90 extern "C" {
91 // This function is only available on 10.6 (and later) but the
92 // LibSystem headers do not use AvailabilityMacros.h to handle weak
93 // importing automatically. This prototype is a copy of the one in
94 // <malloc/malloc.h> with the WEAK_IMPORT_ATTRBIUTE added.
95 extern malloc_zone_t *malloc_default_purgeable_zone(void)
96 WEAK_IMPORT_ATTRIBUTE;
97 }
98 #endif
99
87 // We need to provide wrappers around all the libc functions. 100 // We need to provide wrappers around all the libc functions.
88 namespace { 101 namespace {
89 size_t mz_size(malloc_zone_t* zone, const void* ptr) { 102 size_t mz_size(malloc_zone_t* zone, const void* ptr) {
90 if (MallocExtension::instance()->GetOwnership(ptr) != MallocExtension::kOwned) 103 if (MallocExtension::instance()->GetOwnership(ptr) != MallocExtension::kOwned)
91 return 0; // malloc_zone semantics: return 0 if we don't own the memory 104 return 0; // malloc_zone semantics: return 0 if we don't own the memory
92 105
93 // TODO(csilvers): change this method to take a const void*, one day. 106 // TODO(csilvers): change this method to take a const void*, one day.
94 return MallocExtension::instance()->GetAllocatedSize(const_cast<void*>(ptr)); 107 return MallocExtension::instance()->GetAllocatedSize(const_cast<void*>(ptr));
95 } 108 }
96 109
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
228 tcmalloc_zone.version = 6; 241 tcmalloc_zone.version = 6;
229 tcmalloc_zone.free_definite_size = NULL; 242 tcmalloc_zone.free_definite_size = NULL;
230 tcmalloc_zone.memalign = &mz_memalign; 243 tcmalloc_zone.memalign = &mz_memalign;
231 tcmalloc_introspection.zone_locked = &mi_zone_locked; 244 tcmalloc_introspection.zone_locked = &mi_zone_locked;
232 245
233 // Request the default purgable zone to force its creation. The 246 // Request the default purgable zone to force its creation. The
234 // current default zone is registered with the purgable zone for 247 // current default zone is registered with the purgable zone for
235 // doing tiny and small allocs. Sadly, it assumes that the default 248 // doing tiny and small allocs. Sadly, it assumes that the default
236 // zone is the szone implementation from OS X and will crash if it 249 // zone is the szone implementation from OS X and will crash if it
237 // isn't. By creating the zone now, this will be true and changing 250 // isn't. By creating the zone now, this will be true and changing
238 // the default zone won't cause a problem. (OS X 10.6 and higher.) 251 // the default zone won't cause a problem. This only needs to
239 malloc_default_purgeable_zone(); 252 // happen when actually running on OS X 10.6 and higher (note the
253 // ifdef above only checks if we were *compiled* with 10.6 or
254 // higher; at runtime we have to check if this symbol is defined.)
255 if (malloc_default_purgeable_zone) {
256 malloc_default_purgeable_zone();
257 }
240 #endif 258 #endif
241 259
242 // Register the tcmalloc zone. At this point, it will not be the 260 // Register the tcmalloc zone. At this point, it will not be the
243 // default zone. 261 // default zone.
244 malloc_zone_register(&tcmalloc_zone); 262 malloc_zone_register(&tcmalloc_zone);
245 263
246 // Unregister and reregister the default zone. Unregistering swaps 264 // Unregister and reregister the default zone. Unregistering swaps
247 // the specified zone with the last one registered which for the 265 // the specified zone with the last one registered which for the
248 // default zone makes the more recently registered zone the default 266 // default zone makes the more recently registered zone the default
249 // zone. The default zone is then re-registered to ensure that 267 // zone. The default zone is then re-registered to ensure that
250 // allocations made from it earlier will be handled correctly. 268 // allocations made from it earlier will be handled correctly.
251 // Things are not guaranteed to work that way, but it's how they work now. 269 // Things are not guaranteed to work that way, but it's how they work now.
252 malloc_zone_t *default_zone = malloc_default_zone(); 270 malloc_zone_t *default_zone = malloc_default_zone();
253 malloc_zone_unregister(default_zone); 271 malloc_zone_unregister(default_zone);
254 malloc_zone_register(default_zone); 272 malloc_zone_register(default_zone);
255 } 273 }
256 274
257 #endif // TCMALLOC_LIBC_OVERRIDE_OSX_INL_H_ 275 #endif // TCMALLOC_LIBC_OVERRIDE_OSX_INL_H_
OLDNEW
« no previous file with comments | « third_party/tcmalloc/vendor/src/libc_override_glibc.h ('k') | third_party/tcmalloc/vendor/src/malloc_extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698