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

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

Issue 1886723002: [heap] Sweeper refactoring round 2 (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months 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 | « no previous file | 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>
9
8 #include "src/base/bits.h" 10 #include "src/base/bits.h"
9 #include "src/heap/spaces.h" 11 #include "src/heap/spaces.h"
10 #include "src/heap/store-buffer.h" 12 #include "src/heap/store-buffer.h"
11 13
12 namespace v8 { 14 namespace v8 {
13 namespace internal { 15 namespace internal {
14 16
15 // Callback function, returns whether an object is alive. The heap size 17 // Callback function, returns whether an object is alive. The heap size
16 // of the object is returned in size. It optionally updates the offset 18 // of the object is returned in size. It optionally updates the offset
17 // to the first live object in the page (only used for old and map objects). 19 // to the first live object in the page (only used for old and map objects).
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 404
403 class Sweeper { 405 class Sweeper {
404 public: 406 public:
405 class SweeperTask; 407 class SweeperTask;
406 408
407 enum SweepingMode { SWEEP_ONLY, SWEEP_AND_VISIT_LIVE_OBJECTS }; 409 enum SweepingMode { SWEEP_ONLY, SWEEP_AND_VISIT_LIVE_OBJECTS };
408 enum SkipListRebuildingMode { REBUILD_SKIP_LIST, IGNORE_SKIP_LIST }; 410 enum SkipListRebuildingMode { REBUILD_SKIP_LIST, IGNORE_SKIP_LIST };
409 enum FreeSpaceTreatmentMode { IGNORE_FREE_SPACE, ZAP_FREE_SPACE }; 411 enum FreeSpaceTreatmentMode { IGNORE_FREE_SPACE, ZAP_FREE_SPACE };
410 enum SweepingParallelism { SWEEP_ON_MAIN_THREAD, SWEEP_IN_PARALLEL }; 412 enum SweepingParallelism { SWEEP_ON_MAIN_THREAD, SWEEP_IN_PARALLEL };
411 413
412 typedef std::vector<Page*> SweepingList; 414 typedef std::deque<Page*> SweepingList;
413 typedef List<Page*> SweptList; 415 typedef List<Page*> SweptList;
414 416
415 template <SweepingMode sweeping_mode, SweepingParallelism parallelism, 417 template <SweepingMode sweeping_mode, SweepingParallelism parallelism,
416 SkipListRebuildingMode skip_list_mode, 418 SkipListRebuildingMode skip_list_mode,
417 FreeSpaceTreatmentMode free_space_mode> 419 FreeSpaceTreatmentMode free_space_mode>
418 static int RawSweep(PagedSpace* space, Page* p, ObjectVisitor* v); 420 static int RawSweep(PagedSpace* space, Page* p, ObjectVisitor* v);
419 421
420 explicit Sweeper(Heap* heap) 422 explicit Sweeper(Heap* heap)
421 : heap_(heap), 423 : heap_(heap),
422 pending_sweeper_tasks_semaphore_(0), 424 pending_sweeper_tasks_semaphore_(0),
423 sweeping_in_progress_(false), 425 sweeping_in_progress_(false),
424 num_sweeping_tasks_(0) { 426 late_pages_(false),
425 ForAllSweepingSpaces([this](AllocationSpace space) { 427 num_sweeping_tasks_(0) {}
426 late_sweeping_list_[space] = nullptr;
427 tmp_late_sweeping_list_[space] = nullptr;
428 });
429 }
430 428
431 bool sweeping_in_progress() { return sweeping_in_progress_; } 429 bool sweeping_in_progress() { return sweeping_in_progress_; }
430 bool contains_late_pages() { return late_pages_; }
432 431
433 void AddPage(AllocationSpace space, Page* page); 432 void AddPage(AllocationSpace space, Page* page);
434 void AddLatePage(AllocationSpace space, Page* page); 433 void AddLatePage(AllocationSpace space, Page* page);
435 void CommitLateList(AllocationSpace space);
436 434
437 int ParallelSweepSpace(AllocationSpace identity, int required_freed_bytes, 435 int ParallelSweepSpace(AllocationSpace identity, int required_freed_bytes,
438 int max_pages = 0); 436 int max_pages = 0);
439 int ParallelSweepPage(Page* page, PagedSpace* space); 437 int ParallelSweepPage(Page* page, PagedSpace* space);
440 438
441 void StartSweeping(); 439 void StartSweeping();
442 void StartSweepingHelper(AllocationSpace space_to_start); 440 void StartSweepingHelper(AllocationSpace space_to_start);
443 void EnsureCompleted(); 441 void EnsureCompleted();
444 bool IsSweepingCompleted(); 442 bool IsSweepingCompleted();
445 void SweepOrWaitUntilSweepingCompleted(Page* page); 443 void SweepOrWaitUntilSweepingCompleted(Page* page);
446 444
447 void AddSweptPageSafe(PagedSpace* space, Page* page); 445 void AddSweptPageSafe(PagedSpace* space, Page* page);
448 Page* GetSweptPageSafe(PagedSpace* space); 446 Page* GetSweptPageSafe(PagedSpace* space);
449 447
450 private: 448 private:
451 static const int kAllocationSpaces = LAST_PAGED_SPACE + 1; 449 static const int kAllocationSpaces = LAST_PAGED_SPACE + 1;
452 450
453 template <typename Callback> 451 template <typename Callback>
454 void ForAllSweepingSpaces(Callback callback) { 452 void ForAllSweepingSpaces(Callback callback) {
455 for (int i = 0; i < kAllocationSpaces; i++) { 453 for (int i = 0; i < kAllocationSpaces; i++) {
456 callback(static_cast<AllocationSpace>(i)); 454 callback(static_cast<AllocationSpace>(i));
457 } 455 }
458 } 456 }
459 457
460 SweepingList* GetLateSweepingListSafe(AllocationSpace space); 458 Page* GetSweepingPageSafe(AllocationSpace space);
459 void AddSweepingPageSafe(AllocationSpace space, Page* page);
461 460
462 void PrepareToBeSweptPage(AllocationSpace space, Page* page); 461 void PrepareToBeSweptPage(AllocationSpace space, Page* page);
463 void ParallelSweepList(SweepingList& list, AllocationSpace out_space,
464 int required_freed_bytes, int max_pages,
465 int* max_freed, int* pages_freed);
466 462
467 Heap* heap_; 463 Heap* heap_;
468 base::Mutex mutex_; 464 base::Mutex mutex_;
469 base::Semaphore pending_sweeper_tasks_semaphore_; 465 base::Semaphore pending_sweeper_tasks_semaphore_;
470 SweptList swept_list_[kAllocationSpaces]; 466 SweptList swept_list_[kAllocationSpaces];
471 SweepingList sweeping_list_[kAllocationSpaces]; 467 SweepingList sweeping_list_[kAllocationSpaces];
472 SweepingList* late_sweeping_list_[kAllocationSpaces];
473 SweepingList* tmp_late_sweeping_list_[kAllocationSpaces];
474 bool sweeping_in_progress_; 468 bool sweeping_in_progress_;
469 bool late_pages_;
475 int num_sweeping_tasks_; 470 int num_sweeping_tasks_;
476 }; 471 };
477 472
478 enum IterationMode { 473 enum IterationMode {
479 kKeepMarking, 474 kKeepMarking,
480 kClearMarkbits, 475 kClearMarkbits,
481 }; 476 };
482 477
483 static void Initialize(); 478 static void Initialize();
484 479
(...skipping 413 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 private: 893 private:
899 MarkCompactCollector* collector_; 894 MarkCompactCollector* collector_;
900 }; 895 };
901 896
902 897
903 const char* AllocationSpaceName(AllocationSpace space); 898 const char* AllocationSpaceName(AllocationSpace space);
904 } // namespace internal 899 } // namespace internal
905 } // namespace v8 900 } // namespace v8
906 901
907 #endif // V8_HEAP_MARK_COMPACT_H_ 902 #endif // V8_HEAP_MARK_COMPACT_H_
OLDNEW
« no previous file with comments | « no previous file | src/heap/mark-compact.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698