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
parent f10204b5
......@@ -1850,11 +1850,7 @@ class ScavengingVisitor : public StaticVisitorBase {
&ObjectEvacuationStrategy<POINTER_OBJECT>::
template VisitSpecialized<SharedFunctionInfo::kSize>);
table_.Register(kVisitJSWeakMap,
&ObjectEvacuationStrategy<POINTER_OBJECT>::
Visit);
table_.Register(kVisitJSWeakSet,
table_.Register(kVisitJSWeakCollection,
&ObjectEvacuationStrategy<POINTER_OBJECT>::
Visit);
......
......@@ -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()) {
......
......@@ -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<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>
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));
}
......
......@@ -66,9 +66,7 @@ void StaticNewSpaceVisitor<StaticVisitor>::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<StaticVisitor>::Initialize() {
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 @@ void StaticMarkingVisitor<StaticVisitor>::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() ||
......@@ -401,6 +396,40 @@ void StaticMarkingVisitor<StaticVisitor>::VisitAllocationSite(
}
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>
void StaticMarkingVisitor<StaticVisitor>::VisitCode(
Map* map, HeapObject* object) {
......
......@@ -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;
......
......@@ -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));
......
......@@ -1710,7 +1710,6 @@ static Handle<JSWeakCollection> WeakCollectionInitialize(
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;
}
......
......@@ -46,10 +46,12 @@ static Handle<JSWeakMap> AllocateJSWeakMap(Isolate* isolate) {
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;
}
......
......@@ -46,10 +46,12 @@ static Handle<JSWeakSet> AllocateJSWeakSet(Isolate* isolate) {
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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment