1 // Copyright (c) 2008, Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
31 // Author: Ken Ashcraft <opensource@google.com>
33 #include "static_vars.h"
34 #include <stddef.h> // for NULL
35 #include <new> // for operator new
36 #include "internal_logging.h" // for CHECK_CONDITION
38 #include "sampler.h" // for Sampler
42 SpinLock
Static::pageheap_lock_(SpinLock::LINKER_INITIALIZED
);
43 SizeMap
Static::sizemap_
;
44 CentralFreeListPadded
Static::central_cache_
[kNumClasses
];
45 PageHeapAllocator
<Span
> Static::span_allocator_
;
46 PageHeapAllocator
<StackTrace
> Static::stacktrace_allocator_
;
47 Span
Static::sampled_objects_
;
48 PageHeapAllocator
<StackTraceTable::Bucket
> Static::bucket_allocator_
;
49 StackTrace
* Static::growth_stacks_
= NULL
;
50 PageHeap
* Static::pageheap_
= NULL
;
52 void Static::InitStaticVars() {
54 span_allocator_
.Init();
55 span_allocator_
.New(); // Reduce cache conflicts
56 span_allocator_
.New(); // Reduce cache conflicts
57 stacktrace_allocator_
.Init();
58 bucket_allocator_
.Init();
59 // Do a bit of sanitizing: make sure central_cache is aligned properly
60 CHECK_CONDITION((sizeof(central_cache_
[0]) % 64) == 0);
61 for (int i
= 0; i
< kNumClasses
; ++i
) {
62 central_cache_
[i
].Init(i
);
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
;
69 DLL_Init(&sampled_objects_
);
70 Sampler::InitStatics();
73 } // namespace tcmalloc