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 // 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 bool Snapshot::HaveASnapshotToStartFrom() { |
18 return SnapshotBlob().data != NULL; | 18 return SnapshotBlob().data != NULL; |
19 } | 19 } |
20 | 20 |
21 | 21 |
22 bool Snapshot::Initialize(Isolate* isolate) { | 22 bool Snapshot::Initialize(Isolate* isolate) { |
23 if (!HaveASnapshotToStartFrom()) return false; | 23 if (!HaveASnapshotToStartFrom()) return false; |
24 base::ElapsedTimer timer; | 24 base::ElapsedTimer timer; |
25 if (FLAG_profile_deserialization) timer.Start(); | 25 if (FLAG_profile_deserialization) timer.Start(); |
26 | 26 |
27 const v8::StartupData blob = SnapshotBlob(); | 27 const v8::StartupData blob = SnapshotBlob(); |
28 SnapshotData snapshot_data(ExtractStartupData(&blob)); | 28 Vector<const byte> startup_data = ExtractStartupData(&blob); |
| 29 SnapshotData snapshot_data(startup_data); |
29 Deserializer deserializer(&snapshot_data); | 30 Deserializer deserializer(&snapshot_data); |
30 bool success = isolate->Init(&deserializer); | 31 bool success = isolate->Init(&deserializer); |
31 if (FLAG_profile_deserialization) { | 32 if (FLAG_profile_deserialization) { |
32 double ms = timer.Elapsed().InMillisecondsF(); | 33 double ms = timer.Elapsed().InMillisecondsF(); |
33 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms); | 34 int bytes = startup_data.length(); |
| 35 PrintF("[Deserializing isolate (%d bytes) took %0.3f ms]\n", bytes, ms); |
34 } | 36 } |
35 return success; | 37 return success; |
36 } | 38 } |
37 | 39 |
38 | 40 |
39 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { | 41 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { |
40 if (!HaveASnapshotToStartFrom()) return Handle<Context>(); | 42 if (!HaveASnapshotToStartFrom()) return Handle<Context>(); |
| 43 base::ElapsedTimer timer; |
| 44 if (FLAG_profile_deserialization) timer.Start(); |
41 | 45 |
42 const v8::StartupData blob = SnapshotBlob(); | 46 const v8::StartupData blob = SnapshotBlob(); |
43 SnapshotData snapshot_data(ExtractContextData(&blob)); | 47 Vector<const byte> context_data = ExtractContextData(&blob); |
| 48 SnapshotData snapshot_data(context_data); |
44 Deserializer deserializer(&snapshot_data); | 49 Deserializer deserializer(&snapshot_data); |
45 Object* root; | 50 Object* root; |
46 deserializer.DeserializePartial(isolate, &root); | 51 deserializer.DeserializePartial(isolate, &root); |
47 CHECK(root->IsContext()); | 52 CHECK(root->IsContext()); |
| 53 if (FLAG_profile_deserialization) { |
| 54 double ms = timer.Elapsed().InMillisecondsF(); |
| 55 int bytes = context_data.length(); |
| 56 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms); |
| 57 } |
48 return Handle<Context>(Context::cast(root)); | 58 return Handle<Context>(Context::cast(root)); |
49 } | 59 } |
50 | 60 |
51 | 61 |
52 v8::StartupData Snapshot::CreateSnapshotBlob( | 62 v8::StartupData Snapshot::CreateSnapshotBlob( |
53 const Vector<const byte> startup_data, | 63 const Vector<const byte> startup_data, |
54 const Vector<const byte> context_data) { | 64 const Vector<const byte> context_data) { |
55 int startup_length = startup_data.length(); | 65 int startup_length = startup_data.length(); |
56 int context_length = context_data.length(); | 66 int context_length = context_data.length(); |
57 int context_offset = kIntSize + startup_length; | 67 int context_offset = kIntSize + startup_length; |
(...skipping 24 matching lines...) Expand all Loading... |
82 int startup_length; | 92 int startup_length; |
83 memcpy(&startup_length, data->data, kIntSize); | 93 memcpy(&startup_length, data->data, kIntSize); |
84 int context_offset = kIntSize + startup_length; | 94 int context_offset = kIntSize + startup_length; |
85 const byte* context_data = | 95 const byte* context_data = |
86 reinterpret_cast<const byte*>(data->data + context_offset); | 96 reinterpret_cast<const byte*>(data->data + context_offset); |
87 DCHECK_LT(context_offset, data->raw_size); | 97 DCHECK_LT(context_offset, data->raw_size); |
88 int context_length = data->raw_size - context_offset; | 98 int context_length = data->raw_size - context_offset; |
89 return Vector<const byte>(context_data, context_length); | 99 return Vector<const byte>(context_data, context_length); |
90 } | 100 } |
91 } } // namespace v8::internal | 101 } } // namespace v8::internal |
OLD | NEW |