OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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_MARK_COMPACT_H_ | 5 #ifndef V8_HEAP_MARK_COMPACT_H_ |
6 #define V8_HEAP_MARK_COMPACT_H_ | 6 #define V8_HEAP_MARK_COMPACT_H_ |
7 | 7 |
8 #include <deque> | 8 #include <deque> |
9 | 9 |
10 #include "src/base/bits.h" | 10 #include "src/base/bits.h" |
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 typedef std::deque<Page*> SweepingList; | 309 typedef std::deque<Page*> SweepingList; |
310 typedef List<Page*> SweptList; | 310 typedef List<Page*> SweptList; |
311 | 311 |
312 static int RawSweep(Page* p, FreeListRebuildingMode free_list_mode, | 312 static int RawSweep(Page* p, FreeListRebuildingMode free_list_mode, |
313 FreeSpaceTreatmentMode free_space_mode); | 313 FreeSpaceTreatmentMode free_space_mode); |
314 | 314 |
315 explicit Sweeper(Heap* heap) | 315 explicit Sweeper(Heap* heap) |
316 : heap_(heap), | 316 : heap_(heap), |
317 pending_sweeper_tasks_semaphore_(0), | 317 pending_sweeper_tasks_semaphore_(0), |
318 sweeping_in_progress_(false), | 318 sweeping_in_progress_(false), |
| 319 late_pages_(false), |
319 num_sweeping_tasks_(0) {} | 320 num_sweeping_tasks_(0) {} |
320 | 321 |
321 bool sweeping_in_progress() { return sweeping_in_progress_; } | 322 bool sweeping_in_progress() { return sweeping_in_progress_; } |
| 323 bool contains_late_pages() { return late_pages_; } |
322 | 324 |
323 void AddPage(AllocationSpace space, Page* page); | 325 void AddPage(AllocationSpace space, Page* page); |
| 326 void AddLatePage(AllocationSpace space, Page* page); |
324 | 327 |
325 int ParallelSweepSpace(AllocationSpace identity, int required_freed_bytes, | 328 int ParallelSweepSpace(AllocationSpace identity, int required_freed_bytes, |
326 int max_pages = 0); | 329 int max_pages = 0); |
327 int ParallelSweepPage(Page* page, AllocationSpace identity); | 330 int ParallelSweepPage(Page* page, AllocationSpace identity); |
328 | 331 |
329 // After calling this function sweeping is considered to be in progress | |
330 // and the main thread can sweep lazily, but the background sweeper tasks | |
331 // are not running yet. | |
332 void StartSweeping(); | 332 void StartSweeping(); |
333 void StartSweeperTasks(); | 333 void StartSweepingHelper(AllocationSpace space_to_start); |
334 void EnsureCompleted(); | 334 void EnsureCompleted(); |
335 void EnsureNewSpaceCompleted(); | 335 void EnsureNewSpaceCompleted(); |
336 bool AreSweeperTasksRunning(); | 336 bool IsSweepingCompleted(); |
337 bool IsSweepingCompleted(AllocationSpace space); | |
338 void SweepOrWaitUntilSweepingCompleted(Page* page); | 337 void SweepOrWaitUntilSweepingCompleted(Page* page); |
339 | 338 |
340 void AddSweptPageSafe(PagedSpace* space, Page* page); | 339 void AddSweptPageSafe(PagedSpace* space, Page* page); |
341 Page* GetSweptPageSafe(PagedSpace* space); | 340 Page* GetSweptPageSafe(PagedSpace* space); |
342 | 341 |
343 private: | 342 private: |
344 static const int kAllocationSpaces = LAST_PAGED_SPACE + 1; | 343 static const int kAllocationSpaces = LAST_PAGED_SPACE + 1; |
345 | 344 |
346 static ClearOldToNewSlotsMode GetClearOldToNewSlotsMode(Page* p); | 345 static ClearOldToNewSlotsMode GetClearOldToNewSlotsMode(Page* p); |
347 | 346 |
348 template <typename Callback> | 347 template <typename Callback> |
349 void ForAllSweepingSpaces(Callback callback) { | 348 void ForAllSweepingSpaces(Callback callback) { |
350 for (int i = 0; i < kAllocationSpaces; i++) { | 349 for (int i = 0; i < kAllocationSpaces; i++) { |
351 callback(static_cast<AllocationSpace>(i)); | 350 callback(static_cast<AllocationSpace>(i)); |
352 } | 351 } |
353 } | 352 } |
354 | 353 |
355 Page* GetSweepingPageSafe(AllocationSpace space); | 354 Page* GetSweepingPageSafe(AllocationSpace space); |
356 void AddSweepingPageSafe(AllocationSpace space, Page* page); | 355 void AddSweepingPageSafe(AllocationSpace space, Page* page); |
357 | 356 |
358 void PrepareToBeSweptPage(AllocationSpace space, Page* page); | 357 void PrepareToBeSweptPage(AllocationSpace space, Page* page); |
359 | 358 |
360 Heap* heap_; | 359 Heap* heap_; |
361 base::Semaphore pending_sweeper_tasks_semaphore_; | 360 base::Semaphore pending_sweeper_tasks_semaphore_; |
362 base::Mutex mutex_; | 361 base::Mutex mutex_; |
363 SweptList swept_list_[kAllocationSpaces]; | 362 SweptList swept_list_[kAllocationSpaces]; |
364 SweepingList sweeping_list_[kAllocationSpaces]; | 363 SweepingList sweeping_list_[kAllocationSpaces]; |
365 bool sweeping_in_progress_; | 364 bool sweeping_in_progress_; |
| 365 bool late_pages_; |
366 base::AtomicNumber<intptr_t> num_sweeping_tasks_; | 366 base::AtomicNumber<intptr_t> num_sweeping_tasks_; |
367 }; | 367 }; |
368 | 368 |
369 enum IterationMode { | 369 enum IterationMode { |
370 kKeepMarking, | 370 kKeepMarking, |
371 kClearMarkbits, | 371 kClearMarkbits, |
372 }; | 372 }; |
373 | 373 |
374 static void Initialize(); | 374 static void Initialize(); |
375 | 375 |
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
630 // We have to remove all encountered weak maps from the list of weak | 630 // We have to remove all encountered weak maps from the list of weak |
631 // collections when incremental marking is aborted. | 631 // collections when incremental marking is aborted. |
632 void AbortWeakCollections(); | 632 void AbortWeakCollections(); |
633 | 633 |
634 void ClearWeakCells(Object** non_live_map_list, | 634 void ClearWeakCells(Object** non_live_map_list, |
635 DependentCode** dependent_code_list); | 635 DependentCode** dependent_code_list); |
636 void AbortWeakCells(); | 636 void AbortWeakCells(); |
637 | 637 |
638 void AbortTransitionArrays(); | 638 void AbortTransitionArrays(); |
639 | 639 |
640 // Starts sweeping of spaces by contributing on the main thread and setting | 640 // ----------------------------------------------------------------------- |
641 // up other pages for sweeping. Does not start sweeper tasks. | 641 // Phase 2: Sweeping to clear mark bits and free non-live objects for |
642 void StartSweepSpaces(); | 642 // a non-compacting collection. |
643 void StartSweepSpace(PagedSpace* space); | 643 // |
| 644 // Before: Live objects are marked and non-live objects are unmarked. |
| 645 // |
| 646 // After: Live objects are unmarked, non-live regions have been added to |
| 647 // their space's free list. Active eden semispace is compacted by |
| 648 // evacuation. |
| 649 // |
| 650 |
| 651 // If we are not compacting the heap, we simply sweep the spaces except |
| 652 // for the large object space, clearing mark bits and adding unmarked |
| 653 // regions to each space's free list. |
| 654 void SweepSpaces(); |
644 | 655 |
645 void EvacuateNewSpacePrologue(); | 656 void EvacuateNewSpacePrologue(); |
646 | 657 |
647 void EvacuatePagesInParallel(); | 658 void EvacuatePagesInParallel(); |
648 | 659 |
649 // The number of parallel compaction tasks, including the main thread. | 660 // The number of parallel compaction tasks, including the main thread. |
650 int NumberOfParallelCompactionTasks(int pages, intptr_t live_bytes); | 661 int NumberOfParallelCompactionTasks(int pages, intptr_t live_bytes); |
651 | 662 |
652 void EvacuateNewSpaceAndCandidates(); | 663 void EvacuateNewSpaceAndCandidates(); |
653 | 664 |
654 void UpdatePointersAfterEvacuation(); | 665 void UpdatePointersAfterEvacuation(); |
655 | 666 |
656 // Iterates through all live objects on a page using marking information. | 667 // Iterates through all live objects on a page using marking information. |
657 // Returns whether all objects have successfully been visited. | 668 // Returns whether all objects have successfully been visited. |
658 template <class Visitor> | 669 template <class Visitor> |
659 bool VisitLiveObjects(MemoryChunk* page, Visitor* visitor, | 670 bool VisitLiveObjects(MemoryChunk* page, Visitor* visitor, |
660 IterationMode mode); | 671 IterationMode mode); |
661 | 672 |
662 void RecomputeLiveBytes(MemoryChunk* page); | 673 void RecomputeLiveBytes(MemoryChunk* page); |
663 | 674 |
664 void ReleaseEvacuationCandidates(); | 675 void ReleaseEvacuationCandidates(); |
665 | 676 |
| 677 // Starts sweeping of a space by contributing on the main thread and setting |
| 678 // up other pages for sweeping. |
| 679 void StartSweepSpace(PagedSpace* space); |
666 | 680 |
667 #ifdef DEBUG | 681 #ifdef DEBUG |
668 friend class MarkObjectVisitor; | 682 friend class MarkObjectVisitor; |
669 static void VisitObject(HeapObject* obj); | 683 static void VisitObject(HeapObject* obj); |
670 | 684 |
671 friend class UnmarkObjectVisitor; | 685 friend class UnmarkObjectVisitor; |
672 static void UnmarkObject(HeapObject* obj); | 686 static void UnmarkObject(HeapObject* obj); |
673 #endif | 687 #endif |
674 | 688 |
675 Heap* heap_; | 689 Heap* heap_; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
730 | 744 |
731 private: | 745 private: |
732 MarkCompactCollector* collector_; | 746 MarkCompactCollector* collector_; |
733 }; | 747 }; |
734 | 748 |
735 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); | 749 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); |
736 } // namespace internal | 750 } // namespace internal |
737 } // namespace v8 | 751 } // namespace v8 |
738 | 752 |
739 #endif // V8_HEAP_MARK_COMPACT_H_ | 753 #endif // V8_HEAP_MARK_COMPACT_H_ |
OLD | NEW |