Revision: 21552
Author:   [email protected]
Date:     Wed May 28 08:35:16 2014 UTC
Log:      Make incremental marker post-process JSWeakCollection.

[email protected]
BUG=v8:2070
LOG=N

Review URL: https://codereview.chromium.org/301553003
http://code.google.com/p/v8/source/detail?r=21552

Modified:
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/incremental-marking.cc
 /branches/bleeding_edge/src/mark-compact.cc
 /branches/bleeding_edge/src/objects-visiting-inl.h
 /branches/bleeding_edge/src/objects-visiting.cc
 /branches/bleeding_edge/src/objects-visiting.h
 /branches/bleeding_edge/src/runtime.cc
 /branches/bleeding_edge/test/cctest/test-weakmaps.cc
 /branches/bleeding_edge/test/cctest/test-weaksets.cc

=======================================
--- /branches/bleeding_edge/src/heap.cc Tue May 27 07:57:22 2014 UTC
+++ /branches/bleeding_edge/src/heap.cc Wed May 28 08:35:16 2014 UTC
@@ -1850,11 +1850,7 @@
                     &ObjectEvacuationStrategy<POINTER_OBJECT>::
template VisitSpecialized<SharedFunctionInfo::kSize>);

-    table_.Register(kVisitJSWeakMap,
-                    &ObjectEvacuationStrategy<POINTER_OBJECT>::
-                    Visit);
-
-    table_.Register(kVisitJSWeakSet,
+    table_.Register(kVisitJSWeakCollection,
                     &ObjectEvacuationStrategy<POINTER_OBJECT>::
                     Visit);

=======================================
--- /branches/bleeding_edge/src/incremental-marking.cc Fri May 23 12:55:57 2014 UTC +++ /branches/bleeding_edge/src/incremental-marking.cc Wed May 28 08:35:16 2014 UTC
@@ -231,14 +231,6 @@
     }
     VisitNativeContext(map, context);
   }
-
-  static void VisitWeakCollection(Map* map, HeapObject* object) {
-    Heap* heap = map->GetHeap();
-    VisitPointers(heap,
-                  HeapObject::RawField(object,
- JSWeakCollection::kPropertiesOffset),
-                  HeapObject::RawField(object, JSWeakCollection::kSize));
-  }

   INLINE(static void VisitPointer(Heap* heap, Object** p)) {
     Object* obj = *p;
=======================================
--- /branches/bleeding_edge/src/mark-compact.cc Fri May 23 12:55:57 2014 UTC
+++ /branches/bleeding_edge/src/mark-compact.cc Wed May 28 08:35:16 2014 UTC
@@ -1471,44 +1471,6 @@
     }
     return true;
   }
-
-  static void VisitWeakCollection(Map* map, HeapObject* object) {
- MarkCompactCollector* collector = map->GetHeap()->mark_compact_collector();
-    JSWeakCollection* weak_collection =
-        reinterpret_cast<JSWeakCollection*>(object);
-
-    // Enqueue weak map in linked list of encountered weak maps.
-    if (weak_collection->next() == Smi::FromInt(0)) {
-      weak_collection->set_next(collector->encountered_weak_collections());
-      collector->set_encountered_weak_collections(weak_collection);
-    }
-
-    // Skip visiting the backing hash table containing the mappings.
- int object_size = JSWeakCollection::BodyDescriptor::SizeOf(map, object);
-    BodyVisitorBase<MarkCompactMarkingVisitor>::IteratePointers(
-        map->GetHeap(),
-        object,
-        JSWeakCollection::BodyDescriptor::kStartOffset,
-        JSWeakCollection::kTableOffset);
-    BodyVisitorBase<MarkCompactMarkingVisitor>::IteratePointers(
-        map->GetHeap(),
-        object,
-        JSWeakCollection::kTableOffset + kPointerSize,
-        object_size);
-
-    // Mark the backing hash table without pushing it on the marking stack.
-    Object* table_object = weak_collection->table();
-    if (!table_object->IsHashTable()) return;
-    WeakHashTable* table = WeakHashTable::cast(table_object);
-    Object** table_slot =
- HeapObject::RawField(weak_collection, JSWeakCollection::kTableOffset);
-    MarkBit table_mark = Marking::MarkBitFrom(table);
-    collector->RecordSlot(table_slot, table_slot, table);
-    if (!table_mark.Get()) collector->SetMark(table, table_mark);
- // Recording the map slot can be skipped, because maps are not compacted. - collector->MarkObject(table->map(), Marking::MarkBitFrom(table->map()));
-    ASSERT(MarkCompactCollector::IsMarked(table->map()));
-  }

  private:
   template<int id>
