Index: src/snapshot/serialize.cc |
diff --git a/src/snapshot/serialize.cc b/src/snapshot/serialize.cc |
index 7410c3b393c1a931d991f7f0d1304a75e430e022..66da378617571ccb915303bb828cd01fe0e8448d 100644 |
--- a/src/snapshot/serialize.cc |
+++ b/src/snapshot/serialize.cc |
@@ -1851,6 +1851,28 @@ void Serializer::ObjectSerializer::SerializeExternalString() { |
} |
+// Clear and later restore the next link in the weak cell, if the object is one. |
+class UnlinkWeakCellScope { |
+ public: |
+ explicit UnlinkWeakCellScope(HeapObject* object) : weak_cell_(NULL) { |
+ if (object->IsWeakCell()) { |
+ weak_cell_ = WeakCell::cast(object); |
+ next_ = weak_cell_->next(); |
+ weak_cell_->clear_next(object->GetHeap()); |
+ } |
+ } |
+ |
+ ~UnlinkWeakCellScope() { |
+ if (weak_cell_) weak_cell_->set_next(next_, UPDATE_WEAK_WRITE_BARRIER); |
+ } |
+ |
+ private: |
+ WeakCell* weak_cell_; |
+ Object* next_; |
+ DisallowHeapAllocation no_gc_; |
+}; |
+ |
+ |
void Serializer::ObjectSerializer::Serialize() { |
if (FLAG_trace_serializer) { |
PrintF(" Encoding heap object: "); |
@@ -1910,6 +1932,8 @@ void Serializer::ObjectSerializer::Serialize() { |
return; |
} |
+ UnlinkWeakCellScope unlink_weak_cell(object_); |
+ |
object_->IterateBody(map->instance_type(), size, this); |
OutputRawData(object_->address() + size); |
} |
@@ -1934,6 +1958,8 @@ void Serializer::ObjectSerializer::SerializeDeferred() { |
serializer_->PutBackReference(object_, reference); |
sink_->PutInt(size >> kPointerSizeLog2, "deferred object size"); |
+ UnlinkWeakCellScope unlink_weak_cell(object_); |
+ |
object_->IterateBody(map->instance_type(), size, this); |
OutputRawData(object_->address() + size); |
} |