Reviewers: *Hannes Payer, Michael Lippautz,

Message:
Hannes: PTAL.
Mike: FYI.


https://codereview.chromium.org/1293773002/diff/20001/src/heap/mark-compact.h
File src/heap/mark-compact.h (right):

https://codereview.chromium.org/1293773002/diff/20001/src/heap/mark-compact.h#newcode210
src/heap/mark-compact.h:210: INLINE(bool PushBlack(HeapObject* object))
{
Note that {PushBlack} and {PushGrey} can now be unified into one single
{Push} method. Let me know if you want me to do that in this CL or in a
separate CL.

https://codereview.chromium.org/1293773002/diff/20001/src/heap/mark-compact.h#newcode240
src/heap/mark-compact.h:240: INLINE(void UnshiftGrey(HeapObject*
object)) {
Likewise for unification of {UnshiftGrey} and {UnshiftBlack}.

Description:
[heap] Simplify MarkingDeque implementation.

This removes the dependency of the MarkingDeque on the underlying
collector by moving out the live bytes accounting and object color
mutations into a wrapper. The MarkingDeque can now split into a
separate file.

[email protected]

Please review this at https://codereview.chromium.org/1293773002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+56, -41 lines):
  M src/heap/incremental-marking.cc
  M src/heap/mark-compact.h
  M src/heap/mark-compact.cc
  M src/heap/mark-compact-inl.h


Index: src/heap/incremental-marking.cc
diff --git a/src/heap/incremental-marking.cc b/src/heap/incremental-marking.cc index db19165f0a310eb0dec219df1226b8333c17e96e..cb2ac1e75d95f2b9ab0e02a4b0495291f5bae2eb 100644
--- a/src/heap/incremental-marking.cc
+++ b/src/heap/incremental-marking.cc
@@ -198,11 +198,15 @@ class IncrementalMarkingMarkingVisitor
       } while (scan_until_end && start_offset < object_size);
       chunk->set_progress_bar(start_offset);
       if (start_offset < object_size) {
+        MarkCompactCollector* collector = heap->mark_compact_collector();
         if (Marking::IsGrey(Marking::MarkBitFrom(object))) {
- heap->mark_compact_collector()->marking_deque()->UnshiftGrey(object);
+          collector->marking_deque()->UnshiftGrey(object);
         } else {
           DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object)));
- heap->mark_compact_collector()->marking_deque()->UnshiftBlack(object);
+          if (!collector->marking_deque()->UnshiftBlack(object)) {
+            MemoryChunk::IncrementLiveBytesFromGC(object, -object->Size());
+            Marking::BlackToGrey(object);
+          }
         }
         heap->incremental_marking()->NotifyIncompleteScanOfObject(
             object_size - (start_offset - already_scanned_offset));
Index: src/heap/mark-compact-inl.h
diff --git a/src/heap/mark-compact-inl.h b/src/heap/mark-compact-inl.h
index d38e31e55602c14a874814ca5605facc46b61e43..015440bc40f222e314a11de2973cb23e981db854 100644
--- a/src/heap/mark-compact-inl.h
+++ b/src/heap/mark-compact-inl.h
@@ -23,13 +23,21 @@ void MarkCompactCollector::SetFlags(int flags) {
 }


+void MarkCompactCollector::PushBlack(HeapObject* obj) {
+  if (marking_deque_.PushBlack(obj)) {
+    MemoryChunk::IncrementLiveBytesFromGC(obj, obj->Size());
+  } else {
+    Marking::BlackToGrey(obj);
+  }
+}
+
+
 void MarkCompactCollector::MarkObject(HeapObject* obj, MarkBit mark_bit) {
   DCHECK(Marking::MarkBitFrom(obj) == mark_bit);
   if (Marking::IsWhite(mark_bit)) {
     Marking::WhiteToBlack(mark_bit);
-    MemoryChunk::IncrementLiveBytesFromGC(obj, obj->Size());
     DCHECK(obj->GetIsolate()->heap()->Contains(obj));
-    marking_deque_.PushBlack(obj);
+    PushBlack(obj);
   }
 }