@@ -2816,7 +2778,7 @@
       }
     }
     weak_collection_obj = weak_collection->next();
-    weak_collection->set_next(Smi::FromInt(0));
+    weak_collection->set_next(heap()->undefined_value());
   }
   set_encountered_weak_collections(Smi::FromInt(0));
 }
=======================================
--- /branches/bleeding_edge/src/objects-visiting-inl.h Fri May 23 12:55:57 2014 UTC +++ /branches/bleeding_edge/src/objects-visiting-inl.h Wed May 28 08:35:16 2014 UTC
@@ -66,9 +66,7 @@

   table_.Register(kVisitFreeSpace, &VisitFreeSpace);

-  table_.Register(kVisitJSWeakMap, &JSObjectVisitor::Visit);
-
-  table_.Register(kVisitJSWeakSet, &JSObjectVisitor::Visit);
+  table_.Register(kVisitJSWeakCollection, &JSObjectVisitor::Visit);

   table_.Register(kVisitJSRegExp, &JSObjectVisitor::Visit);

@@ -182,9 +180,7 @@

   table_.Register(kVisitSeqTwoByteString, &DataObjectVisitor::Visit);

-  table_.Register(kVisitJSWeakMap, &StaticVisitor::VisitWeakCollection);
-
-  table_.Register(kVisitJSWeakSet, &StaticVisitor::VisitWeakCollection);
+  table_.Register(kVisitJSWeakCollection, &VisitWeakCollection);

   table_.Register(kVisitOddball,
                   &FixedBodyVisitor<StaticVisitor,
@@ -286,7 +282,6 @@
   // Monomorphic ICs are preserved when possible, but need to be flushed
   // when they might be keeping a Context alive, or when the heap is about
   // to be serialized.
-
   if (FLAG_cleanup_code_caches_at_gc && target->is_inline_cache_stub()
&& (target->ic_state() == MEGAMORPHIC || target->ic_state() == GENERIC || target->ic_state() == POLYMORPHIC || heap->flush_monomorphic_ics() ||
@@ -399,6 +394,40 @@
HeapObject::RawField(object, AllocationSite::kPointerFieldsBeginOffset), HeapObject::RawField(object, AllocationSite::kPointerFieldsEndOffset));
 }
+
+
+template<typename StaticVisitor>
+void StaticMarkingVisitor<StaticVisitor>::VisitWeakCollection(
+    Map* map, HeapObject* object) {
+  Heap* heap = map->GetHeap();
+  JSWeakCollection* weak_collection =
+      reinterpret_cast<JSWeakCollection*>(object);
+  MarkCompactCollector* collector = heap->mark_compact_collector();
+
+  // Enqueue weak map in linked list of encountered weak maps.
+  if (weak_collection->next() == heap->undefined_value()) {
+    weak_collection->set_next(collector->encountered_weak_collections());
+    collector->set_encountered_weak_collections(weak_collection);
+  }
+
+  // Skip visiting the backing hash table containing the mappings and the
+ // pointer to the other enqueued weak collections, both are post-processed.
+  StaticVisitor::VisitPointers(heap,
+      HeapObject::RawField(object, JSWeakCollection::kPropertiesOffset),
+      HeapObject::RawField(object, JSWeakCollection::kTableOffset));
+  STATIC_ASSERT(JSWeakCollection::kTableOffset + kPointerSize ==
+      JSWeakCollection::kNextOffset);
+  STATIC_ASSERT(JSWeakCollection::kNextOffset + kPointerSize ==
+      JSWeakCollection::kSize);
+
+  if (!weak_collection->table()->IsHashTable()) return;
+
+  // Mark the backing hash table without pushing it on the marking stack.
+ Object** slot = HeapObject::RawField(object, JSWeakCollection::kTableOffset);
+  HeapObject* obj = HeapObject::cast(*slot);
+  heap->mark_compact_collector()->RecordSlot(slot, slot, obj);
+  StaticVisitor::MarkObjectWithoutPush(heap, obj);
+}


 template<typename StaticVisitor>
=======================================
--- /branches/bleeding_edge/src/objects-visiting.cc Tue May 13 06:22:49 2014 UTC +++ /branches/bleeding_edge/src/objects-visiting.cc Wed May 28 08:35:16 2014 UTC
@@ -88,10 +88,8 @@
                                  JSMap::kSize);

     case JS_WEAK_MAP_TYPE:
