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

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

Issue 792563002: Revert of Use same blob format for internal and external snapshots. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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 bool Snapshot::HaveASnapshotToStartFrom() { 17
18 return SnapshotBlob().data != NULL; 18 bool Snapshot::Initialize(Isolate* isolate) {
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;
19 } 33 }
20 34
21 35
22 const Vector<const byte> Snapshot::StartupSnapshot() { 36 bool Snapshot::HaveASnapshotToStartFrom() {
23 DCHECK(HaveASnapshotToStartFrom()); 37 return size_ != 0;
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;
60 } 38 }
61 39
62 40
63 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { 41 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) {
64 if (!HaveASnapshotToStartFrom()) return Handle<Context>(); 42 if (context_size_ == 0) return Handle<Context>();
65 43
66 SnapshotData snapshot_data(ContextSnapshot()); 44 SnapshotData snapshot_data(context_data_, context_size_);
67 Deserializer deserializer(&snapshot_data); 45 Deserializer deserializer(&snapshot_data);
68 Object* root; 46 Object* root;
69 deserializer.DeserializePartial(isolate, &root); 47 deserializer.DeserializePartial(isolate, &root);
70 CHECK(root->IsContext()); 48 CHECK(root->IsContext());
71 return Handle<Context>(Context::cast(root)); 49 return Handle<Context>(Context::cast(root));
72 } 50 }
73 51
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
74 } } // namespace v8::internal 63 } } // 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