| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ | 5 #ifndef BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ |
| 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ | 6 #define BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| 11 #include <type_traits> |
| 11 #include <utility> | 12 #include <utility> |
| 12 | 13 |
| 13 #include "base/bits.h" | 14 #include "base/bits.h" |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/process/process_metrics.h" | 17 #include "base/process/process_metrics.h" |
| 17 #include "base/template_util.h" | |
| 18 #include "base/trace_event/heap_profiler_allocation_context.h" | 18 #include "base/trace_event/heap_profiler_allocation_context.h" |
| 19 #include "build/build_config.h" | 19 #include "build/build_config.h" |
| 20 | 20 |
| 21 namespace base { | 21 namespace base { |
| 22 namespace trace_event { | 22 namespace trace_event { |
| 23 | 23 |
| 24 class AllocationRegisterTest; | 24 class AllocationRegisterTest; |
| 25 | 25 |
| 26 namespace internal { | 26 namespace internal { |
| 27 | 27 |
| 28 // Allocates a region of virtual address space of |size| rounded up to the | 28 // Allocates a region of virtual address space of |size| rounded up to the |
| 29 // system page size. The memory is zeroed by the system. A guard page is | 29 // system page size. The memory is zeroed by the system. A guard page is |
| 30 // added after the end. | 30 // added after the end. |
| 31 void* AllocateGuardedVirtualMemory(size_t size); | 31 void* AllocateGuardedVirtualMemory(size_t size); |
| 32 | 32 |
| 33 // Frees a region of virtual address space allocated by a call to | 33 // Frees a region of virtual address space allocated by a call to |
| 34 // |AllocateVirtualMemory|. | 34 // |AllocateVirtualMemory|. |
| 35 void FreeGuardedVirtualMemory(void* address, size_t allocated_size); | 35 void FreeGuardedVirtualMemory(void* address, size_t allocated_size); |
| 36 | 36 |
| 37 // Hash map that mmaps memory only once in the constructor. Its API is | 37 // Hash map that mmaps memory only once in the constructor. Its API is |
| 38 // similar to std::unordered_map, only index (KVIndex) is used to address | 38 // similar to std::unordered_map, only index (KVIndex) is used to address |
| 39 template <size_t NumBuckets, class Key, class Value, class KeyHasher> | 39 template <size_t NumBuckets, class Key, class Value, class KeyHasher> |
| 40 class FixedHashMap { | 40 class FixedHashMap { |
| 41 // To keep things simple we don't call destructors. | 41 // To keep things simple we don't call destructors. |
| 42 static_assert(is_trivially_destructible<Key>::value && | 42 static_assert(std::is_trivially_destructible<Key>::value && |
| 43 is_trivially_destructible<Value>::value, | 43 std::is_trivially_destructible<Value>::value, |
| 44 "Key and Value shouldn't have destructors"); | 44 "Key and Value shouldn't have destructors"); |
| 45 |
| 45 public: | 46 public: |
| 46 using KVPair = std::pair<const Key, Value>; | 47 using KVPair = std::pair<const Key, Value>; |
| 47 | 48 |
| 48 // For implementation simplicity API uses integer index instead | 49 // For implementation simplicity API uses integer index instead |
| 49 // of iterators. Most operations (except Find) on KVIndex are O(1). | 50 // of iterators. Most operations (except Find) on KVIndex are O(1). |
| 50 using KVIndex = size_t; | 51 using KVIndex = size_t; |
| 51 enum : KVIndex { kInvalidKVIndex = static_cast<KVIndex>(-1) }; | 52 enum : KVIndex { kInvalidKVIndex = static_cast<KVIndex>(-1) }; |
| 52 | 53 |
| 53 // Capacity controls how many items this hash map can hold, and largely | 54 // Capacity controls how many items this hash map can hold, and largely |
| 54 // affects memory footprint. | 55 // affects memory footprint. |
| (...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 // Sentinel used when we run out of backtraces_ storage. | 370 // Sentinel used when we run out of backtraces_ storage. |
| 370 BacktraceMap::KVIndex out_of_storage_backtrace_index_; | 371 BacktraceMap::KVIndex out_of_storage_backtrace_index_; |
| 371 | 372 |
| 372 DISALLOW_COPY_AND_ASSIGN(AllocationRegister); | 373 DISALLOW_COPY_AND_ASSIGN(AllocationRegister); |
| 373 }; | 374 }; |
| 374 | 375 |
| 375 } // namespace trace_event | 376 } // namespace trace_event |
| 376 } // namespace base | 377 } // namespace base |
| 377 | 378 |
| 378 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ | 379 #endif // BASE_TRACE_EVENT_HEAP_PROFILER_ALLOCATION_REGISTER_H_ |
| OLD | NEW |