Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(168)

Side by Side Diff: src/heap/mark-compact.h

Issue 2445283003: Reland "[heap] Start sweeper tasks after evacuation" (second try). (Closed)
Patch Set: bugfix Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/heap/incremental-marking.cc ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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),
320 num_sweeping_tasks_(0) {} 319 num_sweeping_tasks_(0) {}
321 320
322 bool sweeping_in_progress() { return sweeping_in_progress_; } 321 bool sweeping_in_progress() { return sweeping_in_progress_; }
323 bool contains_late_pages() { return late_pages_; }
324 322
325 void AddPage(AllocationSpace space, Page* page); 323 void AddPage(AllocationSpace space, Page* page);
326 void AddLatePage(AllocationSpace space, Page* page);
327 324
328 int ParallelSweepSpace(AllocationSpace identity, int required_freed_bytes, 325 int ParallelSweepSpace(AllocationSpace identity, int required_freed_bytes,
329 int max_pages = 0); 326 int max_pages = 0);
330 int ParallelSweepPage(Page* page, AllocationSpace identity); 327 int ParallelSweepPage(Page* page, AllocationSpace identity);
331 328
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 StartSweepingHelper(AllocationSpace space_to_start); 333 void StartSweeperTasks();
334 void EnsureCompleted(); 334 void EnsureCompleted();
335 void EnsureNewSpaceCompleted(); 335 void EnsureNewSpaceCompleted();
336 bool IsSweepingCompleted(); 336 bool AreSweeperTasksRunning();
337 bool IsSweepingCompleted(AllocationSpace space);
337 void SweepOrWaitUntilSweepingCompleted(Page* page); 338 void SweepOrWaitUntilSweepingCompleted(Page* page);
338 339
339 void AddSweptPageSafe(PagedSpace* space, Page* page); 340 void AddSweptPageSafe(PagedSpace* space, Page* page);
340 Page* GetSweptPageSafe(PagedSpace* space); 341 Page* GetSweptPageSafe(PagedSpace* space);
341 342
342 private: 343 private:
343 static const int kAllocationSpaces = LAST_PAGED_SPACE + 1; 344 static const int kAllocationSpaces = LAST_PAGED_SPACE + 1;
344 345
345 static ClearOldToNewSlotsMode GetClearOldToNewSlotsMode(Page* p); 346 static ClearOldToNewSlotsMode GetClearOldToNewSlotsMode(Page* p);
346 347
347 template <typename Callback> 348 template <typename Callback>
348 void ForAllSweepingSpaces(Callback callback) { 349 void ForAllSweepingSpaces(Callback callback) {
349 for (int i = 0; i < kAllocationSpaces; i++) { 350 for (int i = 0; i < kAllocationSpaces; i++) {
350 callback(static_cast<AllocationSpace>(i)); 351 callback(static_cast<AllocationSpace>(i));
351 } 352 }
352 } 353 }
353 354
354 Page* GetSweepingPageSafe(AllocationSpace space); 355 Page* GetSweepingPageSafe(AllocationSpace space);
355 void AddSweepingPageSafe(AllocationSpace space, Page* page); 356 void AddSweepingPageSafe(AllocationSpace space, Page* page);
356 357
357 void PrepareToBeSweptPage(AllocationSpace space, Page* page); 358 void PrepareToBeSweptPage(AllocationSpace space, Page* page);
358 359
359 Heap* heap_; 360 Heap* heap_;
360 base::Semaphore pending_sweeper_tasks_semaphore_; 361 base::Semaphore pending_sweeper_tasks_semaphore_;
361 base::Mutex mutex_; 362 base::Mutex mutex_;
362 SweptList swept_list_[kAllocationSpaces]; 363 SweptList swept_list_[kAllocationSpaces];
363 SweepingList sweeping_list_[kAllocationSpaces]; 364 SweepingList sweeping_list_[kAllocationSpaces];
364 bool sweeping_in_progress_; 365 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
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 // ----------------------------------------------------------------------- 640 // Starts sweeping of spaces by contributing on the main thread and setting
641 // Phase 2: Sweeping to clear mark bits and free non-live objects for 641 // up other pages for sweeping. Does not start sweeper tasks.
642 // a non-compacting collection. 642 void StartSweepSpaces();
643 // 643 void StartSweepSpace(PagedSpace* space);
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();
655 644
656 void EvacuateNewSpacePrologue(); 645 void EvacuateNewSpacePrologue();
657 646
658 void EvacuatePagesInParallel(); 647 void EvacuatePagesInParallel();
659 648
660 // The number of parallel compaction tasks, including the main thread. 649 // The number of parallel compaction tasks, including the main thread.
661 int NumberOfParallelCompactionTasks(int pages, intptr_t live_bytes); 650 int NumberOfParallelCompactionTasks(int pages, intptr_t live_bytes);
662 651
663 void EvacuateNewSpaceAndCandidates(); 652 void EvacuateNewSpaceAndCandidates();
664 653
665 void UpdatePointersAfterEvacuation(); 654 void UpdatePointersAfterEvacuation();
666 655
667 // Iterates through all live objects on a page using marking information. 656 // Iterates through all live objects on a page using marking information.
668 // Returns whether all objects have successfully been visited. 657 // Returns whether all objects have successfully been visited.
669 template <class Visitor> 658 template <class Visitor>
670 bool VisitLiveObjects(MemoryChunk* page, Visitor* visitor, 659 bool VisitLiveObjects(MemoryChunk* page, Visitor* visitor,
671 IterationMode mode); 660 IterationMode mode);
672 661
673 void RecomputeLiveBytes(MemoryChunk* page); 662 void RecomputeLiveBytes(MemoryChunk* page);
674 663
675 void ReleaseEvacuationCandidates(); 664 void ReleaseEvacuationCandidates();
676 665
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);
680 666
681 #ifdef DEBUG 667 #ifdef DEBUG
682 friend class MarkObjectVisitor; 668 friend class MarkObjectVisitor;
683 static void VisitObject(HeapObject* obj); 669 static void VisitObject(HeapObject* obj);
684 670
685 friend class UnmarkObjectVisitor; 671 friend class UnmarkObjectVisitor;
686 static void UnmarkObject(HeapObject* obj); 672 static void UnmarkObject(HeapObject* obj);
687 #endif 673 #endif
688 674
689 Heap* heap_; 675 Heap* heap_;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
744 730
745 private: 731 private:
746 MarkCompactCollector* collector_; 732 MarkCompactCollector* collector_;
747 }; 733 };
748 734
749 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space); 735 V8_EXPORT_PRIVATE const char* AllocationSpaceName(AllocationSpace space);
750 } // namespace internal 736 } // namespace internal
751 } // namespace v8 737 } // namespace v8
752 738
753 #endif // V8_HEAP_MARK_COMPACT_H_ 739 #endif // V8_HEAP_MARK_COMPACT_H_
OLDNEW
« no previous file with comments | « src/heap/incremental-marking.cc ('k') | src/heap/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698