OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 the V8 project 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 V8_ZONE_ACCOUNTING_ALLOCATOR_H_ | 5 #ifndef V8_ZONE_ACCOUNTING_ALLOCATOR_H_ |
6 #define V8_ZONE_ACCOUNTING_ALLOCATOR_H_ | 6 #define V8_ZONE_ACCOUNTING_ALLOCATOR_H_ |
7 | 7 |
8 #include "include/v8-platform.h" | 8 #include "include/v8-platform.h" |
9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" |
10 #include "src/base/atomicops.h" | 10 #include "src/base/atomicops.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 // Return unneeded segments to either insert them into the pool or release | 27 // Return unneeded segments to either insert them into the pool or release |
28 // them if the pool is already full or memory pressure is high. | 28 // them if the pool is already full or memory pressure is high. |
29 virtual void ReturnSegment(Segment* memory); | 29 virtual void ReturnSegment(Segment* memory); |
30 | 30 |
31 size_t GetCurrentMemoryUsage() const; | 31 size_t GetCurrentMemoryUsage() const; |
32 size_t GetMaxMemoryUsage() const; | 32 size_t GetMaxMemoryUsage() const; |
33 | 33 |
34 size_t GetCurrentPoolSize() const; | 34 size_t GetCurrentPoolSize() const; |
35 | 35 |
36 void MemoryPressureNotification(MemoryPressureLevel level); | 36 void MemoryPressureNotification(MemoryPressureLevel level); |
| 37 void ConfigureSegmentPool(const size_t max_pool_size); |
37 | 38 |
38 virtual void ZoneCreation(const Zone* zone) {} | 39 virtual void ZoneCreation(const Zone* zone) {} |
39 virtual void ZoneDestruction(const Zone* zone) {} | 40 virtual void ZoneDestruction(const Zone* zone) {} |
40 | 41 |
41 private: | 42 private: |
42 static const uint8_t kMinSegmentSizePower = 13; | 43 static const uint8_t kMinSegmentSizePower = 13; |
43 static const uint8_t kMaxSegmentSizePower = 18; | 44 static const uint8_t kMaxSegmentSizePower = 18; |
44 static const uint8_t kMaxSegmentsPerBucket = 5; | |
45 | 45 |
46 STATIC_ASSERT(kMinSegmentSizePower <= kMaxSegmentSizePower); | 46 STATIC_ASSERT(kMinSegmentSizePower <= kMaxSegmentSizePower); |
47 | 47 |
| 48 static const uint8_t kNumberBuckets = |
| 49 1 + kMaxSegmentSizePower - kMinSegmentSizePower; |
| 50 |
48 // Allocates a new segment. Returns nullptr on failed allocation. | 51 // Allocates a new segment. Returns nullptr on failed allocation. |
49 Segment* AllocateSegment(size_t bytes); | 52 Segment* AllocateSegment(size_t bytes); |
50 void FreeSegment(Segment* memory); | 53 void FreeSegment(Segment* memory); |
51 | 54 |
52 // Returns a segment from the pool of at least the requested size. | 55 // Returns a segment from the pool of at least the requested size. |
53 Segment* GetSegmentFromPool(size_t requested_size); | 56 Segment* GetSegmentFromPool(size_t requested_size); |
54 // Trys to add a segment to the pool. Returns false if the pool is full. | 57 // Trys to add a segment to the pool. Returns false if the pool is full. |
55 bool AddSegmentToPool(Segment* segment); | 58 bool AddSegmentToPool(Segment* segment); |
56 | 59 |
57 // Empties the pool and puts all its contents onto the garbage stack. | 60 // Empties the pool and puts all its contents onto the garbage stack. |
58 void ClearPool(); | 61 void ClearPool(); |
59 | 62 |
60 Segment* | 63 Segment* unused_segments_heads_[kNumberBuckets]; |
61 unused_segments_heads_[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; | |
62 | 64 |
63 size_t unused_segments_sizes[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; | 65 uint8_t unused_segments_sizes[kNumberBuckets]; |
| 66 uint8_t unused_segments_max_sizes[kNumberBuckets]; |
64 | 67 |
65 base::Mutex unused_segments_mutex_; | 68 base::Mutex unused_segments_mutex_; |
66 | 69 |
67 base::AtomicWord current_memory_usage_ = 0; | 70 base::AtomicWord current_memory_usage_ = 0; |
68 base::AtomicWord max_memory_usage_ = 0; | 71 base::AtomicWord max_memory_usage_ = 0; |
69 base::AtomicWord current_pool_size_ = 0; | 72 base::AtomicWord current_pool_size_ = 0; |
70 | 73 |
71 base::AtomicValue<MemoryPressureLevel> memory_pressure_level_; | 74 base::AtomicValue<MemoryPressureLevel> memory_pressure_level_; |
72 | 75 |
73 DISALLOW_COPY_AND_ASSIGN(AccountingAllocator); | 76 DISALLOW_COPY_AND_ASSIGN(AccountingAllocator); |
74 }; | 77 }; |
75 | 78 |
76 } // namespace internal | 79 } // namespace internal |
77 } // namespace v8 | 80 } // namespace v8 |
78 | 81 |
79 #endif // V8_ZONE_ACCOUNTING_ALLOCATOR_H_ | 82 #endif // V8_ZONE_ACCOUNTING_ALLOCATOR_H_ |
OLD | NEW |