-      return kVisitJSWeakMap;
-
     case JS_WEAK_SET_TYPE:
-      return kVisitJSWeakSet;
+      return kVisitJSWeakCollection;

     case JS_REGEXP_TYPE:
       return kVisitJSRegExp;
=======================================
--- /branches/bleeding_edge/src/objects-visiting.h Tue May 13 06:22:49 2014 UTC +++ /branches/bleeding_edge/src/objects-visiting.h Wed May 28 08:35:16 2014 UTC
@@ -73,8 +73,7 @@
   V(PropertyCell)             \
   V(SharedFunctionInfo)       \
   V(JSFunction)               \
-  V(JSWeakMap)                \
-  V(JSWeakSet)                \
+  V(JSWeakCollection)         \
   V(JSArrayBuffer)            \
   V(JSTypedArray)             \
   V(JSDataView)               \
@@ -382,7 +381,6 @@
   }

   INLINE(static void VisitPropertyCell(Map* map, HeapObject* object));
-  INLINE(static void VisitAllocationSite(Map* map, HeapObject* object));
   INLINE(static void VisitCodeEntry(Heap* heap, Address entry_address));
   INLINE(static void VisitEmbeddedPointer(Heap* heap, RelocInfo* rinfo));
   INLINE(static void VisitCell(Heap* heap, RelocInfo* rinfo));
@@ -404,6 +402,8 @@
   INLINE(static void VisitCode(Map* map, HeapObject* object));
INLINE(static void VisitSharedFunctionInfo(Map* map, HeapObject* object));
   INLINE(static void VisitConstantPoolArray(Map* map, HeapObject* object));
+  INLINE(static void VisitAllocationSite(Map* map, HeapObject* object));
+  INLINE(static void VisitWeakCollection(Map* map, HeapObject* object));
   INLINE(static void VisitJSFunction(Map* map, HeapObject* object));
   INLINE(static void VisitJSRegExp(Map* map, HeapObject* object));
   INLINE(static void VisitJSArrayBuffer(Map* map, HeapObject* object));
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Tue May 27 13:43:29 2014 UTC
+++ /branches/bleeding_edge/src/runtime.cc      Wed May 28 08:35:16 2014 UTC
@@ -1710,7 +1710,6 @@
   ASSERT(weak_collection->map()->inobject_properties() == 0);
   Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 0);
   weak_collection->set_table(*table);
-  weak_collection->set_next(Smi::FromInt(0));
   return weak_collection;
 }

=======================================
--- /branches/bleeding_edge/test/cctest/test-weakmaps.cc Fri May 9 16:39:33 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-weakmaps.cc Wed May 28 08:35:16 2014 UTC
@@ -46,10 +46,12 @@
   Handle<Map> map = factory->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize);
   Handle<JSObject> weakmap_obj = factory->NewJSObjectFromMap(map);
   Handle<JSWeakMap> weakmap(JSWeakMap::cast(*weakmap_obj));
-  // Do not use handles for the hash table, it would make entries strong.
-  Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 1);
-  weakmap->set_table(*table);
-  weakmap->set_next(Smi::FromInt(0));
+  // Do not leak handles for the hash table, it would make entries strong.
+  {
+    HandleScope scope(isolate);
+    Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 1);
+    weakmap->set_table(*table);
+  }
   return weakmap;
 }

=======================================
--- /branches/bleeding_edge/test/cctest/test-weaksets.cc Fri May 9 16:39:33 2014 UTC +++ /branches/bleeding_edge/test/cctest/test-weaksets.cc Wed May 28 08:35:16 2014 UTC
@@ -46,10 +46,12 @@
   Handle<Map> map = factory->NewMap(JS_WEAK_SET_TYPE, JSWeakSet::kSize);
   Handle<JSObject> weakset_obj = factory->NewJSObjectFromMap(map);
   Handle<JSWeakSet> weakset(JSWeakSet::cast(*weakset_obj));
-  // Do not use handles for the hash table, it would make entries strong.
-  Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 1);
-  weakset->set_table(*table);
-  weakset->set_next(Smi::FromInt(0));
+  // Do not leak handles for the hash table, it would make entries strong.
+  {
+    HandleScope scope(isolate);
+    Handle<ObjectHashTable> table = ObjectHashTable::New(isolate, 1);
+    weakset->set_table(*table);
+  }
   return weakset;
 }

--
--
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