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 #include "src/isolate.h"
6 #include "src/serialize.h"
14 class Snapshot : public AllStatic {
18 explicit Metadata(uint32_t data = 0) : data_(data) {}
19 bool embeds_script() { return EmbedsScriptBits::decode(data_); }
20 void set_embeds_script(bool v) {
21 data_ = EmbedsScriptBits::update(data_, v);
24 uint32_t& RawValue() { return data_; }
27 class EmbedsScriptBits : public BitField<bool, 0, 1> {};
31 // Initialize the Isolate from the internal snapshot. Returns false if no
32 // snapshot could be found.
33 static bool Initialize(Isolate* isolate);
34 // Create a new context using the internal partial snapshot.
35 static MaybeHandle<Context> NewContextFromSnapshot(
36 Isolate* isolate, Handle<JSGlobalProxy> global_proxy,
37 Handle<FixedArray>* outdated_contexts_out);
39 static bool HaveASnapshotToStartFrom();
41 static bool EmbedsScript();
43 static uint32_t SizeOfFirstPage(AllocationSpace space);
45 // To be implemented by the snapshot source.
46 static const v8::StartupData SnapshotBlob();
48 static v8::StartupData CreateSnapshotBlob(
49 const StartupSerializer& startup_ser,
50 const PartialSerializer& context_ser, Snapshot::Metadata metadata);
53 static bool SnapshotIsValid(v8::StartupData* snapshot_blob);
57 static Vector<const byte> ExtractStartupData(const v8::StartupData* data);
58 static Vector<const byte> ExtractContextData(const v8::StartupData* data);
59 static Metadata ExtractMetadata(const v8::StartupData* data);
61 // Snapshot blob layout:
63 // [1 - 6] pre-calculated first page sizes for paged spaces
64 // [7] serialized start up data length
65 // ... serialized start up data
66 // ... serialized context data
68 static const int kNumPagedSpaces = LAST_PAGED_SPACE - FIRST_PAGED_SPACE + 1;
70 static const int kMetadataOffset = 0;
71 static const int kFirstPageSizesOffset = kMetadataOffset + kInt32Size;
72 static const int kStartupLengthOffset =
73 kFirstPageSizesOffset + kNumPagedSpaces * kInt32Size;
74 static const int kStartupDataOffset = kStartupLengthOffset + kInt32Size;
76 static int ContextOffset(int startup_length) {
77 return kStartupDataOffset + startup_length;
80 DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot);
83 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
84 void SetSnapshotFromFile(StartupData* snapshot_blob);
87 } } // namespace v8::internal
89 #endif // V8_SNAPSHOT_H_