5 #include "src/snapshot/read-only-serializer.h" 8 #include "src/code-tracer.h" 9 #include "src/global-handles.h" 10 #include "src/objects-inl.h" 11 #include "src/objects/slots.h" 12 #include "src/snapshot/startup-serializer.h" 13 #include "src/v8threads.h" 18 ReadOnlySerializer::ReadOnlySerializer(Isolate* isolate)
19 : RootsSerializer(isolate, RootIndex::kFirstReadOnlyRoot) {
20 STATIC_ASSERT(RootIndex::kFirstReadOnlyRoot == RootIndex::kFirstRoot);
23 ReadOnlySerializer::~ReadOnlySerializer() {
24 OutputStatistics(
"ReadOnlySerializer");
27 void ReadOnlySerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
28 WhereToPoint where_to_point,
30 CHECK(isolate()->heap()->read_only_space()->Contains(obj));
32 if (SerializeHotObject(obj, how_to_code, where_to_point, skip))
return;
33 if (IsRootAndHasBeenSerialized(obj) &&
34 SerializeRoot(obj, how_to_code, where_to_point, skip)) {
37 if (SerializeBackReference(obj, how_to_code, where_to_point, skip))
return;
41 CheckRehashability(obj);
44 ObjectSerializer object_serializer(
this, obj, &sink_, how_to_code,
46 object_serializer.Serialize();
49 void ReadOnlySerializer::SerializeReadOnlyRoots() {
51 CHECK_NULL(isolate()->thread_manager()->FirstThreadStateInUse());
53 CHECK(isolate()->handle_scope_implementer()->blocks()->empty());
55 ReadOnlyRoots(isolate()).Iterate(
this);
58 void ReadOnlySerializer::FinalizeSerialization() {
62 Object* undefined = ReadOnlyRoots(isolate()).undefined_value();
63 VisitRootPointer(Root::kReadOnlyObjectCache,
nullptr, ObjectSlot(&undefined));
64 SerializeDeferredObjects();
68 bool ReadOnlySerializer::MustBeDeferred(HeapObject*
object) {
69 if (root_has_been_serialized(RootIndex::kFreeSpaceMap) &&
70 root_has_been_serialized(RootIndex::kOnePointerFillerMap) &&
71 root_has_been_serialized(RootIndex::kTwoPointerFillerMap)) {
81 return !
object->IsMap();
84 bool ReadOnlySerializer::SerializeUsingReadOnlyObjectCache(
85 SnapshotByteSink* sink, HeapObject* obj, HowToCode how_to_code,
86 WhereToPoint where_to_point,
int skip) {
87 if (!isolate()->heap()->read_only_space()->Contains(obj))
return false;
91 int cache_index = SerializeInObjectCache(obj);
94 FlushSkip(sink, skip);
95 sink->Put(kReadOnlyObjectCache + how_to_code + where_to_point,
96 "ReadOnlyObjectCache");
97 sink->PutInt(cache_index,
"read_only_object_cache_index");