87 {
89
90
91
92
93 int index = IndexForSize(
size);
94 if ((index != kNumLists) && free_map_.
Test(index)) {
95 FreeListElement* element = DequeueElement(index);
96 if (is_protected) {
99 }
100 return reinterpret_cast<uword>(element);
101 }
102
103 if ((index + 1) < kNumLists) {
104 intptr_t next_index = free_map_.
Next(index + 1);
105 if (next_index != -1) {
106
107
108 FreeListElement* element = DequeueElement(next_index);
109 if (is_protected) {
110
111
112
113
114
115 intptr_t remainder_size = element->HeapSize() -
size;
116 intptr_t region_size =
120 }
121 SplitElementAfterAndEnqueue(element,
size, is_protected);
122 return reinterpret_cast<uword>(element);
123 }
124 }
125
126 FreeListElement* previous = nullptr;
127 FreeListElement* current = free_lists_[kNumLists];
128
129
130
131
132
133
134
135
136
138 while (current != nullptr) {
139 if (current->HeapSize() >=
size) {
140
141
142 intptr_t remainder_size = current->HeapSize() -
size;
143 intptr_t region_size =
145 if (is_protected) {
146
147
148
151 }
152
153 if (previous == nullptr) {
154 free_lists_[kNumLists] = current->
next();
155 } else {
156
157
158
159 bool target_is_protected = false;
160 uword target_address = 0
L;
161 if (is_protected) {
162 uword writable_start =
reinterpret_cast<uword>(current);
163 uword writable_end = writable_start + region_size - 1;
164 target_address = previous->next_address();
165 target_is_protected =
168 }
169 if (target_is_protected) {
172 }
173 previous->set_next(current->next());
174 if (target_is_protected) {
177 }
178 }
179 SplitElementAfterAndEnqueue(current,
size, is_protected);
180 freelist_search_budget_ =
182 return reinterpret_cast<uword>(current);
183 } else if (tries_left-- < 0) {
184 freelist_search_budget_ = kInitialFreeListSearchBudget;
185 return 0;
186 }
187 previous = current;
188 current = current->next();
189 }
190 return 0;
191}
bool Test(intptr_t i) const
intptr_t Next(intptr_t i) const
FreeListElement * next() const
static intptr_t HeaderSizeFor(intptr_t size)
static void Protect(void *address, intptr_t size, Protection mode)
static bool InSamePage(uword address0, uword address1)
constexpr intptr_t kWordSize