OLD | NEW |
1 // Copyright (c) 2008, Google Inc. | 1 // Copyright (c) 2008, 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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 // a thread is destroyed. | 252 // a thread is destroyed. |
253 // We also give a hint to the compiler to use the "initial exec" TLS | 253 // We also give a hint to the compiler to use the "initial exec" TLS |
254 // model. This is faster than the default TLS model, at the cost that | 254 // model. This is faster than the default TLS model, at the cost that |
255 // you cannot dlopen this library. (To see the difference, look at | 255 // you cannot dlopen this library. (To see the difference, look at |
256 // the CPU use of __tls_get_addr with and without this attribute.) | 256 // the CPU use of __tls_get_addr with and without this attribute.) |
257 // Since we don't really use dlopen in google code -- and using dlopen | 257 // Since we don't really use dlopen in google code -- and using dlopen |
258 // on a malloc replacement is asking for trouble in any case -- that's | 258 // on a malloc replacement is asking for trouble in any case -- that's |
259 // a good tradeoff for us. | 259 // a good tradeoff for us. |
260 #ifdef HAVE_TLS | 260 #ifdef HAVE_TLS |
261 static __thread ThreadCache* threadlocal_heap_ | 261 static __thread ThreadCache* threadlocal_heap_ |
262 # ifdef HAVE___ATTRIBUTE__ | 262 // This code links against pyautolib.so, which causes dlopen() on that shared |
| 263 // object to fail when -fprofile-generate is used with it. Ideally |
| 264 // pyautolib.so should not link against this code. There is a bug filed for |
| 265 // that: |
| 266 // http://code.google.com/p/chromium/issues/detail?id=124489 |
| 267 // For now the workaround is to pass in -DPGO_GENERATE when building Chrome |
| 268 // for instrumentation (-fprofile-generate). |
| 269 // For all non-instrumentation builds, this define will not be set and the |
| 270 // performance benefit of "intial-exec" will be achieved. |
| 271 #if defined(HAVE___ATTRIBUTE__) && !defined(PGO_GENERATE) |
263 __attribute__ ((tls_model ("initial-exec"))) | 272 __attribute__ ((tls_model ("initial-exec"))) |
264 # endif | 273 # endif |
265 ; | 274 ; |
266 #endif | 275 #endif |
267 | 276 |
268 // Thread-specific key. Initialization here is somewhat tricky | 277 // Thread-specific key. Initialization here is somewhat tricky |
269 // because some Linux startup code invokes malloc() before it | 278 // because some Linux startup code invokes malloc() before it |
270 // is in a good enough state to handle pthread_keycreate(). | 279 // is in a good enough state to handle pthread_keycreate(). |
271 // Therefore, we use TSD keys only after tsd_inited is set to true. | 280 // Therefore, we use TSD keys only after tsd_inited is set to true. |
272 // Until then, we use a slow path to get the heap object. | 281 // Until then, we use a slow path to get the heap object. |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 // because we may be in the thread destruction code and may have | 421 // because we may be in the thread destruction code and may have |
413 // already cleaned up the cache for this thread. | 422 // already cleaned up the cache for this thread. |
414 inline ThreadCache* ThreadCache::GetCacheIfPresent() { | 423 inline ThreadCache* ThreadCache::GetCacheIfPresent() { |
415 if (!tsd_inited_) return NULL; | 424 if (!tsd_inited_) return NULL; |
416 return GetThreadHeap(); | 425 return GetThreadHeap(); |
417 } | 426 } |
418 | 427 |
419 } // namespace tcmalloc | 428 } // namespace tcmalloc |
420 | 429 |
421 #endif // TCMALLOC_THREAD_CACHE_H_ | 430 #endif // TCMALLOC_THREAD_CACHE_H_ |
OLD | NEW |