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 16 matching lines...) Expand all Loading... |
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 | 29 |
30 // --- | 30 // --- |
31 // Author: Ken Ashcraft <opensource@google.com> | 31 // Author: Ken Ashcraft <opensource@google.com> |
32 | 32 |
33 #include "static_vars.h" | 33 #include "static_vars.h" |
34 #include <stddef.h> // for NULL | 34 #include <stddef.h> // for NULL |
35 #include <new> // for operator new | 35 #include <new> // for operator new |
36 #include "internal_logging.h" // for CHECK_CONDITION | 36 #include "internal_logging.h" // for CHECK_CONDITION |
| 37 #include "common.h" |
37 #include "sampler.h" // for Sampler | 38 #include "sampler.h" // for Sampler |
38 | 39 |
39 namespace tcmalloc { | 40 namespace tcmalloc { |
40 | 41 |
41 SpinLock Static::pageheap_lock_(SpinLock::LINKER_INITIALIZED); | 42 SpinLock Static::pageheap_lock_(SpinLock::LINKER_INITIALIZED); |
42 SizeMap Static::sizemap_; | 43 SizeMap Static::sizemap_; |
43 CentralFreeListPadded Static::central_cache_[kNumClasses]; | 44 CentralFreeListPadded Static::central_cache_[kNumClasses]; |
44 PageHeapAllocator<Span> Static::span_allocator_; | 45 PageHeapAllocator<Span> Static::span_allocator_; |
45 PageHeapAllocator<StackTrace> Static::stacktrace_allocator_; | 46 PageHeapAllocator<StackTrace> Static::stacktrace_allocator_; |
46 Span Static::sampled_objects_; | 47 Span Static::sampled_objects_; |
47 PageHeapAllocator<StackTraceTable::Bucket> Static::bucket_allocator_; | 48 PageHeapAllocator<StackTraceTable::Bucket> Static::bucket_allocator_; |
48 StackTrace* Static::growth_stacks_ = NULL; | 49 StackTrace* Static::growth_stacks_ = NULL; |
49 char Static::pageheap_memory_[sizeof(PageHeap)]; | 50 PageHeap* Static::pageheap_ = NULL; |
50 | 51 |
51 void Static::InitStaticVars() { | 52 void Static::InitStaticVars() { |
52 sizemap_.Init(); | 53 sizemap_.Init(); |
53 span_allocator_.Init(); | 54 span_allocator_.Init(); |
54 span_allocator_.New(); // Reduce cache conflicts | 55 span_allocator_.New(); // Reduce cache conflicts |
55 span_allocator_.New(); // Reduce cache conflicts | 56 span_allocator_.New(); // Reduce cache conflicts |
56 stacktrace_allocator_.Init(); | 57 stacktrace_allocator_.Init(); |
57 bucket_allocator_.Init(); | 58 bucket_allocator_.Init(); |
58 // Do a bit of sanitizing: make sure central_cache is aligned properly | 59 // Do a bit of sanitizing: make sure central_cache is aligned properly |
59 CHECK_CONDITION((sizeof(central_cache_[0]) % 64) == 0); | 60 CHECK_CONDITION((sizeof(central_cache_[0]) % 64) == 0); |
60 for (int i = 0; i < kNumClasses; ++i) { | 61 for (int i = 0; i < kNumClasses; ++i) { |
61 central_cache_[i].Init(i); | 62 central_cache_[i].Init(i); |
62 } | 63 } |
63 new ((void*)pageheap_memory_) PageHeap; | 64 // It's important to have PageHeap allocated, not in static storage, |
| 65 // so that HeapLeakChecker does not consider all the byte patterns stored |
| 66 // in is caches as pointers that are sources of heap object liveness, |
| 67 // which leads to it missing some memory leaks. |
| 68 pageheap_ = new (MetaDataAlloc(sizeof(PageHeap))) PageHeap; |
64 DLL_Init(&sampled_objects_); | 69 DLL_Init(&sampled_objects_); |
65 Sampler::InitStatics(); | 70 Sampler::InitStatics(); |
66 } | 71 } |
67 | 72 |
68 } // namespace tcmalloc | 73 } // namespace tcmalloc |
OLD | NEW |