1 // Copyright 2006-2008 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.
5 #ifndef V8_SNAPSHOT_SNAPSHOT_H_
6 #define V8_SNAPSHOT_SNAPSHOT_H_
8 #include "src/snapshot/serialize.h"
13 // Forward declarations.
15 class PartialSerializer;
16 class StartupSerializer;
18 class Snapshot : public AllStatic {
22 explicit Metadata(uint32_t data = 0) : data_(data) {}
23 bool embeds_script() { return EmbedsScriptBits::decode(data_); }
24 void set_embeds_script(bool v) {
25 data_ = EmbedsScriptBits::update(data_, v);
28 uint32_t& RawValue() { return data_; }
31 class EmbedsScriptBits : public BitField<bool, 0, 1> {};
35 // Initialize the Isolate from the internal snapshot. Returns false if no
36 // snapshot could be found.
37 static bool Initialize(Isolate* isolate);
38 // Create a new context using the internal partial snapshot.
39 static MaybeHandle<Context> NewContextFromSnapshot(
40 Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
41 Handle<FixedArray>* outdated_contexts_out);
43 static bool HaveASnapshotToStartFrom(Isolate* isolate);
45 static bool EmbedsScript(Isolate* isolate);
47 static uint32_t SizeOfFirstPage(Isolate* isolate, AllocationSpace space);
50 // To be implemented by the snapshot source.
51 static const v8::StartupData* DefaultSnapshotBlob();
53 static v8::StartupData CreateSnapshotBlob(
54 const StartupSerializer& startup_ser,
55 const PartialSerializer& context_ser, Snapshot::Metadata metadata);
58 static bool SnapshotIsValid(v8::StartupData* snapshot_blob);
62 static Vector<const byte> ExtractStartupData(const v8::StartupData* data);
63 static Vector<const byte> ExtractContextData(const v8::StartupData* data);
64 static Metadata ExtractMetadata(const v8::StartupData* data);
66 // Snapshot blob layout:
68 // [1 - 6] pre-calculated first page sizes for paged spaces
69 // [7] serialized start up data length
70 // ... serialized start up data
71 // ... serialized context data
73 static const int kNumPagedSpaces = LAST_PAGED_SPACE - FIRST_PAGED_SPACE + 1;
75 static const int kMetadataOffset = 0;
76 static const int kFirstPageSizesOffset = kMetadataOffset + kInt32Size;
77 static const int kStartupLengthOffset =
78 kFirstPageSizesOffset + kNumPagedSpaces * kInt32Size;
79 static const int kStartupDataOffset = kStartupLengthOffset + kInt32Size;
81 static int ContextOffset(int startup_length) {
82 return kStartupDataOffset + startup_length;
85 DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot);
88 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
89 void SetSnapshotFromFile(StartupData* snapshot_blob);
92 } } // namespace v8::internal
94 #endif // V8_SNAPSHOT_SNAPSHOT_H_