Index: src/zone/accounting-allocator.h |
diff --git a/src/zone/accounting-allocator.h b/src/zone/accounting-allocator.h |
index 31016a5018326d8c89e7cf1fd779ce111da5b2bb..6a32e18af7b8daaab93789e1e1b8dd8bf314525c 100644 |
--- a/src/zone/accounting-allocator.h |
+++ b/src/zone/accounting-allocator.h |
@@ -19,19 +19,55 @@ namespace internal { |
class V8_EXPORT_PRIVATE AccountingAllocator { |
public: |
- AccountingAllocator() = default; |
- virtual ~AccountingAllocator() = default; |
+ AccountingAllocator(); |
+ virtual ~AccountingAllocator(); |
- virtual Segment* AllocateSegment(size_t bytes); |
- virtual void FreeSegment(Segment* memory); |
+ // Gets an empty segment from the pool or creates a new one. |
+ virtual Segment* GetSegment(size_t bytes); |
+ // Return unneeded segments to either insert them into the pool or release |
+ // them if the pool is already full or memory pressure is high. |
+ virtual void ReturnSegment(Segment* memory); |
size_t GetCurrentMemoryUsage() const; |
size_t GetMaxMemoryUsage() const; |
+ size_t GetCurrentPoolSize() const; |
+ |
+ void MemoryPressureNotification(MemoryPressureLevel level); |
+ |
private: |
+ static const uint8_t kMinSegmentSizePower = 13; |
+ static const uint8_t kMaxSegmentSizePower = 18; |
+ static const uint8_t kMaxSegmentsPerBucket = 5; |
+ |
+ STATIC_ASSERT(kMinSegmentSizePower <= kMaxSegmentSizePower); |
+ |
+ // Allocates a new segment. Returns nullptr on failed allocation. |
+ Segment* AllocateSegment(size_t bytes); |
+ void FreeSegment(Segment* memory); |
+ |
+ // Returns a segment from the pool of at least the requested size. |
+ Segment* GetSegmentFromPool(size_t requested_size); |
+ // Trys to add a segment to the pool. Returns false if the pool is full. |
+ bool AddSegmentToPool(Segment* segment); |
+ |
+ // Empties the pool and puts all its contents onto the garbage stack. |
+ void ClearPool(); |
+ |
+ Segment* |
+ unused_segments_heads_[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; |
+ |
+ size_t unused_segments_sizes[1 + kMaxSegmentSizePower - kMinSegmentSizePower]; |
+ |
+ size_t unused_segments_size_ = 0; |
+ |
+ base::Mutex unused_segments_mutex_; |
+ |
base::AtomicWord current_memory_usage_ = 0; |
base::AtomicWord max_memory_usage_ = 0; |
+ base::AtomicValue<MemoryPressureLevel> memory_pressure_level_; |
+ |
DISALLOW_COPY_AND_ASSIGN(AccountingAllocator); |
}; |