From: mstarzinger@chromium.org Date: Wed, 28 May 2014 08:35:16 +0000 (+0000) Subject: Make incremental marker post-process JSWeakCollection. X-Git-Tag: upstream/4.7.83~8920 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3812677b42ecb515b48098eaa8f3e814739c83bb;p=platform%2Fupstream%2Fv8.git Make incremental marker post-process JSWeakCollection. R=hpayer@chromium.org BUG=v8:2070 LOG=N Review URL: https://codereview.chromium.org/301553003 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21552 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/heap.cc b/src/heap.cc index b7a5918..ff7a9ff 100644 --- a/src/heap.cc +++ b/src/heap.cc @@ -1850,11 +1850,7 @@ class ScavengingVisitor : public StaticVisitorBase { &ObjectEvacuationStrategy:: template VisitSpecialized); - table_.Register(kVisitJSWeakMap, - &ObjectEvacuationStrategy:: - Visit); - - table_.Register(kVisitJSWeakSet, + table_.Register(kVisitJSWeakCollection, &ObjectEvacuationStrategy:: Visit); diff --git a/src/incremental-marking.cc b/src/incremental-marking.cc index aec0c37..bf5d8cc 100644 --- a/src/incremental-marking.cc +++ b/src/incremental-marking.cc @@ -232,14 +232,6 @@ class IncrementalMarkingMarkingVisitor 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; if (obj->IsHeapObject()) { diff --git a/src/mark-compact.cc b/src/mark-compact.cc index 6b3b3db..7e7a343 100644 --- a/src/mark-compact.cc +++ b/src/mark-compact.cc @@ -1472,44 +1472,6 @@ class MarkCompactMarkingVisitor return true; } - static void VisitWeakCollection(Map* map, HeapObject* object) { - MarkCompactCollector* collector = map->GetHeap()->mark_compact_collector(); - JSWeakCollection* weak_collection = - reinterpret_cast(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::IteratePointers( - map->GetHeap(), - object, - JSWeakCollection::BodyDescriptor::kStartOffset, - JSWeakCollection::kTableOffset); - BodyVisitorBase::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 static inline void TrackObjectStatsAndVisit(Map* map, HeapObject* obj); @@ -2816,7 +2778,7 @@ void MarkCompactCollector::ClearWeakCollections() { } } 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)); } diff --git a/src/objects-visiting-inl.h b/src/objects-visiting-inl.h index 7ed0e4a..65c93a2 100644 --- a/src/objects-visiting-inl.h +++ b/src/objects-visiting-inl.h @@ -66,9 +66,7 @@ void StaticNewSpaceVisitor::Initialize() { 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 @@ void StaticMarkingVisitor::Initialize() { table_.Register(kVisitSeqTwoByteString, &DataObjectVisitor::Visit); - table_.Register(kVisitJSWeakMap, &StaticVisitor::VisitWeakCollection); - - table_.Register(kVisitJSWeakSet, &StaticVisitor::VisitWeakCollection); + table_.Register(kVisitJSWeakCollection, &VisitWeakCollection); table_.Register(kVisitOddball, &FixedBodyVisitor::VisitCodeTarget( // 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() || @@ -402,6 +397,40 @@ void StaticMarkingVisitor::VisitAllocationSite( template +void StaticMarkingVisitor::VisitWeakCollection( + Map* map, HeapObject* object) { + Heap* heap = map->GetHeap(); + JSWeakCollection* weak_collection = + reinterpret_cast(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 void StaticMarkingVisitor::VisitCode( Map* map, HeapObject* object) { Heap* heap = map->GetHeap(); diff --git a/src/objects-visiting.cc b/src/objects-visiting.cc index aea8a09..708f8cf 100644 --- a/src/objects-visiting.cc +++ b/src/objects-visiting.cc @@ -88,10 +88,8 @@ StaticVisitorBase::VisitorId StaticVisitorBase::GetVisitorId( JSMap::kSize); case JS_WEAK_MAP_TYPE: - return kVisitJSWeakMap; - case JS_WEAK_SET_TYPE: - return kVisitJSWeakSet; + return kVisitJSWeakCollection; case JS_REGEXP_TYPE: return kVisitJSRegExp; diff --git a/src/objects-visiting.h b/src/objects-visiting.h index d9ab02a..a4eb384 100644 --- a/src/objects-visiting.h +++ b/src/objects-visiting.h @@ -73,8 +73,7 @@ class StaticVisitorBase : public AllStatic { V(PropertyCell) \ V(SharedFunctionInfo) \ V(JSFunction) \ - V(JSWeakMap) \ - V(JSWeakSet) \ + V(JSWeakCollection) \ V(JSArrayBuffer) \ V(JSTypedArray) \ V(JSDataView) \ @@ -382,7 +381,6 @@ class StaticMarkingVisitor : public StaticVisitorBase { } 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 @@ class StaticMarkingVisitor : public StaticVisitorBase { 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)); diff --git a/src/runtime.cc b/src/runtime.cc index 0bff90b..351a4ca 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -1710,7 +1710,6 @@ static Handle WeakCollectionInitialize( ASSERT(weak_collection->map()->inobject_properties() == 0); Handle table = ObjectHashTable::New(isolate, 0); weak_collection->set_table(*table); - weak_collection->set_next(Smi::FromInt(0)); return weak_collection; } diff --git a/test/cctest/test-weakmaps.cc b/test/cctest/test-weakmaps.cc index 369dae5..2684deb 100644 --- a/test/cctest/test-weakmaps.cc +++ b/test/cctest/test-weakmaps.cc @@ -46,10 +46,12 @@ static Handle AllocateJSWeakMap(Isolate* isolate) { Handle map = factory->NewMap(JS_WEAK_MAP_TYPE, JSWeakMap::kSize); Handle weakmap_obj = factory->NewJSObjectFromMap(map); Handle weakmap(JSWeakMap::cast(*weakmap_obj)); - // Do not use handles for the hash table, it would make entries strong. - Handle 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 table = ObjectHashTable::New(isolate, 1); + weakmap->set_table(*table); + } return weakmap; } diff --git a/test/cctest/test-weaksets.cc b/test/cctest/test-weaksets.cc index a83e16b..0e1ef17 100644 --- a/test/cctest/test-weaksets.cc +++ b/test/cctest/test-weaksets.cc @@ -46,10 +46,12 @@ static Handle AllocateJSWeakSet(Isolate* isolate) { Handle map = factory->NewMap(JS_WEAK_SET_TYPE, JSWeakSet::kSize); Handle weakset_obj = factory->NewJSObjectFromMap(map); Handle weakset(JSWeakSet::cast(*weakset_obj)); - // Do not use handles for the hash table, it would make entries strong. - Handle 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 table = ObjectHashTable::New(isolate, 1); + weakset->set_table(*table); + } return weakset; }