Revision: 9004
Author:   [email protected]
Date:     Tue Aug 23 09:03:55 2011
Log:      Clear mark bits while sweeping and not explicitly.

[email protected],[email protected]
BUG=v8:1463

Review URL: http://codereview.chromium.org/7712026
http://code.google.com/p/v8/source/detail?r=9004

Modified:
 /branches/experimental/gc/src/incremental-marking.cc
 /branches/experimental/gc/src/incremental-marking.h
 /branches/experimental/gc/src/mark-compact.cc
 /branches/experimental/gc/src/mark-compact.h
 /branches/experimental/gc/src/spaces.cc

=======================================
--- /branches/experimental/gc/src/incremental-marking.cc Thu Aug 18 09:12:57 2011 +++ /branches/experimental/gc/src/incremental-marking.cc Tue Aug 23 09:03:55 2011
@@ -230,34 +230,31 @@
 }


-void IncrementalMarking::ClearMarkbits(PagedSpace* space) {
+void IncrementalMarking::ActivateIncrementalWriteBarrier(PagedSpace* space) {
   PageIterator it(space);
   while (it.has_next()) {
     Page* p = it.next();
-    Bitmap::Clear(p);
     SetOldSpacePageFlags(p, true);
   }
 }


-void IncrementalMarking::ClearMarkbits(NewSpace* space) {
+void IncrementalMarking::ActivateIncrementalWriteBarrier(NewSpace* space) {
   NewSpacePageIterator it(space->ToSpaceStart(), space->ToSpaceEnd());
   while (it.has_next()) {
     NewSpacePage* p = it.next();
-    Bitmap::Clear(p);
     SetNewSpacePageFlags(p, true);
   }
 }


-void IncrementalMarking::ClearMarkbits() {
-  // TODO(gc): Clear the mark bits in the sweeper.
-  ClearMarkbits(heap_->old_pointer_space());
-  ClearMarkbits(heap_->old_data_space());
-  ClearMarkbits(heap_->cell_space());
-  ClearMarkbits(heap_->map_space());
-  ClearMarkbits(heap_->code_space());
-  ClearMarkbits(heap_->new_space());
+void IncrementalMarking::ActivateIncrementalWriteBarrier() {
+  ActivateIncrementalWriteBarrier(heap_->old_pointer_space());
+  ActivateIncrementalWriteBarrier(heap_->old_data_space());
+  ActivateIncrementalWriteBarrier(heap_->cell_space());
+  ActivateIncrementalWriteBarrier(heap_->map_space());
+  ActivateIncrementalWriteBarrier(heap_->code_space());
+  ActivateIncrementalWriteBarrier(heap_->new_space());

   LargePage* lop = heap_->lo_space()->first_page();
   while (lop->is_valid()) {
@@ -265,38 +262,6 @@
     lop = lop->next_page();
   }
 }
-
-
-#ifdef DEBUG
-void IncrementalMarking::VerifyMarkbitsAreClean(PagedSpace* space) {
-  PageIterator it(space);
-
-  while (it.has_next()) {
-    Page* p = it.next();
-    ASSERT(p->markbits()->IsClean());
-  }
-}
-
-
-void IncrementalMarking::VerifyMarkbitsAreClean(NewSpace* space) {
-  NewSpacePageIterator it(space->ToSpaceStart(), space->ToSpaceEnd());
-
-  while (it.has_next()) {
-    NewSpacePage* p = it.next();
-    ASSERT(p->markbits()->IsClean());
-  }
-}
-
-
-void IncrementalMarking::VerifyMarkbitsAreClean() {
-  VerifyMarkbitsAreClean(heap_->old_pointer_space());
-  VerifyMarkbitsAreClean(heap_->old_data_space());
-  VerifyMarkbitsAreClean(heap_->code_space());
-  VerifyMarkbitsAreClean(heap_->cell_space());
-  VerifyMarkbitsAreClean(heap_->map_space());
-  VerifyMarkbitsAreClean(heap_->new_space());
-}
-#endif


 bool IncrementalMarking::WorthActivating() {
@@ -408,11 +373,11 @@
   if (FLAG_force_marking_deque_overflows) size = 64 * kPointerSize;
   marking_deque_.Initialize(addr, addr + size);

-  // Clear markbits.
-  ClearMarkbits();
+  ActivateIncrementalWriteBarrier();

 #ifdef DEBUG
-  VerifyMarkbitsAreClean();
+  // Marking bits are cleared by the sweeper.
+  heap_->mark_compact_collector()->VerifyMarkbitsAreClean();
 #endif

   // Mark strong roots grey.
=======================================
--- /branches/experimental/gc/src/incremental-marking.h Tue Aug 23 06:33:22 2011 +++ /branches/experimental/gc/src/incremental-marking.h Tue Aug 23 09:03:55 2011
@@ -200,21 +200,15 @@
     bytes_rescanned_ = 0;
     allocation_marking_factor_ = kInitialAllocationMarkingFactor;
   }
-
-  static void ClearMarkbits(PagedSpace* space);
-  static void ClearMarkbits(NewSpace* space);
-  void ClearMarkbits();
-
-#ifdef DEBUG
-  void VerifyMarkbitsAreClean();
-  static void VerifyMarkbitsAreClean(PagedSpace* space);
-  static void VerifyMarkbitsAreClean(NewSpace* space);
-#endif

   void StartMarking();

-  void DeactivateIncrementalWriteBarrierForSpace(PagedSpace* space);
-  void DeactivateIncrementalWriteBarrierForSpace(NewSpace* space);
+  static void ActivateIncrementalWriteBarrier(PagedSpace* space);
+  static void ActivateIncrementalWriteBarrier(NewSpace* space);
+  void ActivateIncrementalWriteBarrier();
+
+  static void DeactivateIncrementalWriteBarrierForSpace(PagedSpace* space);
+  static void DeactivateIncrementalWriteBarrierForSpace(NewSpace* space);
   void DeactivateIncrementalWriteBarrier();

   static void SetOldSpacePageFlags(MemoryChunk* chunk, bool is_marking);
=======================================
--- /branches/experimental/gc/src/mark-compact.cc       Tue Aug 23 06:33:22 2011
+++ /branches/experimental/gc/src/mark-compact.cc       Tue Aug 23 09:03:55 2011
@@ -280,7 +280,7 @@


 #ifdef DEBUG
-static void VerifyMarkbitsAreClean(PagedSpace* space) {
+void MarkCompactCollector::VerifyMarkbitsAreClean(PagedSpace* space) {
   PageIterator it(space);

   while (it.has_next()) {
@@ -289,7 +289,7 @@
   }
 }

-static void VerifyMarkbitsAreClean(NewSpace* space) {
+void MarkCompactCollector::VerifyMarkbitsAreClean(NewSpace* space) {
   NewSpacePageIterator it(space->bottom(), space->top());

   while (it.has_next()) {
@@ -298,13 +298,13 @@
   }
 }

-static void VerifyMarkbitsAreClean(Heap* heap) {
-  VerifyMarkbitsAreClean(heap->old_pointer_space());
-  VerifyMarkbitsAreClean(heap->old_data_space());
-  VerifyMarkbitsAreClean(heap->code_space());
-  VerifyMarkbitsAreClean(heap->cell_space());
-  VerifyMarkbitsAreClean(heap->map_space());
-  VerifyMarkbitsAreClean(heap->new_space());
+void MarkCompactCollector::VerifyMarkbitsAreClean() {
+  VerifyMarkbitsAreClean(heap_->old_pointer_space());
+  VerifyMarkbitsAreClean(heap_->old_data_space());
+  VerifyMarkbitsAreClean(heap_->code_space());
+  VerifyMarkbitsAreClean(heap_->cell_space());
+  VerifyMarkbitsAreClean(heap_->map_space());
+  VerifyMarkbitsAreClean(heap_->new_space());
 }
 #endif

@@ -328,7 +328,6 @@


 static void ClearMarkbits(Heap* heap) {
-  // TODO(gc): Clean the mark bits while sweeping.
   ClearMarkbits(heap->code_space());
   ClearMarkbits(heap->map_space());
   ClearMarkbits(heap->old_pointer_space());
@@ -425,8 +424,10 @@
   }
 #endif

+  // Clear marking bits for precise sweeping to collect all garbage.
if (heap()->incremental_marking()->IsMarking() && PreciseSweepingRequired()) {
     heap()->incremental_marking()->Abort();
+    ClearMarkbits(heap_);
   }

   if (!FLAG_never_compact) StartCompaction();
@@ -438,12 +439,11 @@
     space->PrepareForMarkCompact();
   }

-  if (!heap()->incremental_marking()->IsMarking()) {
-    ClearMarkbits(heap_);
 #ifdef DEBUG
-    VerifyMarkbitsAreClean(heap_);
-#endif
-  }
+  if (!heap()->incremental_marking()->IsMarking()) {
+    VerifyMarkbitsAreClean();
+  }
+#endif

 #ifdef DEBUG
   live_bytes_ = 0;
@@ -2614,9 +2614,8 @@
 // if requested.
 static void SweepPrecisely(PagedSpace* space, Page* p, SweepingMode mode) {
   ASSERT(!p->IsEvacuationCandidate() && !p->WasSwept());
+  ASSERT(!p->IsFlagSet(MemoryChunk::WAS_SWEPT_CONSERVATIVELY));
   MarkBit::CellType* cells = p->markbits()->cells();
-
-  p->ClearFlag(MemoryChunk::WAS_SWEPT_CONSERVATIVELY);
   p->MarkSwept();

   int last_cell_index =
@@ -2653,6 +2652,8 @@
       }
       free_start = free_end + size;
     }
+    // Clear marking bits for current cell.
+    cells[cell_index] = 0;
   }
   if (free_start != p->ObjectAreaEnd()) {
space->Free(free_start, static_cast<int>(p->ObjectAreaEnd() - free_start));
@@ -3093,22 +3094,19 @@
 // spaces will not contain the free space map.
intptr_t MarkCompactCollector::SweepConservatively(PagedSpace* space, Page* p) {
   ASSERT(!p->IsEvacuationCandidate() && !p->WasSwept());
-
-  intptr_t freed_bytes = 0;
-
   MarkBit::CellType* cells = p->markbits()->cells();
-
   p->SetFlag(MemoryChunk::WAS_SWEPT_CONSERVATIVELY);

- // This is the start of the 32 word block that we are currently looking at.
-  Address block_address = p->ObjectAreaStart();
-
   int last_cell_index =
       Bitmap::IndexToCell(
           Bitmap::CellAlignIndex(
               p->AddressToMarkbitIndex(p->ObjectAreaEnd())));

   int cell_index = Page::kFirstUsedCell;
+  intptr_t freed_bytes = 0;
+
+ // This is the start of the 32 word block that we are currently looking at.
+  Address block_address = p->ObjectAreaStart();

// Skip over all the dead objects at the start of the page and mark them free.
   for (cell_index = Page::kFirstUsedCell;
@@ -3164,6 +3162,8 @@
// Update our undigested record of where the current free area started.
       free_start = block_address;
       free_start_cell = cell;
+      // Clear marking bits for current cell.
+      cells[cell_index] = 0;
     }
   }

=======================================
--- /branches/experimental/gc/src/mark-compact.h        Tue Aug 23 06:33:22 2011
+++ /branches/experimental/gc/src/mark-compact.h        Tue Aug 23 09:03:55 2011
@@ -440,6 +440,12 @@
     PRECISE
   };

+#ifdef DEBUG
+  void VerifyMarkbitsAreClean();
+  static void VerifyMarkbitsAreClean(PagedSpace* space);
+  static void VerifyMarkbitsAreClean(NewSpace* space);
+#endif
+
   // Sweep a single page from the given space conservatively.
   // Return a number of reclaimed bytes.
   static intptr_t SweepConservatively(PagedSpace* space, Page* p);
=======================================
--- /branches/experimental/gc/src/spaces.cc     Tue Aug 23 06:33:22 2011
+++ /branches/experimental/gc/src/spaces.cc     Tue Aug 23 09:03:55 2011
@@ -1930,26 +1930,31 @@
   Free(top(), old_linear_size);
   SetTop(NULL, NULL);

-  // Stop lazy sweeping for the space.
-  if (FLAG_trace_gc && first_unswept_page_ != NULL) {
+  // Stop lazy sweeping and clear marking bits for the space.
+  if (first_unswept_page_ != NULL) {
     int pages = 0;
-    Page* p = last_unswept_page_;
+    Page* last = last_unswept_page_->next_page();
+    Page* p = first_unswept_page_;
     do {
       pages++;
+      Bitmap::Clear(p);
       p = p->next_page();
-    } while (p != last_unswept_page_);
-    PrintF("Abandoned %d unswept pages\n", pages);
+    } while (p != last);
+    if (FLAG_trace_gc) {
+      PrintF("Abandoned %d unswept pages\n", pages);
+    }
   }
   first_unswept_page_ = last_unswept_page_ = Page::FromAddress(NULL);

   // Clear the free list before a full GC---it will be rebuilt afterward.
   free_list_.Reset();

-  // Clear EVACUATED flag from all pages.
+  // Clear WAS_SWEPT and WAS_SWEPT_CONSERVATIVELY flags from all pages.
   PageIterator it(this);
   while (it.has_next()) {
     Page* page = it.next();
     page->ClearSwept();
+    page->ClearFlag(MemoryChunk::WAS_SWEPT_CONSERVATIVELY);
   }
 }

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to