OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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_HEAP_SPACES_INL_H_ | 5 #ifndef V8_HEAP_SPACES_INL_H_ |
6 #define V8_HEAP_SPACES_INL_H_ | 6 #define V8_HEAP_SPACES_INL_H_ |
7 | 7 |
8 #include "src/heap/incremental-marking.h" | 8 #include "src/heap/incremental-marking.h" |
9 #include "src/heap/spaces.h" | 9 #include "src/heap/spaces.h" |
10 #include "src/isolate.h" | 10 #include "src/isolate.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 LargePage* result = next_page_; | 162 LargePage* result = next_page_; |
163 if (next_page_ != nullptr) { | 163 if (next_page_ != nullptr) { |
164 next_page_ = next_page_->next_page(); | 164 next_page_ = next_page_->next_page(); |
165 } | 165 } |
166 return result; | 166 return result; |
167 } | 167 } |
168 | 168 |
169 // ----------------------------------------------------------------------------- | 169 // ----------------------------------------------------------------------------- |
170 // MemoryAllocator | 170 // MemoryAllocator |
171 | 171 |
| 172 template <typename PageType, MemoryAllocator::AllocationMode mode, |
| 173 typename SpaceType> |
| 174 inline PageType* MemoryAllocator::AllocatePage(intptr_t size, SpaceType* owner, |
| 175 Executability executable) { |
| 176 MemoryChunk* chunk = nullptr; |
| 177 if (mode == kPooled) { |
| 178 chunk = AllocatePagePooled(owner, executable); |
| 179 } |
| 180 if (chunk == nullptr) { |
| 181 chunk = AllocateChunk(size, size, executable, owner); |
| 182 } |
| 183 if (chunk == nullptr) return nullptr; |
| 184 return PageType::Initialize(isolate_->heap(), chunk, executable, owner); |
| 185 } |
| 186 |
172 #ifdef ENABLE_HEAP_PROTECTION | 187 #ifdef ENABLE_HEAP_PROTECTION |
173 | 188 |
174 void MemoryAllocator::Protect(Address start, size_t size) { | 189 void MemoryAllocator::Protect(Address start, size_t size) { |
175 base::OS::Protect(start, size); | 190 base::OS::Protect(start, size); |
176 } | 191 } |
177 | 192 |
178 | 193 |
179 void MemoryAllocator::Unprotect(Address start, size_t size, | 194 void MemoryAllocator::Unprotect(Address start, size_t size, |
180 Executability executable) { | 195 Executability executable) { |
181 base::OS::Unprotect(start, size, executable); | 196 base::OS::Unprotect(start, size, executable); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 bool NewSpace::FromSpaceContains(Object* o) { return from_space_.Contains(o); } | 259 bool NewSpace::FromSpaceContains(Object* o) { return from_space_.Contains(o); } |
245 | 260 |
246 // -------------------------------------------------------------------------- | 261 // -------------------------------------------------------------------------- |
247 // AllocationResult | 262 // AllocationResult |
248 | 263 |
249 AllocationSpace AllocationResult::RetrySpace() { | 264 AllocationSpace AllocationResult::RetrySpace() { |
250 DCHECK(IsRetry()); | 265 DCHECK(IsRetry()); |
251 return static_cast<AllocationSpace>(Smi::cast(object_)->value()); | 266 return static_cast<AllocationSpace>(Smi::cast(object_)->value()); |
252 } | 267 } |
253 | 268 |
| 269 NewSpacePage* NewSpacePage::Initialize(Heap* heap, MemoryChunk* chunk, |
| 270 Executability executable, |
| 271 SemiSpace* owner) { |
| 272 DCHECK_EQ(executable, Executability::NOT_EXECUTABLE); |
| 273 bool in_to_space = (owner->id() != kFromSpace); |
| 274 chunk->SetFlag(in_to_space ? MemoryChunk::IN_TO_SPACE |
| 275 : MemoryChunk::IN_FROM_SPACE); |
| 276 DCHECK(!chunk->IsFlagSet(in_to_space ? MemoryChunk::IN_FROM_SPACE |
| 277 : MemoryChunk::IN_TO_SPACE)); |
| 278 NewSpacePage* page = static_cast<NewSpacePage*>(chunk); |
| 279 heap->incremental_marking()->SetNewSpacePageFlags(page); |
| 280 return page; |
| 281 } |
254 | 282 |
255 // -------------------------------------------------------------------------- | 283 // -------------------------------------------------------------------------- |
256 // PagedSpace | 284 // PagedSpace |
257 | 285 |
258 Page* Page::Initialize(Heap* heap, MemoryChunk* chunk, Executability executable, | 286 Page* Page::Initialize(Heap* heap, MemoryChunk* chunk, Executability executable, |
259 PagedSpace* owner) { | 287 PagedSpace* owner) { |
260 Page* page = reinterpret_cast<Page*>(chunk); | 288 Page* page = reinterpret_cast<Page*>(chunk); |
261 page->mutex_ = new base::Mutex(); | 289 page->mutex_ = new base::Mutex(); |
262 DCHECK(page->area_size() <= kAllocatableMemory); | 290 DCHECK(page->area_size() <= kAllocatableMemory); |
263 DCHECK(chunk->owner() == owner); | 291 DCHECK(chunk->owner() == owner); |
| 292 |
264 owner->IncreaseCapacity(page->area_size()); | 293 owner->IncreaseCapacity(page->area_size()); |
265 heap->incremental_marking()->SetOldSpacePageFlags(chunk); | 294 heap->incremental_marking()->SetOldSpacePageFlags(chunk); |
266 | 295 |
267 // Make sure that categories are initialized before freeing the area. | 296 // Make sure that categories are initialized before freeing the area. |
268 page->InitializeFreeListCategories(); | 297 page->InitializeFreeListCategories(); |
269 owner->Free(page->area_start(), page->area_size()); | 298 owner->Free(page->area_start(), page->area_size()); |
270 | 299 |
271 return page; | 300 return page; |
272 } | 301 } |
273 | 302 |
(...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 other->allocation_info_.Reset(nullptr, nullptr); | 719 other->allocation_info_.Reset(nullptr, nullptr); |
691 return true; | 720 return true; |
692 } | 721 } |
693 return false; | 722 return false; |
694 } | 723 } |
695 | 724 |
696 } // namespace internal | 725 } // namespace internal |
697 } // namespace v8 | 726 } // namespace v8 |
698 | 727 |
699 #endif // V8_HEAP_SPACES_INL_H_ | 728 #endif // V8_HEAP_SPACES_INL_H_ |
OLD | NEW |