Fix processing of partially initialized JSWeakCollection.

R=hpayer@chromium.org
BUG=v8:2070
LOG=N

Review URL: https://codereview.chromium.org/300843009

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21563 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1a26ea6a
......@@ -2740,21 +2740,22 @@ void MarkCompactCollector::ProcessWeakCollections() {
GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_WEAKCOLLECTION_PROCESS);
Object* weak_collection_obj = encountered_weak_collections();
while (weak_collection_obj != Smi::FromInt(0)) {
ASSERT(MarkCompactCollector::IsMarked(
HeapObject::cast(weak_collection_obj)));
JSWeakCollection* weak_collection =
reinterpret_cast<JSWeakCollection*>(weak_collection_obj);
ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table());
Object** anchor = reinterpret_cast<Object**>(table->address());
for (int i = 0; i < table->Capacity(); i++) {
if (MarkCompactCollector::IsMarked(HeapObject::cast(table->KeyAt(i)))) {
Object** key_slot =
table->RawFieldOfElementAt(ObjectHashTable::EntryToIndex(i));
RecordSlot(anchor, key_slot, *key_slot);
Object** value_slot =
table->RawFieldOfElementAt(ObjectHashTable::EntryToValueIndex(i));
MarkCompactMarkingVisitor::MarkObjectByPointer(
this, anchor, value_slot);
ASSERT(MarkCompactCollector::IsMarked(weak_collection));
if (weak_collection->table()->IsHashTable()) {
ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table());
Object** anchor = reinterpret_cast<Object**>(table->address());
for (int i = 0; i < table->Capacity(); i++) {
if (MarkCompactCollector::IsMarked(HeapObject::cast(table->KeyAt(i)))) {
Object** key_slot =
table->RawFieldOfElementAt(ObjectHashTable::EntryToIndex(i));
RecordSlot(anchor, key_slot, *key_slot);
Object** value_slot =
table->RawFieldOfElementAt(ObjectHashTable::EntryToValueIndex(i));
MarkCompactMarkingVisitor::MarkObjectByPointer(
this, anchor, value_slot);
}
}
}
weak_collection_obj = weak_collection->next();
......@@ -2766,14 +2767,16 @@ void MarkCompactCollector::ClearWeakCollections() {
GCTracer::Scope gc_scope(tracer_, GCTracer::Scope::MC_WEAKCOLLECTION_CLEAR);
Object* weak_collection_obj = encountered_weak_collections();
while (weak_collection_obj != Smi::FromInt(0)) {
ASSERT(MarkCompactCollector::IsMarked(
HeapObject::cast(weak_collection_obj)));
JSWeakCollection* weak_collection =
reinterpret_cast<JSWeakCollection*>(weak_collection_obj);
ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table());
for (int i = 0; i < table->Capacity(); i++) {
if (!MarkCompactCollector::IsMarked(HeapObject::cast(table->KeyAt(i)))) {
table->RemoveEntry(i);
ASSERT(MarkCompactCollector::IsMarked(weak_collection));
if (weak_collection->table()->IsHashTable()) {
ObjectHashTable* table = ObjectHashTable::cast(weak_collection->table());
for (int i = 0; i < table->Capacity(); i++) {
HeapObject* key = HeapObject::cast(table->KeyAt(i));
if (!MarkCompactCollector::IsMarked(key)) {
table->RemoveEntry(i);
}
}
}
weak_collection_obj = weak_collection->next();
......
......@@ -404,7 +404,7 @@ void StaticMarkingVisitor<StaticVisitor>::VisitWeakCollection(
reinterpret_cast<JSWeakCollection*>(object);
MarkCompactCollector* collector = heap->mark_compact_collector();
// Enqueue weak map in linked list of encountered weak maps.
// Enqueue weak collection in linked list of encountered weak collections.
if (weak_collection->next() == heap->undefined_value()) {
weak_collection->set_next(collector->encountered_weak_collections());
collector->set_encountered_weak_collections(weak_collection);
......@@ -420,6 +420,7 @@ void StaticMarkingVisitor<StaticVisitor>::VisitWeakCollection(
STATIC_ASSERT(JSWeakCollection::kNextOffset + kPointerSize ==
JSWeakCollection::kSize);
// Partially initialized weak collection is enqueued, but table is ignored.
if (!weak_collection->table()->IsHashTable()) return;
// Mark the backing hash table without pushing it on the marking stack.
......
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