Commit c7ba2f7f authored by jkummerow's avatar jkummerow Committed by Commit bot

[serializer] Move WeakFixedArray compaction to separate heap walk phase

This avoids discovering and compacting the same array repeatedly. No change in resulting snapshots intended.

R=yangguo@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#30177}
parent a38a573a
......@@ -394,6 +394,28 @@ StartupData V8::CreateSnapshotDataBlob(const char* custom_source) {
// If we don't do this then we end up with a stray root pointing at the
// context even after we have disposed of the context.
internal_isolate->heap()->CollectAllAvailableGarbage("mksnapshot");
// GC may have cleared weak cells, so compact any WeakFixedArrays
// found on the heap.
i::HeapIterator iterator(internal_isolate->heap(),
i::HeapIterator::kFilterUnreachable);
for (i::HeapObject* o = iterator.next(); o != NULL; o = iterator.next()) {
if (o->IsPrototypeInfo()) {
i::Object* prototype_users =
i::PrototypeInfo::cast(o)->prototype_users();
if (prototype_users->IsWeakFixedArray()) {
i::WeakFixedArray* array = i::WeakFixedArray::cast(prototype_users);
array->Compact<i::JSObject::PrototypeRegistryCompactionCallback>();
}
} else if (o->IsScript()) {
i::Object* shared_list = i::Script::cast(o)->shared_function_infos();
if (shared_list->IsWeakFixedArray()) {
i::WeakFixedArray* array = i::WeakFixedArray::cast(shared_list);
array->Compact<i::WeakFixedArray::NullCallback>();
}
}
}
i::Object* raw_context = *v8::Utils::OpenPersistent(context);
context.Reset();
......
......@@ -1923,38 +1923,10 @@ void Serializer::ObjectSerializer::Serialize() {
// We don't expect fillers.
DCHECK(!object_->IsFiller());
if (object_->IsPrototypeInfo()) {
Object* prototype_users = PrototypeInfo::cast(object_)->prototype_users();
if (prototype_users->IsWeakFixedArray()) {
WeakFixedArray* array = WeakFixedArray::cast(prototype_users);
array->Compact<JSObject::PrototypeRegistryCompactionCallback>();
}
}
// Compaction of a prototype users list can require the registered users
// to update their remembered slots. That doesn't work if those users
// have already been serialized themselves. So if this object is a
// registered user, compact its prototype's user list now.
if (object_->IsMap()) {
Map* map = Map::cast(object_);
if (map->is_prototype_map() && map->prototype_info()->IsPrototypeInfo() &&
PrototypeInfo::cast(map->prototype_info())->registry_slot() !=
PrototypeInfo::UNREGISTERED) {
JSObject* proto = JSObject::cast(map->prototype());
PrototypeInfo* info = PrototypeInfo::cast(proto->map()->prototype_info());
WeakFixedArray* array = WeakFixedArray::cast(info->prototype_users());
array->Compact<JSObject::PrototypeRegistryCompactionCallback>();
}
}
if (object_->IsScript()) {
// Clear cached line ends.
Object* undefined = serializer_->isolate()->heap()->undefined_value();
Script::cast(object_)->set_line_ends(undefined);
Object* shared_list = Script::cast(object_)->shared_function_infos();
if (shared_list->IsWeakFixedArray()) {
WeakFixedArray::cast(shared_list)
->Compact<WeakFixedArray::NullCallback>();
}
}
if (object_->IsExternalString()) {
......
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