5 #ifndef V8_ZONE_ACCOUNTING_ALLOCATOR_H_ 6 #define V8_ZONE_ACCOUNTING_ALLOCATOR_H_ 8 #include "include/v8-platform.h" 9 #include "include/v8.h" 10 #include "src/base/atomic-utils.h" 11 #include "src/base/atomicops.h" 12 #include "src/base/macros.h" 13 #include "src/base/platform/mutex.h" 14 #include "src/base/platform/semaphore.h" 15 #include "src/base/platform/time.h" 16 #include "src/zone/zone-segment.h" 17 #include "testing/gtest/include/gtest/gtest_prod.h" 24 static const size_t kMaxPoolSize = 8ul * KB;
30 virtual Segment* GetSegment(
size_t bytes);
33 virtual void ReturnSegment(
Segment* memory);
35 size_t GetCurrentMemoryUsage()
const;
36 size_t GetMaxMemoryUsage()
const;
38 size_t GetCurrentPoolSize()
const;
40 void MemoryPressureNotification(MemoryPressureLevel level);
45 void ConfigureSegmentPool(
const size_t max_pool_size);
47 virtual void ZoneCreation(
const Zone* zone) {}
48 virtual void ZoneDestruction(
const Zone* zone) {}
51 FRIEND_TEST(
Zone, SegmentPoolConstraints);
53 static const size_t kMinSegmentSizePower = 13;
54 static const size_t kMaxSegmentSizePower = 18;
56 STATIC_ASSERT(kMinSegmentSizePower <= kMaxSegmentSizePower);
58 static const size_t kNumberBuckets =
59 1 + kMaxSegmentSizePower - kMinSegmentSizePower;
62 Segment* AllocateSegment(
size_t bytes);
63 void FreeSegment(
Segment* memory);
66 Segment* GetSegmentFromPool(
size_t requested_size);
68 bool AddSegmentToPool(
Segment* segment);
73 Segment* unused_segments_heads_[kNumberBuckets];
75 size_t unused_segments_sizes_[kNumberBuckets];
76 size_t unused_segments_max_sizes_[kNumberBuckets];
80 base::AtomicWord current_memory_usage_ = 0;
81 base::AtomicWord max_memory_usage_ = 0;
82 base::AtomicWord current_pool_size_ = 0;
92 #endif // V8_ZONE_ACCOUNTING_ALLOCATOR_H_