| OLD | NEW |
| 1 // Copyright (c) 2005, Google Inc. | 1 // Copyright (c) 2005, 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 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 DEFINE_bool(malloc_skip_mmap, | 126 DEFINE_bool(malloc_skip_mmap, |
| 127 EnvToBool("TCMALLOC_SKIP_MMAP", false), | 127 EnvToBool("TCMALLOC_SKIP_MMAP", false), |
| 128 "Whether mmap can be used to obtain memory."); | 128 "Whether mmap can be used to obtain memory."); |
| 129 | 129 |
| 130 // static allocators | 130 // static allocators |
| 131 class SbrkSysAllocator : public SysAllocator { | 131 class SbrkSysAllocator : public SysAllocator { |
| 132 public: | 132 public: |
| 133 SbrkSysAllocator() : SysAllocator() { | 133 SbrkSysAllocator() : SysAllocator() { |
| 134 } | 134 } |
| 135 void* Alloc(size_t size, size_t *actual_size, size_t alignment); | 135 void* Alloc(size_t size, size_t *actual_size, size_t alignment); |
| 136 void FlagsInitialized() {} | |
| 137 }; | 136 }; |
| 138 static char sbrk_space[sizeof(SbrkSysAllocator)]; | 137 static char sbrk_space[sizeof(SbrkSysAllocator)]; |
| 139 | 138 |
| 140 class MmapSysAllocator : public SysAllocator { | 139 class MmapSysAllocator : public SysAllocator { |
| 141 public: | 140 public: |
| 142 MmapSysAllocator() : SysAllocator() { | 141 MmapSysAllocator() : SysAllocator() { |
| 143 } | 142 } |
| 144 void* Alloc(size_t size, size_t *actual_size, size_t alignment); | 143 void* Alloc(size_t size, size_t *actual_size, size_t alignment); |
| 145 void FlagsInitialized() {} | |
| 146 }; | 144 }; |
| 147 static char mmap_space[sizeof(MmapSysAllocator)]; | 145 static char mmap_space[sizeof(MmapSysAllocator)]; |
| 148 | 146 |
| 149 class DevMemSysAllocator : public SysAllocator { | 147 class DevMemSysAllocator : public SysAllocator { |
| 150 public: | 148 public: |
| 151 DevMemSysAllocator() : SysAllocator() { | 149 DevMemSysAllocator() : SysAllocator() { |
| 152 } | 150 } |
| 153 void* Alloc(size_t size, size_t *actual_size, size_t alignment); | 151 void* Alloc(size_t size, size_t *actual_size, size_t alignment); |
| 154 void FlagsInitialized() {} | |
| 155 }; | 152 }; |
| 156 | 153 |
| 157 class DefaultSysAllocator : public SysAllocator { | 154 class DefaultSysAllocator : public SysAllocator { |
| 158 public: | 155 public: |
| 159 DefaultSysAllocator() : SysAllocator() { | 156 DefaultSysAllocator() : SysAllocator() { |
| 160 for (int i = 0; i < kMaxAllocators; i++) { | 157 for (int i = 0; i < kMaxAllocators; i++) { |
| 161 failed_[i] = true; | 158 failed_[i] = true; |
| 162 allocs_[i] = NULL; | 159 allocs_[i] = NULL; |
| 160 names_[i] = NULL; |
| 163 } | 161 } |
| 164 } | 162 } |
| 165 void SetChildAllocator(SysAllocator* alloc, unsigned int index, | 163 void SetChildAllocator(SysAllocator* alloc, unsigned int index, |
| 166 const char* name) { | 164 const char* name) { |
| 167 if (index < kMaxAllocators && alloc != NULL) { | 165 if (index < kMaxAllocators && alloc != NULL) { |
| 168 allocs_[index] = alloc; | 166 allocs_[index] = alloc; |
| 169 failed_[index] = false; | 167 failed_[index] = false; |
| 168 names_[index] = name; |
| 170 } | 169 } |
| 171 } | 170 } |
| 172 void* Alloc(size_t size, size_t *actual_size, size_t alignment); | 171 void* Alloc(size_t size, size_t *actual_size, size_t alignment); |
| 173 void FlagsInitialized() {} | |
| 174 | 172 |
| 175 private: | 173 private: |
| 176 static const int kMaxAllocators = 2; | 174 static const int kMaxAllocators = 2; |
| 177 bool failed_[kMaxAllocators]; | 175 bool failed_[kMaxAllocators]; |
| 178 SysAllocator* allocs_[kMaxAllocators]; | 176 SysAllocator* allocs_[kMaxAllocators]; |
| 179 const char* names_[kMaxAllocators]; | 177 const char* names_[kMaxAllocators]; |
| 180 }; | 178 }; |
| 181 static char default_space[sizeof(DefaultSysAllocator)]; | 179 static char default_space[sizeof(DefaultSysAllocator)]; |
| 182 static const char sbrk_name[] = "SbrkSysAllocator"; | 180 static const char sbrk_name[] = "SbrkSysAllocator"; |
| 183 static const char mmap_name[] = "MmapSysAllocator"; | 181 static const char mmap_name[] = "MmapSysAllocator"; |
| (...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 513 // Note -- ignoring most return codes, because if this fails it | 511 // Note -- ignoring most return codes, because if this fails it |
| 514 // doesn't matter... | 512 // doesn't matter... |
| 515 while (madvise(reinterpret_cast<char*>(new_start), new_end - new_start, | 513 while (madvise(reinterpret_cast<char*>(new_start), new_end - new_start, |
| 516 MADV_DONTNEED) == -1 && | 514 MADV_DONTNEED) == -1 && |
| 517 errno == EAGAIN) { | 515 errno == EAGAIN) { |
| 518 // NOP | 516 // NOP |
| 519 } | 517 } |
| 520 } | 518 } |
| 521 #endif | 519 #endif |
| 522 } | 520 } |
| OLD | NEW |