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 #include "src/isolate.h" | 5 #include "src/isolate.h" |
6 | 6 |
7 #ifndef V8_SNAPSHOT_H_ | 7 #ifndef V8_SNAPSHOT_H_ |
8 #define V8_SNAPSHOT_H_ | 8 #define V8_SNAPSHOT_H_ |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
11 namespace internal { | 11 namespace internal { |
12 | 12 |
13 class Snapshot : public AllStatic { | 13 class Snapshot : public AllStatic { |
14 public: | 14 public: |
| 15 class Metadata { |
| 16 public: |
| 17 explicit Metadata(uint32_t data = 0) : data_(data) {} |
| 18 bool embeds_script() { return EmbedsScriptBits::decode(data_); } |
| 19 void set_embeds_script(bool v) { |
| 20 data_ = EmbedsScriptBits::update(data_, v); |
| 21 } |
| 22 |
| 23 uint32_t& RawValue() { return data_; } |
| 24 |
| 25 private: |
| 26 class EmbedsScriptBits : public BitField<bool, 0, 1> {}; |
| 27 uint32_t data_; |
| 28 }; |
| 29 |
15 // Initialize the Isolate from the internal snapshot. Returns false if no | 30 // Initialize the Isolate from the internal snapshot. Returns false if no |
16 // snapshot could be found. | 31 // snapshot could be found. |
17 static bool Initialize(Isolate* isolate); | 32 static bool Initialize(Isolate* isolate); |
18 // Create a new context using the internal partial snapshot. | 33 // Create a new context using the internal partial snapshot. |
19 static MaybeHandle<Context> NewContextFromSnapshot( | 34 static MaybeHandle<Context> NewContextFromSnapshot( |
20 Isolate* isolate, Handle<FixedArray>* outdated_contexts_out); | 35 Isolate* isolate, Handle<FixedArray>* outdated_contexts_out); |
21 | 36 |
22 static bool HaveASnapshotToStartFrom(); | 37 static bool HaveASnapshotToStartFrom(); |
23 | 38 |
| 39 static bool EmbedsScript(); |
| 40 |
24 // To be implemented by the snapshot source. | 41 // To be implemented by the snapshot source. |
25 static const v8::StartupData SnapshotBlob(); | 42 static const v8::StartupData SnapshotBlob(); |
26 | 43 |
27 static v8::StartupData CreateSnapshotBlob( | 44 static v8::StartupData CreateSnapshotBlob( |
28 const Vector<const byte> startup_data, | 45 const Vector<const byte> startup_data, |
29 const Vector<const byte> context_data); | 46 const Vector<const byte> context_data, Metadata metadata); |
30 | 47 |
| 48 #ifdef DEBUG |
| 49 static bool SnapshotIsValid(v8::StartupData* snapshot_blob); |
| 50 #endif // DEBUG |
| 51 |
| 52 private: |
31 static Vector<const byte> ExtractStartupData(const v8::StartupData* data); | 53 static Vector<const byte> ExtractStartupData(const v8::StartupData* data); |
32 static Vector<const byte> ExtractContextData(const v8::StartupData* data); | 54 static Vector<const byte> ExtractContextData(const v8::StartupData* data); |
| 55 static Metadata ExtractMetadata(const v8::StartupData* data); |
33 | 56 |
34 private: | 57 static const int kMetadataOffset = 0; |
| 58 static const int kStartupLengthOffset = kMetadataOffset + kInt32Size; |
| 59 static const int kStartupDataOffset = kStartupLengthOffset + kInt32Size; |
| 60 |
| 61 static int ContextOffset(int startup_length) { |
| 62 return kStartupDataOffset + startup_length; |
| 63 } |
| 64 |
35 DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot); | 65 DISALLOW_IMPLICIT_CONSTRUCTORS(Snapshot); |
36 }; | 66 }; |
37 | 67 |
38 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 68 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
39 void SetSnapshotFromFile(StartupData* snapshot_blob); | 69 void SetSnapshotFromFile(StartupData* snapshot_blob); |
40 #endif | 70 #endif |
41 | 71 |
42 } } // namespace v8::internal | 72 } } // namespace v8::internal |
43 | 73 |
44 #endif // V8_SNAPSHOT_H_ | 74 #endif // V8_SNAPSHOT_H_ |
OLD | NEW |