5 #ifndef V8_SNAPSHOT_SNAPSHOT_H_ 6 #define V8_SNAPSHOT_SNAPSHOT_H_ 8 #include "src/snapshot/partial-serializer.h" 9 #include "src/snapshot/startup-serializer.h" 11 #include "src/utils.h" 18 class PartialSerializer;
19 class StartupSerializer;
29 :
SerializedData(const_cast<byte*>(snapshot.begin()), snapshot.length()) {
32 std::vector<Reservation> Reservations()
const;
46 static const uint32_t kNumReservationsOffset =
47 kMagicNumberOffset + kUInt32Size;
48 static const uint32_t kPayloadLengthOffset =
49 kNumReservationsOffset + kUInt32Size;
50 static const uint32_t kHeaderSize = kPayloadLengthOffset + kUInt32Size;
59 static bool Initialize(
Isolate* isolate);
65 v8::DeserializeEmbedderFieldsCallback embedder_fields_deserializer);
69 static bool HasContextSnapshot(
Isolate* isolate,
size_t index);
70 static bool EmbedsScript(
Isolate* isolate);
73 static const v8::StartupData* DefaultSnapshotBlob();
75 static bool VerifyChecksum(
const v8::StartupData* data);
79 static v8::StartupData CreateSnapshotBlob(
82 const std::vector<SnapshotData*>& context_snapshots,
83 bool can_be_rehashed);
86 static bool SnapshotIsValid(
const v8::StartupData* snapshot_blob);
90 static uint32_t ExtractNumContexts(
const v8::StartupData* data);
91 static uint32_t ExtractContextOffset(
const v8::StartupData* data,
93 static bool ExtractRehashability(
const v8::StartupData* data);
99 static uint32_t GetHeaderValue(
const v8::StartupData* data,
uint32_t offset) {
100 return ReadLittleEndianValue<uint32_t>(
101 reinterpret_cast<Address>(data->data) + offset);
104 WriteLittleEndianValue(reinterpret_cast<Address>(data) + offset, value);
107 static void CheckVersion(
const v8::StartupData* data);
125 static const uint32_t kNumberOfContextsOffset = 0;
127 static const uint32_t kRehashabilityOffset =
128 kNumberOfContextsOffset + kUInt32Size;
129 static const uint32_t kChecksumPartAOffset =
130 kRehashabilityOffset + kUInt32Size;
131 static const uint32_t kChecksumPartBOffset =
132 kChecksumPartAOffset + kUInt32Size;
133 static const uint32_t kVersionStringOffset =
134 kChecksumPartBOffset + kUInt32Size;
135 static const uint32_t kVersionStringLength = 64;
136 static const uint32_t kReadOnlyOffsetOffset =
137 kVersionStringOffset + kVersionStringLength;
138 static const uint32_t kFirstContextOffsetOffset =
139 kReadOnlyOffsetOffset + kUInt32Size;
142 const uint32_t kChecksumStart = kVersionStringOffset;
144 reinterpret_cast<const byte*
>(data->data + kChecksumStart),
145 data->raw_size - kChecksumStart);
148 static uint32_t StartupSnapshotOffset(
int num_contexts) {
149 return POINTER_SIZE_ALIGN(kFirstContextOffsetOffset +
150 num_contexts * kInt32Size);
153 static uint32_t ContextSnapshotOffsetOffset(
int index) {
154 return kFirstContextOffsetOffset + index * kInt32Size;
157 DISALLOW_IMPLICIT_CONSTRUCTORS(
Snapshot);
160 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 161 void SetSnapshotFromFile(StartupData* snapshot_blob);
167 #endif // V8_SNAPSHOT_SNAPSHOT_H_