5 #ifndef V8_BASE_REGION_ALLOCATOR_H_ 6 #define V8_BASE_REGION_ALLOCATOR_H_ 10 #include "src/base/address-region.h" 11 #include "src/base/utils/random-number-generator.h" 12 #include "testing/gtest/include/gtest/gtest_prod.h" 30 static constexpr
Address kAllocationFailure =
static_cast<Address>(-1);
37 Address AllocateRegion(
size_t size);
46 bool AllocateRegionAt(
Address requested_address,
size_t size);
51 size_t FreeRegion(
Address address) {
return TrimRegion(address, 0); }
57 size_t TrimRegion(
Address address,
size_t new_size);
61 size_t CheckRegion(
Address address);
64 bool IsFree(
Address address,
size_t size);
66 Address begin()
const {
return whole_region_.begin(); }
67 Address end()
const {
return whole_region_.end(); }
68 size_t size()
const {
return whole_region_.size(); }
70 bool contains(
Address address)
const {
71 return whole_region_.contains(address);
74 bool contains(
Address address,
size_t size)
const {
75 return whole_region_.contains(address, size);
79 size_t free_size()
const {
return free_size_; }
83 size_t page_size()
const {
return page_size_; }
85 void Print(std::ostream& os)
const;
90 Region(
Address address,
size_t size,
bool is_used)
93 bool is_used()
const {
return is_used_; }
94 void set_is_used(
bool used) { is_used_ = used; }
96 void Print(std::ostream& os)
const;
103 const Region whole_region_;
106 const size_t region_size_in_pages_;
110 const size_t max_load_for_randomization_;
116 const size_t page_size_;
118 struct AddressEndOrder {
119 bool operator()(
const Region* a,
const Region* b)
const {
120 return a->end() < b->end();
124 typedef std::set<Region*, AddressEndOrder> AllRegionsSet;
125 AllRegionsSet all_regions_;
127 struct SizeAddressOrder {
128 bool operator()(
const Region* a,
const Region* b)
const {
129 if (a->size() != b->size())
return a->size() < b->size();
130 return a->begin() < b->begin();
134 std::set<Region*, SizeAddressOrder> free_regions_;
137 AllRegionsSet::iterator FindRegion(
Address address);
140 void FreeListAddRegion(Region* region);
143 Region* FreeListFindRegion(
size_t size);
146 void FreeListRemoveRegion(Region* region);
150 Region* Split(Region* region,
size_t new_size);
153 void Merge(AllRegionsSet::iterator prev_iter,
154 AllRegionsSet::iterator next_iter);
156 FRIEND_TEST(RegionAllocatorTest, AllocateRegionRandom);
157 FRIEND_TEST(RegionAllocatorTest, Fragmentation);
158 FRIEND_TEST(RegionAllocatorTest, FindRegion);
159 FRIEND_TEST(RegionAllocatorTest, Contains);
167 #endif // V8_BASE_REGION_ALLOCATOR_H_