Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2008, 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 |
| 11 // copyright notice, this list of conditions and the following disclaimer | 11 // copyright notice, this list of conditions and the following disclaimer |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 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: Sanjay Ghemawat <opensource@google.com> | 31 // Author: Sanjay Ghemawat <opensource@google.com> |
| 32 // | 32 // |
| 33 // Common definitions for tcmalloc code. | 33 // Common definitions for tcmalloc code. |
| 34 | 34 |
|
jar (doing other things)
2011/08/20 02:40:30
nit: remove trailing whitespace.
bxx
2011/08/24 00:19:24
Done.
| |
| 35 #ifndef TCMALLOC_COMMON_H_ | 35 #ifndef TCMALLOC_COMMON_H_ |
| 36 #define TCMALLOC_COMMON_H_ | 36 #define TCMALLOC_COMMON_H_ |
| 37 | 37 |
| 38 #include "config.h" | 38 #include "config.h" |
| 39 | |
|
jar (doing other things)
2011/08/20 02:40:30
nit: remove extra newline.
bxx
2011/08/24 00:19:24
Done.
| |
| 39 #include <stddef.h> // for size_t | 40 #include <stddef.h> // for size_t |
| 40 #ifdef HAVE_STDINT_H | 41 #ifdef HAVE_STDINT_H |
| 41 #include <stdint.h> // for uintptr_t, uint64_t | 42 #include <stdint.h> // for uintptr_t, uint64_t |
| 42 #endif | 43 #endif |
| 44 | |
| 45 #include "free_list.h" // for SIZE_CLASS macros | |
| 43 #include "internal_logging.h" // for ASSERT, etc | 46 #include "internal_logging.h" // for ASSERT, etc |
| 44 | 47 |
| 45 // Type that can hold a page number | 48 // Type that can hold a page number |
| 46 typedef uintptr_t PageID; | 49 typedef uintptr_t PageID; |
| 47 | 50 |
| 48 // Type that can hold the length of a run of pages | 51 // Type that can hold the length of a run of pages |
| 49 typedef uintptr_t Length; | 52 typedef uintptr_t Length; |
| 50 | 53 |
| 51 //------------------------------------------------------------------- | 54 //------------------------------------------------------------------- |
| 52 // Configuration | 55 // Configuration |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 150 // So for these larger sizes we have an array indexed by ceil(size/128). | 153 // So for these larger sizes we have an array indexed by ceil(size/128). |
| 151 // | 154 // |
| 152 // We flatten both logical arrays into one physical array and use | 155 // We flatten both logical arrays into one physical array and use |
| 153 // arithmetic to compute an appropriate index. The constants used by | 156 // arithmetic to compute an appropriate index. The constants used by |
| 154 // ClassIndex() were selected to make the flattening work. | 157 // ClassIndex() were selected to make the flattening work. |
| 155 // | 158 // |
| 156 // Examples: | 159 // Examples: |
| 157 // Size Expression Index | 160 // Size Expression Index |
| 158 // ------------------------------------------------------- | 161 // ------------------------------------------------------- |
| 159 // 0 (0 + 7) / 8 0 | 162 // 0 (0 + 7) / 8 0 |
| 160 // 1 (1 + 7) / 8 1 | 163 // 1 (1 + 7) / 8 1 |
|
jar (doing other things)
2011/08/20 02:40:30
Note that they were distinguishing a class 0 for 0
bxx
2011/08/24 00:19:24
My edit to ClassIndex() in common.h should address
| |
| 161 // ... | 164 // ... |
| 162 // 1024 (1024 + 7) / 8 128 | 165 // 1024 (1024 + 7) / 8 128 |
| 163 // 1025 (1025 + 127 + (120<<7)) / 128 129 | 166 // 1025 (1025 + 127 + (120<<7)) / 128 129 |
| 164 // ... | 167 // ... |
| 165 // 32768 (32768 + 127 + (120<<7)) / 128 376 | 168 // 32768 (32768 + 127 + (120<<7)) / 128 376 |
| 166 static const int kMaxSmallSize = 1024; | 169 static const int kMaxSmallSize = 1024; |
| 167 static const size_t kClassArraySize = | 170 static const size_t kClassArraySize = |
| 168 (((1 << kPageShift) * 8u + 127 + (120 << 7)) >> 7) + 1; | 171 (((1 << kPageShift) * 8u + 127 + (120 << 7)) >> 7) + 1; |
| 169 unsigned char class_array_[kClassArraySize]; | 172 unsigned char class_array_[kClassArraySize]; |
| 170 | 173 |
| 171 // Compute index of the class_array[] entry for a given size | 174 // Compute index of the class_array[] entry for a given size |
| 172 static inline int ClassIndex(int s) { | 175 static inline int ClassIndex(int s) { |
| 173 ASSERT(0 <= s); | 176 ASSERT(0 <= s); |
| 174 ASSERT(s <= kMaxSize); | 177 ASSERT(s <= kMaxSize); |
| 175 const bool big = (s > kMaxSmallSize); | 178 const bool big = (s > kMaxSmallSize); |
| 176 const int add_amount = big ? (127 + (120<<7)) : 7; | 179 const int add_amount = big ? (127 + (120<<7)) : 7; |
| 177 const int shift_amount = big ? 7 : 3; | 180 const int shift_amount = big ? 7 : 3; |
| 178 return (s + add_amount) >> shift_amount; | 181 const int size_class = (s + add_amount) >> shift_amount; |
| 182 return (size_class < MIN_SIZE_CLASS) ? MIN_SIZE_CLASS : size_class; | |
|
jar (doing other things)
2011/08/20 02:40:30
I assume this was added to preclude 8 byte allocat
bxx
2011/08/24 00:19:24
Done.
| |
| 179 } | 183 } |
| 180 | 184 |
| 181 int NumMoveSize(size_t size); | 185 int NumMoveSize(size_t size); |
| 182 | 186 |
| 183 // Mapping from size class to max size storable in that class | 187 // Mapping from size class to max size storable in that class |
| 184 size_t class_to_size_[kNumClasses]; | 188 size_t class_to_size_[kNumClasses]; |
| 185 | 189 |
| 186 // Mapping from size class to number of pages to allocate at a time | 190 // Mapping from size class to number of pages to allocate at a time |
| 187 size_t class_to_pages_[kNumClasses]; | 191 size_t class_to_pages_[kNumClasses]; |
| 188 | 192 |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 static const int kMaxStackDepth = 31; | 248 static const int kMaxStackDepth = 31; |
| 245 struct StackTrace { | 249 struct StackTrace { |
| 246 uintptr_t size; // Size of object | 250 uintptr_t size; // Size of object |
| 247 uintptr_t depth; // Number of PC values stored in array below | 251 uintptr_t depth; // Number of PC values stored in array below |
| 248 void* stack[kMaxStackDepth]; | 252 void* stack[kMaxStackDepth]; |
| 249 }; | 253 }; |
| 250 | 254 |
| 251 } // namespace tcmalloc | 255 } // namespace tcmalloc |
| 252 | 256 |
| 253 #endif // TCMALLOC_COMMON_H_ | 257 #endif // TCMALLOC_COMMON_H_ |
| OLD | NEW |