| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_SNAPSHOT_SNAPSHOT_H_ | 5 #ifndef V8_SNAPSHOT_SNAPSHOT_H_ |
| 6 #define V8_SNAPSHOT_SNAPSHOT_H_ | 6 #define V8_SNAPSHOT_SNAPSHOT_H_ |
| 7 | 7 |
| 8 #include "src/snapshot/partial-serializer.h" | 8 #include "src/snapshot/partial-serializer.h" |
| 9 #include "src/snapshot/startup-serializer.h" | 9 #include "src/snapshot/startup-serializer.h" |
| 10 | 10 |
| 11 namespace v8 { | 11 namespace v8 { |
| 12 namespace internal { | 12 namespace internal { |
| 13 | 13 |
| 14 // Forward declarations. | 14 // Forward declarations. |
| 15 class Isolate; | 15 class Isolate; |
| 16 class PartialSerializer; | 16 class PartialSerializer; |
| 17 class StartupSerializer; | 17 class StartupSerializer; |
| 18 | 18 |
| 19 // Wrapper around reservation sizes and the serialization payload. |
| 20 class SnapshotData : public SerializedData { |
| 21 public: |
| 22 // Used when producing. |
| 23 explicit SnapshotData(const Serializer* serializer); |
| 24 |
| 25 // Used when consuming. |
| 26 explicit SnapshotData(const Vector<const byte> snapshot) |
| 27 : SerializedData(const_cast<byte*>(snapshot.begin()), snapshot.length()) { |
| 28 CHECK(IsSane()); |
| 29 } |
| 30 |
| 31 Vector<const Reservation> Reservations() const; |
| 32 Vector<const byte> Payload() const; |
| 33 |
| 34 Vector<const byte> RawData() const { |
| 35 return Vector<const byte>(data_, size_); |
| 36 } |
| 37 |
| 38 private: |
| 39 bool IsSane(); |
| 40 |
| 41 // The data header consists of uint32_t-sized entries: |
| 42 // [0] magic number and external reference count |
| 43 // [1] version hash |
| 44 // [2] number of reservation size entries |
| 45 // [3] payload length |
| 46 // ... reservations |
| 47 // ... serialized payload |
| 48 static const int kCheckSumOffset = kMagicNumberOffset + kInt32Size; |
| 49 static const int kNumReservationsOffset = kCheckSumOffset + kInt32Size; |
| 50 static const int kPayloadLengthOffset = kNumReservationsOffset + kInt32Size; |
| 51 static const int kHeaderSize = kPayloadLengthOffset + kInt32Size; |
| 52 }; |
| 53 |
| 19 class Snapshot : public AllStatic { | 54 class Snapshot : public AllStatic { |
| 20 public: | 55 public: |
| 21 // Initialize the Isolate from the internal snapshot. Returns false if no | 56 // Initialize the Isolate from the internal snapshot. Returns false if no |
| 22 // snapshot could be found. | 57 // snapshot could be found. |
| 23 static bool Initialize(Isolate* isolate); | 58 static bool Initialize(Isolate* isolate); |
| 24 // Create a new context using the internal partial snapshot. | 59 // Create a new context using the internal partial snapshot. |
| 25 static MaybeHandle<Context> NewContextFromSnapshot( | 60 static MaybeHandle<Context> NewContextFromSnapshot( |
| 26 Isolate* isolate, Handle<JSGlobalProxy> global_proxy); | 61 Isolate* isolate, Handle<JSGlobalProxy> global_proxy, int context_index); |
| 27 | 62 |
| 28 static bool HaveASnapshotToStartFrom(Isolate* isolate); | 63 static bool HaveASnapshotToStartFrom(Isolate* isolate); |
| 29 | 64 |
| 30 static bool EmbedsScript(Isolate* isolate); | 65 static bool EmbedsScript(Isolate* isolate); |
| 31 | 66 |
| 32 static uint32_t SizeOfFirstPage(Isolate* isolate, AllocationSpace space); | 67 static uint32_t SizeOfFirstPage(Isolate* isolate, AllocationSpace space); |
| 33 | 68 |
| 34 | 69 |
| 35 // To be implemented by the snapshot source. | 70 // To be implemented by the snapshot source. |
| 36 static const v8::StartupData* DefaultSnapshotBlob(); | 71 static const v8::StartupData* DefaultSnapshotBlob(); |
| 37 | 72 |
| 38 static v8::StartupData CreateSnapshotBlob( | 73 static v8::StartupData CreateSnapshotBlob( |
| 39 const StartupSerializer* startup_serializer, | 74 const SnapshotData* startup_snapshot, |
| 40 const PartialSerializer* context_serializer); | 75 const List<SnapshotData*>* context_snapshots); |
| 41 | 76 |
| 42 #ifdef DEBUG | 77 #ifdef DEBUG |
| 43 static bool SnapshotIsValid(v8::StartupData* snapshot_blob); | 78 static bool SnapshotIsValid(v8::StartupData* snapshot_blob); |
| 44 #endif // DEBUG | 79 #endif // DEBUG |
| 45 | 80 |
| 46 private: | 81 private: |
| 82 static int ExtractNumContexts(const v8::StartupData* data); |
| 47 static Vector<const byte> ExtractStartupData(const v8::StartupData* data); | 83 static Vector<const byte> ExtractStartupData(const v8::StartupData* data); |
| 48 static Vector<const byte> ExtractContextData(const v8::StartupData* data); | 84 static Vector<const byte> ExtractContextData(const v8::StartupData* data, |
| 85 int index); |
| 49 | 86 |
| 50 // Snapshot blob layout: | 87 // Snapshot blob layout: |
| 51 // [0 - 5] pre-calculated first page sizes for paged spaces | 88 // [0 - 5] pre-calculated first page sizes for paged spaces |
| 52 // [6] serialized start up data length | 89 // [6] number of contexts N |
| 53 // ... serialized start up data | 90 // [7] offset to context 0 |
| 54 // ... serialized context data | 91 // [8] offset to context 1 |
| 92 // ... |
| 93 // ... offset to context N - 1 |
| 94 // ... startup snapshot data |
| 95 // ... context 0 snapshot data |
| 96 // ... context 1 snapshot data |
| 55 | 97 |
| 56 static const int kNumPagedSpaces = LAST_PAGED_SPACE - FIRST_PAGED_SPACE + 1; | 98 static const int kNumPagedSpaces = LAST_PAGED_SPACE - FIRST_PAGED_SPACE + 1; |
| 57 | 99 |
| 58 static const int kFirstPageSizesOffset = 0; | 100 static const int kFirstPageSizesOffset = 0; |
| 59 static const int kStartupLengthOffset = | 101 static const int kNumberOfContextsOffset = |
| 60 kFirstPageSizesOffset + kNumPagedSpaces * kInt32Size; | 102 kFirstPageSizesOffset + kNumPagedSpaces * kInt32Size; |
| 61 static const int kStartupDataOffset = kStartupLengthOffset + kInt32Size; | 103 static const int kFirstContextOffsetOffset = |
| 104 kNumberOfContextsOffset + kInt32Size; |
| 62 | 105 |
| 63 static int ContextOffset(int startup_length) { | 106 static int StartupSnapshotOffset(int num_contexts) { |
| 64 return kStartupDataOffset + startup_length; | 107 return kFirstContextOffsetOffset + num_contexts * kInt32Size; |
| 108 } |
| 109 |
| 110 static int ContextSnapshotOffsetOffset(int index) { |
| 111 return kFirstContextOffsetOffset + index * kInt32Size; |
| 65 } | 112 } |
| 66 | 113 |
| 67 DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot); | 114 DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot); |
| 68 }; | 115 }; |
| 69 | 116 |
| 70 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 117 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 71 void SetSnapshotFromFile(StartupData* snapshot_blob); | 118 void SetSnapshotFromFile(StartupData* snapshot_blob); |
| 72 #endif | 119 #endif |
| 73 | 120 |
| 74 // Wrapper around reservation sizes and the serialization payload. | |
| 75 class SnapshotData : public SerializedData { | |
| 76 public: | |
| 77 // Used when producing. | |
| 78 explicit SnapshotData(const Serializer* serializer); | |
| 79 | |
| 80 // Used when consuming. | |
| 81 explicit SnapshotData(const Vector<const byte> snapshot) | |
| 82 : SerializedData(const_cast<byte*>(snapshot.begin()), snapshot.length()) { | |
| 83 CHECK(IsSane()); | |
| 84 } | |
| 85 | |
| 86 Vector<const Reservation> Reservations() const; | |
| 87 Vector<const byte> Payload() const; | |
| 88 | |
| 89 Vector<const byte> RawData() const { | |
| 90 return Vector<const byte>(data_, size_); | |
| 91 } | |
| 92 | |
| 93 private: | |
| 94 bool IsSane(); | |
| 95 | |
| 96 // The data header consists of uint32_t-sized entries: | |
| 97 // [0] magic number and external reference count | |
| 98 // [1] version hash | |
| 99 // [2] number of reservation size entries | |
| 100 // [3] payload length | |
| 101 // ... reservations | |
| 102 // ... serialized payload | |
| 103 static const int kCheckSumOffset = kMagicNumberOffset + kInt32Size; | |
| 104 static const int kNumReservationsOffset = kCheckSumOffset + kInt32Size; | |
| 105 static const int kPayloadLengthOffset = kNumReservationsOffset + kInt32Size; | |
| 106 static const int kHeaderSize = kPayloadLengthOffset + kInt32Size; | |
| 107 }; | |
| 108 | |
| 109 } // namespace internal | 121 } // namespace internal |
| 110 } // namespace v8 | 122 } // namespace v8 |
| 111 | 123 |
| 112 #endif // V8_SNAPSHOT_SNAPSHOT_H_ | 124 #endif // V8_SNAPSHOT_SNAPSHOT_H_ |
| OLD | NEW |