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 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
280 DCHECK(!chunk->IsFlagSet(in_to_space ? MemoryChunk::IN_FROM_SPACE | 280 DCHECK(!chunk->IsFlagSet(in_to_space ? MemoryChunk::IN_FROM_SPACE |
281 : MemoryChunk::IN_TO_SPACE)); | 281 : MemoryChunk::IN_TO_SPACE)); |
282 NewSpacePage* page = static_cast<NewSpacePage*>(chunk); | 282 NewSpacePage* page = static_cast<NewSpacePage*>(chunk); |
283 heap->incremental_marking()->SetNewSpacePageFlags(page); | 283 heap->incremental_marking()->SetNewSpacePageFlags(page); |
284 return page; | 284 return page; |
285 } | 285 } |
286 | 286 |
287 // -------------------------------------------------------------------------- | 287 // -------------------------------------------------------------------------- |
288 // PagedSpace | 288 // PagedSpace |
289 | 289 |
| 290 template <Page::InitializationMode mode> |
290 Page* Page::Initialize(Heap* heap, MemoryChunk* chunk, Executability executable, | 291 Page* Page::Initialize(Heap* heap, MemoryChunk* chunk, Executability executable, |
291 PagedSpace* owner) { | 292 PagedSpace* owner) { |
292 Page* page = reinterpret_cast<Page*>(chunk); | 293 Page* page = reinterpret_cast<Page*>(chunk); |
293 page->mutex_ = new base::Mutex(); | 294 page->mutex_ = new base::Mutex(); |
294 DCHECK(page->area_size() <= kAllocatableMemory); | 295 DCHECK(page->area_size() <= kAllocatableMemory); |
295 DCHECK(chunk->owner() == owner); | 296 DCHECK(chunk->owner() == owner); |
296 | 297 |
297 owner->IncreaseCapacity(page->area_size()); | 298 owner->IncreaseCapacity(page->area_size()); |
298 heap->incremental_marking()->SetOldSpacePageFlags(chunk); | 299 heap->incremental_marking()->SetOldSpacePageFlags(chunk); |
299 | 300 |
300 // Make sure that categories are initialized before freeing the area. | 301 // Make sure that categories are initialized before freeing the area. |
301 page->InitializeFreeListCategories(); | 302 page->InitializeFreeListCategories(); |
302 owner->Free(page->area_start(), page->area_size()); | 303 // In the case we do not free the memory, we effectively account for the whole |
| 304 // page as allocated memory that cannot be used for further allocations. |
| 305 if (mode == kFreeMemory) { |
| 306 owner->Free(page->area_start(), page->area_size()); |
| 307 } |
303 | 308 |
304 return page; | 309 return page; |
305 } | 310 } |
306 | 311 |
| 312 Page* Page::Convert(NewSpacePage* old_page, PagedSpace* new_owner) { |
| 313 old_page->set_owner(new_owner); |
| 314 old_page->SetFlags(0, ~0); |
| 315 new_owner->AccountCommitted(old_page->size()); |
| 316 Page* new_page = Page::Initialize<kDoNotFreeMemory>( |
| 317 old_page->heap(), old_page, NOT_EXECUTABLE, new_owner); |
| 318 new_page->InsertAfter(new_owner->anchor()->prev_page()); |
| 319 return new_page; |
| 320 } |
| 321 |
307 void Page::InitializeFreeListCategories() { | 322 void Page::InitializeFreeListCategories() { |
308 for (int i = kFirstCategory; i < kNumberOfCategories; i++) { | 323 for (int i = kFirstCategory; i < kNumberOfCategories; i++) { |
309 categories_[i].Initialize(static_cast<FreeListCategoryType>(i)); | 324 categories_[i].Initialize(static_cast<FreeListCategoryType>(i)); |
310 } | 325 } |
311 } | 326 } |
312 | 327 |
313 void MemoryChunk::IncrementLiveBytesFromGC(HeapObject* object, int by) { | 328 void MemoryChunk::IncrementLiveBytesFromGC(HeapObject* object, int by) { |
314 MemoryChunk::FromAddress(object->address())->IncrementLiveBytes(by); | 329 MemoryChunk::FromAddress(object->address())->IncrementLiveBytes(by); |
315 } | 330 } |
316 | 331 |
(...skipping 412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
729 other->allocation_info_.Reset(nullptr, nullptr); | 744 other->allocation_info_.Reset(nullptr, nullptr); |
730 return true; | 745 return true; |
731 } | 746 } |
732 return false; | 747 return false; |
733 } | 748 } |
734 | 749 |
735 } // namespace internal | 750 } // namespace internal |
736 } // namespace v8 | 751 } // namespace v8 |
737 | 752 |
738 #endif // V8_HEAP_SPACES_INL_H_ | 753 #endif // V8_HEAP_SPACES_INL_H_ |
OLD | NEW |