Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Side by Side Diff: src/snapshot-external.cc

Issue 787033002: Use same blob format for internal and external snapshots. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comments Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/snapshot-empty.cc ('k') | src/snapshot-source-sink.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 // Used for building with external snapshots. 5 // Used for building with external snapshots.
6 6
7 #include "src/snapshot.h" 7 #include "src/snapshot.h"
8 8
9 #include "src/serialize.h" 9 #include "src/serialize.h"
10 #include "src/snapshot-source-sink.h" 10 #include "src/snapshot-source-sink.h"
11 #include "src/v8.h" // for V8::Initialize 11 #include "src/v8.h" // for V8::Initialize
12 12
13
14 #ifndef V8_USE_EXTERNAL_STARTUP_DATA
15 #error snapshot-external.cc is used only for the external snapshot build.
16 #endif // V8_USE_EXTERNAL_STARTUP_DATA
17
18
13 namespace v8 { 19 namespace v8 {
14 namespace internal { 20 namespace internal {
15 21
16 22 static v8::StartupData* external_startup_blob = NULL;
17 struct SnapshotImpl {
18 public:
19 const byte* data;
20 int size;
21 const byte* context_data;
22 int context_size;
23 };
24
25
26 static SnapshotImpl* snapshot_impl_ = NULL;
27
28
29 bool Snapshot::HaveASnapshotToStartFrom() {
30 return snapshot_impl_ != NULL;
31 }
32
33
34 bool Snapshot::Initialize(Isolate* isolate) {
35 if (!HaveASnapshotToStartFrom()) return false;
36 base::ElapsedTimer timer;
37 if (FLAG_profile_deserialization) timer.Start();
38
39 SnapshotData snapshot_data(snapshot_impl_->data, snapshot_impl_->size);
40 Deserializer deserializer(&snapshot_data);
41 bool success = isolate->Init(&deserializer);
42 if (FLAG_profile_deserialization) {
43 double ms = timer.Elapsed().InMillisecondsF();
44 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
45 }
46 return success;
47 }
48
49
50 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
51 if (!HaveASnapshotToStartFrom()) return Handle<Context>();
52
53 SnapshotData snapshot_data(snapshot_impl_->context_data,
54 snapshot_impl_->context_size);
55 Deserializer deserializer(&snapshot_data);
56 Object* root;
57 deserializer.DeserializePartial(isolate, &root);
58 CHECK(root->IsContext());
59 return Handle<Context>(Context::cast(root));
60 }
61
62 23
63 void SetSnapshotFromFile(StartupData* snapshot_blob) { 24 void SetSnapshotFromFile(StartupData* snapshot_blob) {
64 DCHECK(snapshot_blob); 25 DCHECK(snapshot_blob);
65 DCHECK(snapshot_blob->data); 26 DCHECK(snapshot_blob->data);
66 DCHECK(snapshot_blob->raw_size > 0); 27 DCHECK(snapshot_blob->raw_size > 0);
67 DCHECK(!snapshot_impl_); 28 DCHECK(!external_startup_blob);
29 external_startup_blob = snapshot_blob;
68 30
69 snapshot_impl_ = new SnapshotImpl; 31 // Validate snapshot blob.
70 SnapshotByteSource source(reinterpret_cast<const byte*>(snapshot_blob->data), 32 DCHECK(!Snapshot::StartupSnapshot().is_empty());
71 snapshot_blob->raw_size); 33 DCHECK(!Snapshot::ContextSnapshot().is_empty());
72 bool success = source.GetBlob(&snapshot_impl_->data, 34 }
73 &snapshot_impl_->size); 35
74 success &= source.GetBlob(&snapshot_impl_->context_data, 36
75 &snapshot_impl_->context_size); 37 const v8::StartupData Snapshot::SnapshotBlob() {
76 DCHECK(success); 38 return *external_startup_blob;
77 } 39 }
78 40
79 } } // namespace v8::internal 41 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/snapshot-empty.cc ('k') | src/snapshot-source-sink.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698