diff --git a/src/snapshot/serializer.cc b/src/snapshot/serializer.cc index 4b0a7f1548..56d87b8916 100644 --- a/src/snapshot/serializer.cc +++ b/src/snapshot/serializer.cc @@ -116,11 +116,16 @@ void Serializer::VisitRootPointers(Root root, if (root == Root::kBuiltins || root == Root::kDispatchTable) return; for (Object** current = start; current < end; current++) { - if ((*current)->IsSmi()) { - PutSmi(Smi::cast(*current)); - } else { - SerializeObject(HeapObject::cast(*current), kPlain, kStartOfObject, 0); - } + SerializeRootObject(*current); + } +} + +template +void Serializer::SerializeRootObject(Object* object) { + if (object->IsSmi()) { + PutSmi(Smi::cast(object)); + } else { + SerializeObject(HeapObject::cast(object), kPlain, kStartOfObject, 0); } } diff --git a/src/snapshot/serializer.h b/src/snapshot/serializer.h index a382828f8c..9427cb6c78 100644 --- a/src/snapshot/serializer.h +++ b/src/snapshot/serializer.h @@ -170,6 +170,7 @@ class Serializer : public SerializerDeserializer { void VisitRootPointers(Root root, const char* description, Object** start, Object** end) override; + void SerializeRootObject(Object* object); void PutRoot(int index, HeapObject* object, HowToCode how, WhereToPoint where, int skip); diff --git a/src/snapshot/startup-serializer.cc b/src/snapshot/startup-serializer.cc index d985efb68c..9ad6cda5d1 100644 --- a/src/snapshot/startup-serializer.cc +++ b/src/snapshot/startup-serializer.cc @@ -132,24 +132,13 @@ void StartupSerializer::VisitRootPointers(Root root, const char* description, Object** start, Object** end) { if (start == isolate()->heap()->roots_array_start()) { // Serializing the root list needs special handling: - // - The first pass over the root list only serializes immortal immovables. - // - The second pass over the root list serializes the rest. // - Only root list elements that have been fully serialized can be - // referenced via as root by using kRootArray bytecodes. - int skip = 0; + // referenced using kRootArray bytecodes. for (Object** current = start; current < end; current++) { + SerializeRootObject(*current); int root_index = static_cast(current - start); - if ((*current)->IsSmi()) { - FlushSkip(skip); - PutSmi(Smi::cast(*current)); - } else { - SerializeObject(HeapObject::cast(*current), kPlain, kStartOfObject, - skip); - } root_has_been_serialized_.set(root_index); - skip = 0; } - FlushSkip(skip); } else { Serializer::VisitRootPointers(root, description, start, end); } diff --git a/src/snapshot/startup-serializer.h b/src/snapshot/startup-serializer.h index 190cc59529..cf334d10b2 100644 --- a/src/snapshot/startup-serializer.h +++ b/src/snapshot/startup-serializer.h @@ -18,10 +18,10 @@ class StartupSerializer : public Serializer<> { ~StartupSerializer() override; // Serialize the current state of the heap. The order is: - // 1) Immortal immovable roots - // 2) Remaining strong references. - // 3) Partial snapshot cache. - // 4) Weak references (e.g. the string table). + // 1) Strong roots + // 2) Builtins and bytecode handlers + // 3) Partial snapshot cache + // 4) Weak references (e.g. the string table) void SerializeStrongReferences(); void SerializeWeakReferencesAndDeferred();