1 // Copyright 2017 the V8 project authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #ifndef V8_SNAPSHOT_BUILTIN_SERIALIZER_H_ 6 #define V8_SNAPSHOT_BUILTIN_SERIALIZER_H_ 7 8 #include "src/interpreter/interpreter.h" 9 #include "src/snapshot/builtin-serializer-allocator.h" 10 #include "src/snapshot/builtin-snapshot-utils.h" 11 #include "src/snapshot/serializer.h" 12 13 namespace v8 { 14 namespace internal { 15 16 class StartupSerializer; 17 18 // Responsible for serializing builtin and bytecode handler objects during 19 // startup snapshot creation into a dedicated area of the snapshot. 20 // See snapshot.h for documentation of the snapshot layout. 21 class BuiltinSerializer : public Serializer<BuiltinSerializerAllocator> { 22 using BSU = BuiltinSnapshotUtils; 23 24 public: 25 BuiltinSerializer(Isolate* isolate, StartupSerializer* startup_serializer); 26 ~BuiltinSerializer() override; 27 28 void SerializeBuiltinsAndHandlers(); 29 30 private: 31 void VisitRootPointers(Root root, const char* description, Object** start, 32 Object** end) override; 33 34 void SerializeBuiltin(Code* code); 35 void SerializeHandler(Code* code); 36 void SerializeObject(HeapObject* o, HowToCode how_to_code, 37 WhereToPoint where_to_point, int skip) override; 38 39 void SetBuiltinOffset(int builtin_id, uint32_t offset); 40 void SetHandlerOffset(interpreter::Bytecode bytecode, 41 interpreter::OperandScale operand_scale, 42 uint32_t offset); 43 44 // The startup serializer is needed for access to the partial snapshot cache, 45 // which is used to serialize things like embedded constants. 46 StartupSerializer* startup_serializer_; 47 48 // Stores the starting offset, within the serialized data, of each code 49 // object. This is later packed into the builtin snapshot, and used by the 50 // builtin deserializer to deserialize individual builtins and bytecode 51 // handlers. 52 // 53 // Indices [kFirstBuiltinIndex, kFirstBuiltinIndex + kNumberOfBuiltins[: 54 // Builtin offsets. 55 // Indices [kFirstHandlerIndex, kFirstHandlerIndex + kNumberOfHandlers[: 56 // Bytecode handler offsets. 57 uint32_t code_offsets_[BuiltinSnapshotUtils::kNumberOfCodeObjects]; 58 59 DISALLOW_COPY_AND_ASSIGN(BuiltinSerializer); 60 }; 61 62 } // namespace internal 63 } // namespace v8 64 65 #endif // V8_SNAPSHOT_BUILTIN_SERIALIZER_H_ 66