Index: src/heap/mark-compact.cc
diff --git a/src/heap/mark-compact.cc b/src/heap/mark-compact.cc
index e34dbfd2337cc0bec932e2729d51ae1aeb5d1787..95f762c05cc09b6d23400f02114e0a1f1623cd97 100644
--- a/src/heap/mark-compact.cc
+++ b/src/heap/mark-compact.cc
@@ -1734,21 +1734,18 @@ class MarkCompactWeakObjectRetainer : public WeakObjectRetainer {
 // iterator.  Stop when the marking stack is filled or the end of the space
 // is reached, whichever comes first.
 template <class T>
-static void DiscoverGreyObjectsWithIterator(Heap* heap,
-                                            MarkingDeque* marking_deque,
-                                            T* it) {
+void MarkCompactCollector::DiscoverGreyObjectsWithIterator(T* it) {
   // The caller should ensure that the marking stack is initially not full,
   // so that we don't waste effort pointlessly scanning for objects.
-  DCHECK(!marking_deque->IsFull());
+  DCHECK(!marking_deque()->IsFull());

-  Map* filler_map = heap->one_pointer_filler_map();
+  Map* filler_map = heap()->one_pointer_filler_map();
for (HeapObject* object = it->Next(); object != NULL; object = it->Next()) {
     MarkBit markbit = Marking::MarkBitFrom(object);
     if ((object->map() != filler_map) && Marking::IsGrey(markbit)) {
       Marking::GreyToBlack(markbit);
-      MemoryChunk::IncrementLiveBytesFromGC(object, object->Size());
-      marking_deque->PushBlack(object);
-      if (marking_deque->IsFull()) return;
+      PushBlack(object);
+      if (marking_deque()->IsFull()) return;
     }
   }
 }
@@ -1757,9 +1754,8 @@ static void DiscoverGreyObjectsWithIterator(Heap* heap,
 static inline int MarkWordToObjectStarts(uint32_t mark_bits, int* starts);


-static void DiscoverGreyObjectsOnPage(MarkingDeque* marking_deque,
-                                      MemoryChunk* p) {
-  DCHECK(!marking_deque->IsFull());
+void MarkCompactCollector::DiscoverGreyObjectsOnPage(MemoryChunk* p) {
+  DCHECK(!marking_deque()->IsFull());
   DCHECK(strcmp(Marking::kWhiteBitPattern, "00") == 0);
   DCHECK(strcmp(Marking::kBlackBitPattern, "10") == 0);
   DCHECK(strcmp(Marking::kGreyBitPattern, "11") == 0);
@@ -1791,9 +1787,8 @@ static void DiscoverGreyObjectsOnPage(MarkingDeque* marking_deque,
       Marking::GreyToBlack(markbit);
       Address addr = cell_base + offset * kPointerSize;
       HeapObject* object = HeapObject::FromAddress(addr);
-      MemoryChunk::IncrementLiveBytesFromGC(object, object->Size());
-      marking_deque->PushBlack(object);
-      if (marking_deque->IsFull()) return;
+      PushBlack(object);
+      if (marking_deque()->IsFull()) return;
       offset += 2;
       grey_objects >>= 2;
     }
@@ -1866,25 +1861,23 @@ int MarkCompactCollector::DiscoverAndEvacuateBlackObjectsOnPage(
 }


-static void DiscoverGreyObjectsInSpace(Heap* heap, MarkingDeque* marking_deque,
-                                       PagedSpace* space) {
+void MarkCompactCollector::DiscoverGreyObjectsInSpace(PagedSpace* space) {
   PageIterator it(space);
   while (it.has_next()) {
     Page* p = it.next();
-    DiscoverGreyObjectsOnPage(marking_deque, p);
-    if (marking_deque->IsFull()) return;
+    DiscoverGreyObjectsOnPage(p);
+    if (marking_deque()->IsFull()) return;
   }
 }


-static void DiscoverGreyObjectsInNewSpace(Heap* heap,
-                                          MarkingDeque* marking_deque) {
-  NewSpace* space = heap->new_space();
+void MarkCompactCollector::DiscoverGreyObjectsInNewSpace() {
+  NewSpace* space = heap()->new_space();
   NewSpacePageIterator it(space->bottom(), space->top());
   while (it.has_next()) {
     NewSpacePage* page = it.next();
-    DiscoverGreyObjectsOnPage(marking_deque, page);
-    if (marking_deque->IsFull()) return;
+    DiscoverGreyObjectsOnPage(page);
+    if (marking_deque()->IsFull()) return;
   }
 }

@@ -2009,20 +2002,20 @@ void MarkCompactCollector::RefillMarkingDeque() {
isolate()->CountUsage(v8::Isolate::UseCounterFeature::kMarkDequeOverflow);
   DCHECK(marking_deque_.overflowed());

-  DiscoverGreyObjectsInNewSpace(heap(), &marking_deque_);
+  DiscoverGreyObjectsInNewSpace();
   if (marking_deque_.IsFull()) return;

-  DiscoverGreyObjectsInSpace(heap(), &marking_deque_, heap()->old_space());
+  DiscoverGreyObjectsInSpace(heap()->old_space());
   if (marking_deque_.IsFull()) return;

- DiscoverGreyObjectsInSpace(heap(), &marking_deque_, heap()->code_space());
+  DiscoverGreyObjectsInSpace(heap()->code_space());
   if (marking_deque_.IsFull()) return;

-  DiscoverGreyObjectsInSpace(heap(), &marking_deque_, heap()->map_space());
+  DiscoverGreyObjectsInSpace(heap()->map_space());
   if (marking_deque_.IsFull()) return;

   LargeObjectIterator lo_it(heap()->lo_space());
-  DiscoverGreyObjectsWithIterator(heap(), &marking_deque_, &lo_it);
+  DiscoverGreyObjectsWithIterator(&lo_it);
   if (marking_deque_.IsFull()) return;

   marking_deque_.ClearOverflowed();
Index: src/heap/mark-compact.h
diff --git a/src/heap/mark-compact.h b/src/heap/mark-compact.h
index 6168436ee06d684986d9ad208aece45e8ebf4547..51a117d43d69ac22a9fb8d0a6c37bc77dc92ea76 100644
--- a/src/heap/mark-compact.h
+++ b/src/heap/mark-compact.h
@@ -205,18 +205,17 @@ class MarkingDeque {

   void SetOverflowed() { overflowed_ = true; }

-  // Push the (marked) object on the marking stack if there is room,
-  // otherwise mark the object as overflowed and wait for a rescan of the
-  // heap.
-  INLINE(void PushBlack(HeapObject* object)) {
+ // Push the (marked) object on the marking stack if there is room, otherwise
+  // mark the deque as overflowed and wait for a rescan of the heap.
+  INLINE(bool PushBlack(HeapObject* object)) {
     DCHECK(object->IsHeapObject());
     if (IsFull()) {
-      Marking::BlackToGrey(object);
-      MemoryChunk::IncrementLiveBytesFromGC(object, -object->Size());
       SetOverflowed();
+      return false;
     } else {
       array_[top_] = object;
       top_ = ((top_ + 1) & mask_);
+      return true;
     }
   }

@@ -248,16 +247,16 @@ class MarkingDeque {
     }
   }

-  INLINE(void UnshiftBlack(HeapObject* object)) {
+  INLINE(bool UnshiftBlack(HeapObject* object)) {
     DCHECK(object->IsHeapObject());
     DCHECK(Marking::IsBlack(Marking::MarkBitFrom(object)));
     if (IsFull()) {
-      Marking::BlackToGrey(object);
-      MemoryChunk::IncrementLiveBytesFromGC(object, -object->Size());
       SetOverflowed();
+      return false;
     } else {
       bottom_ = ((bottom_ - 1) & mask_);
       array_[bottom_] = object;
+      return true;
     }
   }

@@ -778,6 +777,9 @@ class MarkCompactCollector {

   void AfterMarking();

+ // Pushes a black object onto the marking stack and accounts for live bytes.
+  INLINE(void PushBlack(HeapObject* obj));
+
   // Marks the object black and pushes it on the marking stack.
   // This is for non-incremental marking only.
   INLINE(void MarkObject(HeapObject* obj, MarkBit mark_bit));
@@ -826,6 +828,14 @@ class MarkCompactCollector {
   // flag on the marking stack.
   void RefillMarkingDeque();

+ // Helper methods for refilling the marking stack by discovering grey objects
+  // on various pages of the heap. Used by {RefillMarkingDeque} only.
+  template <class T>
+  void DiscoverGreyObjectsWithIterator(T* it);
+  void DiscoverGreyObjectsOnPage(MemoryChunk* p);
+  void DiscoverGreyObjectsInSpace(PagedSpace* space);
+  void DiscoverGreyObjectsInNewSpace();
+
   // Callback function for telling whether the object *p is an unmarked
   // heap object.
   static bool IsUnmarkedHeapObject(Object** p);


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to