[heap] Cleanup: Align naming of parallel sweeping with parallel compaction.
authormlippautz <mlippautz@chromium.org>
Fri, 18 Sep 2015 10:49:11 +0000 (03:49 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 18 Sep 2015 10:49:20 +0000 (10:49 +0000)
Pure refactoring.

R=hpayer@chromium.org
BUG=

Review URL: https://codereview.chromium.org/1354613002

Cr-Commit-Position: refs/heads/master@{#30822}

src/heap/mark-compact.cc
src/heap/mark-compact.h
src/heap/spaces.cc
src/heap/spaces.h
test/cctest/test-heap.cc

index 9f5ac52028ae2bda5a16c8cb8d2c62adb03a821c..7f98b33ec508509c858f20078a5548009ed9d941 100644 (file)
@@ -52,13 +52,7 @@ MarkCompactCollector::MarkCompactCollector(Heap* heap)
       state_(IDLE),
 #endif
       marking_parity_(ODD_MARKING_PARITY),
-      compacting_(false),
       was_marked_incrementally_(false),
-      sweeping_in_progress_(false),
-      parallel_compaction_in_progress_(false),
-      pending_sweeper_jobs_semaphore_(0),
-      pending_compaction_tasks_semaphore_(0),
-      concurrent_compaction_tasks_active_(0),
       evacuation_(false),
       slots_buffer_allocator_(nullptr),
       migration_slots_buffer_(nullptr),
@@ -66,7 +60,13 @@ MarkCompactCollector::MarkCompactCollector(Heap* heap)
       marking_deque_memory_(NULL),
       marking_deque_memory_committed_(0),
       code_flusher_(NULL),
-      have_code_to_deoptimize_(false) {
+      have_code_to_deoptimize_(false),
+      compacting_(false),
+      sweeping_in_progress_(false),
+      compaction_in_progress_(false),
+      pending_sweeper_tasks_semaphore_(0),
+      pending_compaction_tasks_semaphore_(0),
+      concurrent_compaction_tasks_active_(0) {
 }
 
 #ifdef VERIFY_HEAP
@@ -507,7 +507,7 @@ class MarkCompactCollector::SweeperTask : public v8::Task {
   // v8::Task overrides.
   void Run() override {
     heap_->mark_compact_collector()->SweepInParallel(space_, 0);
-    heap_->mark_compact_collector()->pending_sweeper_jobs_semaphore_.Signal();
+    heap_->mark_compact_collector()->pending_sweeper_tasks_semaphore_.Signal();
   }
 
   Heap* heap_;
@@ -559,9 +559,9 @@ void MarkCompactCollector::EnsureSweepingCompleted() {
   }
 
   if (heap()->concurrent_sweeping_enabled()) {
-    pending_sweeper_jobs_semaphore_.Wait();
-    pending_sweeper_jobs_semaphore_.Wait();
-    pending_sweeper_jobs_semaphore_.Wait();
+    pending_sweeper_tasks_semaphore_.Wait();
+    pending_sweeper_tasks_semaphore_.Wait();
+    pending_sweeper_tasks_semaphore_.Wait();
   }
 
   ParallelSweepSpacesComplete();
@@ -582,11 +582,11 @@ void MarkCompactCollector::EnsureSweepingCompleted() {
 
 
 bool MarkCompactCollector::IsSweepingCompleted() {
-  if (!pending_sweeper_jobs_semaphore_.WaitFor(
+  if (!pending_sweeper_tasks_semaphore_.WaitFor(
           base::TimeDelta::FromSeconds(0))) {
     return false;
   }
-  pending_sweeper_jobs_semaphore_.Signal();
+  pending_sweeper_tasks_semaphore_.Signal();
   return true;
 }
 
@@ -2565,7 +2565,7 @@ void MarkCompactCollector::RecordMigratedSlot(
   // When parallel compaction is in progress, store and slots buffer entries
   // require synchronization.
   if (heap_->InNewSpace(value)) {
-    if (parallel_compaction_in_progress_) {
+    if (compaction_in_progress_) {
       heap_->store_buffer()->MarkSynchronized(slot);
     } else {
       heap_->store_buffer()->Mark(slot);
@@ -3388,7 +3388,7 @@ void MarkCompactCollector::EvacuatePagesInParallel() {
       ->Get(CODE_SPACE)
       ->MoveOverFreeMemory(heap()->code_space());
 
-  parallel_compaction_in_progress_ = true;
+  compaction_in_progress_ = true;
   // Kick off parallel tasks.
   for (int i = 1; i < num_tasks; i++) {
     concurrent_compaction_tasks_active_++;
@@ -3471,7 +3471,7 @@ void MarkCompactCollector::WaitUntilCompactionCompleted() {
     pending_compaction_tasks_semaphore_.Wait();
     concurrent_compaction_tasks_active_--;
   }
-  parallel_compaction_in_progress_ = false;
+  compaction_in_progress_ = false;
 }
 
 
@@ -3482,8 +3482,8 @@ void MarkCompactCollector::EvacuatePages(
     Page* p = evacuation_candidates_[i];
     DCHECK(p->IsEvacuationCandidate() ||
            p->IsFlagSet(Page::RESCAN_ON_EVACUATION));
-    DCHECK(static_cast<int>(p->parallel_sweeping()) ==
-           MemoryChunk::SWEEPING_DONE);
+    DCHECK(static_cast<int>(p->parallel_sweeping_state().Value()) ==
+           MemoryChunk::kSweepingDone);
     if (p->parallel_compaction_state().TrySetValue(
             MemoryChunk::kCompactingDone, MemoryChunk::kCompactingInProgress)) {
       if (p->IsEvacuationCandidate()) {
@@ -3627,7 +3627,7 @@ static int Sweep(PagedSpace* space, FreeList* free_list, Page* p,
   if (parallelism == MarkCompactCollector::SWEEP_IN_PARALLEL) {
     // When concurrent sweeping is active, the page will be marked after
     // sweeping by the main thread.
-    p->set_parallel_sweeping(MemoryChunk::SWEEPING_FINALIZE);
+    p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingFinalize);
   } else {
     p->SetWasSwept();
   }
@@ -4276,11 +4276,12 @@ int MarkCompactCollector::SweepInParallel(Page* page, PagedSpace* space) {
   int max_freed = 0;
   if (page->TryLock()) {
     // If this page was already swept in the meantime, we can return here.
-    if (page->parallel_sweeping() != MemoryChunk::SWEEPING_PENDING) {
+    if (page->parallel_sweeping_state().Value() !=
+        MemoryChunk::kSweepingPending) {
       page->mutex()->Unlock();
       return 0;
     }
-    page->set_parallel_sweeping(MemoryChunk::SWEEPING_IN_PROGRESS);
+    page->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingInProgress);
     FreeList* free_list;
     FreeList private_free_list(space);
     if (space->identity() == OLD_SPACE) {
@@ -4321,7 +4322,7 @@ void MarkCompactCollector::SweepSpace(PagedSpace* space, SweeperType sweeper) {
 
   while (it.has_next()) {
     Page* p = it.next();
-    DCHECK(p->parallel_sweeping() == MemoryChunk::SWEEPING_DONE);
+    DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone);
 
     // Clear sweeping flags indicating that marking bits are still intact.
     p->ClearWasSwept();
@@ -4375,7 +4376,7 @@ void MarkCompactCollector::SweepSpace(PagedSpace* space, SweeperType sweeper) {
             PrintF("Sweeping 0x%" V8PRIxPTR " in parallel.\n",
                    reinterpret_cast<intptr_t>(p));
           }
-          p->set_parallel_sweeping(MemoryChunk::SWEEPING_PENDING);
+          p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingPending);
           space->IncreaseUnsweptFreeBytes(p);
         }
         space->set_end_of_unswept_pages(p);
@@ -4482,11 +4483,12 @@ void MarkCompactCollector::ParallelSweepSpaceComplete(PagedSpace* space) {
   PageIterator it(space);
   while (it.has_next()) {
     Page* p = it.next();
-    if (p->parallel_sweeping() == MemoryChunk::SWEEPING_FINALIZE) {
-      p->set_parallel_sweeping(MemoryChunk::SWEEPING_DONE);
+    if (p->parallel_sweeping_state().Value() ==
+        MemoryChunk::kSweepingFinalize) {
+      p->parallel_sweeping_state().SetValue(MemoryChunk::kSweepingDone);
       p->SetWasSwept();
     }
-    DCHECK(p->parallel_sweeping() == MemoryChunk::SWEEPING_DONE);
+    DCHECK(p->parallel_sweeping_state().Value() == MemoryChunk::kSweepingDone);
   }
 }
 
index 6fc5dbba6206421feba3dab05b972d7331c771e8..6558eb2ddebba2b6349c64eb2fbf4f2c9ea40247 100644 (file)
@@ -542,27 +542,8 @@ class MarkCompactCollector {
 
   MarkingParity marking_parity_;
 
-  // True if we are collecting slots to perform evacuation from evacuation
-  // candidates.
-  bool compacting_;
-
   bool was_marked_incrementally_;
 
-  // True if concurrent or parallel sweeping is currently in progress.
-  bool sweeping_in_progress_;
-
-  // True if parallel compaction is currently in progress.
-  bool parallel_compaction_in_progress_;
-
-  // Synchronize sweeper threads.
-  base::Semaphore pending_sweeper_jobs_semaphore_;
-
-  // Synchronize compaction tasks.
-  base::Semaphore pending_compaction_tasks_semaphore_;
-
-  // Number of active compaction tasks (including main thread).
-  intptr_t concurrent_compaction_tasks_active_;
-
   bool evacuation_;
 
   SlotsBufferAllocator* slots_buffer_allocator_;
@@ -793,6 +774,25 @@ class MarkCompactCollector {
   base::SmartPointer<FreeList> free_list_code_space_;
   base::SmartPointer<FreeList> free_list_map_space_;
 
+  // True if we are collecting slots to perform evacuation from evacuation
+  // candidates.
+  bool compacting_;
+
+  // True if concurrent or parallel sweeping is currently in progress.
+  bool sweeping_in_progress_;
+
+  // True if parallel compaction is currently in progress.
+  bool compaction_in_progress_;
+
+  // Semaphore used to synchronize sweeper tasks.
+  base::Semaphore pending_sweeper_tasks_semaphore_;
+
+  // Semaphore used to synchronize compaction tasks.
+  base::Semaphore pending_compaction_tasks_semaphore_;
+
+  // Number of active compaction tasks (including main thread).
+  intptr_t concurrent_compaction_tasks_active_;
+
   friend class Heap;
 };
 
index c74b93f52c1672417ffbf9d250ffebee234b8b76..259ee75e0d09b978c8ac6ed93ac3e18331a346fd 100644 (file)
@@ -471,7 +471,7 @@ MemoryChunk* MemoryChunk::Initialize(Heap* heap, Address base, size_t size,
   chunk->write_barrier_counter_ = kWriteBarrierCounterGranularity;
   chunk->progress_bar_ = 0;
   chunk->high_water_mark_.SetValue(static_cast<intptr_t>(area_start - base));
-  chunk->set_parallel_sweeping(SWEEPING_DONE);
+  chunk->parallel_sweeping_state().SetValue(kSweepingDone);
   chunk->parallel_compaction_state().SetValue(kCompactingDone);
   chunk->mutex_ = NULL;
   chunk->available_in_small_free_list_ = 0;
index 0bc1c175a2c019020ff17a1c1d724d3fb71decbf..b8fc9b7efe0845d4852b6660c8465abdda18f115 100644 (file)
@@ -281,6 +281,19 @@ class MemoryChunk {
     kCompactingAborted,
   };
 
+  // |kSweepingDone|: The page state when sweeping is complete or sweeping must
+  //   not be performed on that page.
+  // |kSweepingFinalize|: A sweeper thread is done sweeping this page and will
+  //   not touch the page memory anymore.
+  // |kSweepingInProgress|: This page is currently swept by a sweeper thread.
+  // |kSweepingPending|: This page is ready for parallel sweeping.
+  enum ParallelSweepingState {
+    kSweepingDone,
+    kSweepingFinalize,
+    kSweepingInProgress,
+    kSweepingPending
+  };
+
   // Only works if the pointer is in the first kPageSize of the MemoryChunk.
   static MemoryChunk* FromAddress(Address a) {
     return reinterpret_cast<MemoryChunk*>(OffsetFrom(a) & ~kAlignmentMask);
@@ -448,27 +461,8 @@ class MemoryChunk {
   // Return all current flags.
   intptr_t GetFlags() { return flags_; }
 
-
-  // SWEEPING_DONE - The page state when sweeping is complete or sweeping must
-  // not be performed on that page.
-  // SWEEPING_FINALIZE - A sweeper thread is done sweeping this page and will
-  // not touch the page memory anymore.
-  // SWEEPING_IN_PROGRESS - This page is currently swept by a sweeper thread.
-  // SWEEPING_PENDING - This page is ready for parallel sweeping.
-  enum ParallelSweepingState {
-    SWEEPING_DONE,
-    SWEEPING_FINALIZE,
-    SWEEPING_IN_PROGRESS,
-    SWEEPING_PENDING
-  };
-
-  ParallelSweepingState parallel_sweeping() {
-    return static_cast<ParallelSweepingState>(
-        base::Acquire_Load(&parallel_sweeping_));
-  }
-
-  void set_parallel_sweeping(ParallelSweepingState state) {
-    base::Release_Store(&parallel_sweeping_, state);
+  AtomicValue<ParallelSweepingState>& parallel_sweeping_state() {
+    return parallel_sweeping_;
   }
 
   AtomicValue<ParallelCompactingState>& parallel_compaction_state() {
@@ -488,7 +482,9 @@ class MemoryChunk {
     DCHECK(SweepingCompleted());
   }
 
-  bool SweepingCompleted() { return parallel_sweeping() <= SWEEPING_FINALIZE; }
+  bool SweepingCompleted() {
+    return parallel_sweeping_state().Value() <= kSweepingFinalize;
+  }
 
   // Manage live byte count (count of bytes known to be live,
   // because they are marked black).
@@ -743,7 +739,7 @@ class MemoryChunk {
   AtomicValue<intptr_t> high_water_mark_;
 
   base::Mutex* mutex_;
-  base::AtomicWord parallel_sweeping_;
+  AtomicValue<ParallelSweepingState> parallel_sweeping_;
   AtomicValue<ParallelCompactingState> parallel_compaction_;
 
   // PagedSpace free-list statistics.
index 4c286f2c1c14e38eb22694ac933850ab7d27099c..8d7666910e833cc27884617fef17fbb15f483600 100644 (file)
@@ -5644,7 +5644,8 @@ TEST(ArrayShiftSweeping) {
   CHECK(heap->InOldSpace(o->elements()));
   CHECK(heap->InOldSpace(*o));
   Page* page = Page::FromAddress(o->elements()->address());
-  CHECK(page->parallel_sweeping() <= MemoryChunk::SWEEPING_FINALIZE ||
+  CHECK(page->parallel_sweeping_state().Value() <=
+            MemoryChunk::kSweepingFinalize ||
         Marking::IsBlack(Marking::MarkBitFrom(o->elements())));
 }