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

Side by Side Diff: src/snapshot-common.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.h ('k') | src/snapshot-empty.cc » ('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 // The common functionality when building with or without snapshots. 5 // The common functionality when building with or without snapshots.
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/base/platform/platform.h" 10 #include "src/base/platform/platform.h"
11 #include "src/serialize.h" 11 #include "src/serialize.h"
12 #include "src/snapshot.h" 12 #include "src/snapshot.h"
13 13
14 namespace v8 { 14 namespace v8 {
15 namespace internal { 15 namespace internal {
16 16
17 17 bool Snapshot::HaveASnapshotToStartFrom() {
18 bool Snapshot::Initialize(Isolate* isolate) { 18 return SnapshotBlob().data != NULL;
19 if (size_ > 0) {
20 base::ElapsedTimer timer;
21 if (FLAG_profile_deserialization) timer.Start();
22
23 SnapshotData snapshot_data(data_, size_);
24 Deserializer deserializer(&snapshot_data);
25 bool success = isolate->Init(&deserializer);
26 if (FLAG_profile_deserialization) {
27 double ms = timer.Elapsed().InMillisecondsF();
28 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
29 }
30 return success;
31 }
32 return false;
33 } 19 }
34 20
35 21
36 bool Snapshot::HaveASnapshotToStartFrom() { 22 const Vector<const byte> Snapshot::StartupSnapshot() {
37 return size_ != 0; 23 DCHECK(HaveASnapshotToStartFrom());
24 const v8::StartupData blob = SnapshotBlob();
25 SnapshotByteSource source(blob.data, blob.raw_size);
26 const byte* data;
27 int length;
28 bool success = source.GetBlob(&data, &length);
29 CHECK(success);
30 return Vector<const byte>(data, length);
31 }
32
33
34 const Vector<const byte> Snapshot::ContextSnapshot() {
35 DCHECK(HaveASnapshotToStartFrom());
36 const v8::StartupData blob = SnapshotBlob();
37 SnapshotByteSource source(blob.data, blob.raw_size);
38 const byte* data;
39 int length;
40 bool success = source.GetBlob(&data, &length);
41 success &= source.GetBlob(&data, &length);
42 CHECK(success);
43 return Vector<const byte>(data, length);
44 }
45
46
47 bool Snapshot::Initialize(Isolate* isolate) {
48 if (!HaveASnapshotToStartFrom()) return false;
49 base::ElapsedTimer timer;
50 if (FLAG_profile_deserialization) timer.Start();
51
52 SnapshotData snapshot_data(StartupSnapshot());
53 Deserializer deserializer(&snapshot_data);
54 bool success = isolate->Init(&deserializer);
55 if (FLAG_profile_deserialization) {
56 double ms = timer.Elapsed().InMillisecondsF();
57 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms);
58 }
59 return success;
38 } 60 }
39 61
40 62
41 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { 63 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
42 if (context_size_ == 0) return Handle<Context>(); 64 if (!HaveASnapshotToStartFrom()) return Handle<Context>();
43 65
44 SnapshotData snapshot_data(context_data_, context_size_); 66 SnapshotData snapshot_data(ContextSnapshot());
45 Deserializer deserializer(&snapshot_data); 67 Deserializer deserializer(&snapshot_data);
46 Object* root; 68 Object* root;
47 deserializer.DeserializePartial(isolate, &root); 69 deserializer.DeserializePartial(isolate, &root);
48 CHECK(root->IsContext()); 70 CHECK(root->IsContext());
49 return Handle<Context>(Context::cast(root)); 71 return Handle<Context>(Context::cast(root));
50 } 72 }
51 73
52
53 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
54 // Dummy implementations of Set*FromFile(..) APIs.
55 //
56 // These are meant for use with snapshot-external.cc. Should this file
57 // be compiled with those options we just supply these dummy implementations
58 // below. This happens when compiling the mksnapshot utility.
59 void SetNativesFromFile(StartupData* data) { CHECK(false); }
60 void SetSnapshotFromFile(StartupData* data) { CHECK(false); }
61 #endif // V8_USE_EXTERNAL_STARTUP_DATA
62
63 } } // namespace v8::internal 74 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/snapshot.h ('k') | src/snapshot-empty.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698