Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 | 6 |
| 7 #if defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && \ | 7 #if defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && \ |
| 8 !defined(TARGET_ARCH_DBC) && !defined(HOST_OS_FUCHSIA) | 8 !defined(TARGET_ARCH_DBC) && !defined(HOST_OS_FUCHSIA) |
| 9 | 9 |
| 10 #include "vm/malloc_hooks.h" | 10 #include "vm/malloc_hooks.h" |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 147 intptr_t allocation_size() const { return allocation_size_; } | 147 intptr_t allocation_size() const { return allocation_size_; } |
| 148 | 148 |
| 149 private: | 149 private: |
| 150 // Note: sample_ is not owned by AllocationInfo, but by the SampleBuffer | 150 // Note: sample_ is not owned by AllocationInfo, but by the SampleBuffer |
| 151 // created by the profiler. As such, this is only here to track if the sample | 151 // created by the profiler. As such, this is only here to track if the sample |
| 152 // is still associated with a native allocation, and its fields are never | 152 // is still associated with a native allocation, and its fields are never |
| 153 // accessed from this class. | 153 // accessed from this class. |
| 154 Sample* sample_; | 154 Sample* sample_; |
| 155 uword address_; | 155 uword address_; |
| 156 intptr_t allocation_size_; | 156 intptr_t allocation_size_; |
| 157 | |
| 158 // The number of frames that are generated by the malloc hooks and collection | |
| 159 // of the stack trace. These frames are ignored when collecting the stack | |
| 160 // trace for a memory allocation. If this number is incorrect, some tests in | |
| 161 // malloc_hook_tests.cc might fail, particularily | |
| 162 // StackTraceMallocHookLengthTest. If this value is updated, please make sure | |
| 163 // that the MallocHooks test cases pass on all platforms. | |
| 164 static const intptr_t kSkipCount = 6; | |
| 165 }; | 157 }; |
| 166 | 158 |
| 167 | 159 |
| 168 // Custom key/value trait specifically for address/size pairs. Unlike | 160 // Custom key/value trait specifically for address/size pairs. Unlike |
| 169 // RawPointerKeyValueTrait, the default value is -1 as 0 can be a valid entry. | 161 // RawPointerKeyValueTrait, the default value is -1 as 0 can be a valid entry. |
| 170 class AddressKeyValueTrait : public AllStatic { | 162 class AddressKeyValueTrait : public AllStatic { |
| 171 public: | 163 public: |
| 172 typedef const void* Key; | 164 typedef const void* Key; |
| 173 typedef AllocationInfo* Value; | 165 typedef AllocationInfo* Value; |
| 174 | 166 |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 } | 428 } |
| 437 | 429 |
| 438 MallocLocker ml(MallocHooksState::malloc_hook_mutex(), | 430 MallocLocker ml(MallocHooksState::malloc_hook_mutex(), |
| 439 MallocHooksState::malloc_hook_mutex_owner()); | 431 MallocHooksState::malloc_hook_mutex_owner()); |
| 440 // Now that we hold the lock, check to make sure everything is still active. | 432 // Now that we hold the lock, check to make sure everything is still active. |
| 441 if ((ptr != NULL) && MallocHooksState::Active()) { | 433 if ((ptr != NULL) && MallocHooksState::Active()) { |
| 442 AllocationInfo* allocation_info = NULL; | 434 AllocationInfo* allocation_info = NULL; |
| 443 if (MallocHooksState::address_map()->Lookup(ptr, &allocation_info)) { | 435 if (MallocHooksState::address_map()->Lookup(ptr, &allocation_info)) { |
| 444 MallocHooksState::DecrementHeapAllocatedMemoryInBytes( | 436 MallocHooksState::DecrementHeapAllocatedMemoryInBytes( |
| 445 allocation_info->allocation_size()); | 437 allocation_info->allocation_size()); |
| 446 ASSERT(MallocHooksState::address_map()->Remove(ptr)); | 438 bool result = MallocHooksState::address_map()->Remove(ptr); |
|
Cutch
2017/03/27 17:52:29
const bool ...
| |
| 439 ASSERT(result); | |
| 447 delete allocation_info; | 440 delete allocation_info; |
| 448 } | 441 } |
| 449 } | 442 } |
| 450 } | 443 } |
| 451 | 444 |
| 452 } // namespace dart | 445 } // namespace dart |
| 453 | 446 |
| 454 #endif // defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && | 447 #endif // defined(DART_USE_TCMALLOC) && !defined(PRODUCT) && |
| 455 // !defined(TARGET_ARCH_DBC) && !defined(HOST_OS_FUCHSIA) | 448 // !defined(TARGET_ARCH_DBC) && !defined(HOST_OS_FUCHSIA) |
| OLD | NEW |