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 // 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 namespace v8 { | 13 namespace v8 { |
14 namespace internal { | 14 namespace internal { |
15 | 15 |
16 | 16 |
17 struct SnapshotImpl { | 17 struct SnapshotImpl { |
18 public: | 18 public: |
19 const byte* data; | 19 const byte* data; |
20 int size; | 20 int size; |
21 int new_space_used; | |
22 int pointer_space_used; | |
23 int data_space_used; | |
24 int code_space_used; | |
25 int map_space_used; | |
26 int cell_space_used; | |
27 int property_cell_space_used; | |
28 int lo_space_used; | |
29 | |
30 const byte* context_data; | 21 const byte* context_data; |
31 int context_size; | 22 int context_size; |
32 int context_new_space_used; | |
33 int context_pointer_space_used; | |
34 int context_data_space_used; | |
35 int context_code_space_used; | |
36 int context_map_space_used; | |
37 int context_cell_space_used; | |
38 int context_property_cell_space_used; | |
39 int context_lo_space_used; | |
40 }; | 23 }; |
41 | 24 |
42 | 25 |
43 static SnapshotImpl* snapshot_impl_ = NULL; | 26 static SnapshotImpl* snapshot_impl_ = NULL; |
44 | 27 |
45 | 28 |
46 bool Snapshot::HaveASnapshotToStartFrom() { | 29 bool Snapshot::HaveASnapshotToStartFrom() { |
47 return snapshot_impl_ != NULL; | 30 return snapshot_impl_ != NULL; |
48 } | 31 } |
49 | 32 |
50 | 33 |
51 bool Snapshot::Initialize(Isolate* isolate) { | 34 bool Snapshot::Initialize(Isolate* isolate) { |
52 if (!HaveASnapshotToStartFrom()) | 35 if (!HaveASnapshotToStartFrom()) return false; |
53 return false; | 36 base::ElapsedTimer timer; |
| 37 if (FLAG_profile_deserialization) timer.Start(); |
54 | 38 |
55 base::ElapsedTimer timer; | 39 |
56 if (FLAG_profile_deserialization) { | 40 SnapshotData snapshot_data(snapshot_impl_->data, snapshot_impl_->size); |
57 timer.Start(); | 41 Deserializer deserializer(&snapshot_data); |
58 } | |
59 SnapshotByteSource source(snapshot_impl_->data, snapshot_impl_->size); | |
60 Deserializer deserializer(&source); | |
61 deserializer.AddReservation(NEW_SPACE, snapshot_impl_->new_space_used); | |
62 deserializer.AddReservation(OLD_POINTER_SPACE, | |
63 snapshot_impl_->pointer_space_used); | |
64 deserializer.AddReservation(OLD_DATA_SPACE, snapshot_impl_->data_space_used); | |
65 deserializer.AddReservation(CODE_SPACE, snapshot_impl_->code_space_used); | |
66 deserializer.AddReservation(MAP_SPACE, snapshot_impl_->map_space_used); | |
67 deserializer.AddReservation(CELL_SPACE, snapshot_impl_->cell_space_used); | |
68 deserializer.AddReservation(PROPERTY_CELL_SPACE, | |
69 snapshot_impl_->property_cell_space_used); | |
70 deserializer.AddReservation(LO_SPACE, snapshot_impl_->lo_space_used); | |
71 bool success = isolate->Init(&deserializer); | 42 bool success = isolate->Init(&deserializer); |
72 if (FLAG_profile_deserialization) { | 43 if (FLAG_profile_deserialization) { |
73 double ms = timer.Elapsed().InMillisecondsF(); | 44 double ms = timer.Elapsed().InMillisecondsF(); |
74 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms); | 45 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms); |
75 } | 46 } |
76 return success; | 47 return success; |
77 } | 48 } |
78 | 49 |
79 | 50 |
80 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { | 51 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { |
81 if (!HaveASnapshotToStartFrom()) | 52 if (!HaveASnapshotToStartFrom()) return Handle<Context>(); |
82 return Handle<Context>(); | |
83 | 53 |
84 SnapshotByteSource source(snapshot_impl_->context_data, | 54 SnapshotData snapshot_data(snapshot_impl_->context_data, |
85 snapshot_impl_->context_size); | 55 snapshot_impl_->context_size); |
86 Deserializer deserializer(&source); | 56 Deserializer deserializer(&snapshot_data); |
87 deserializer.AddReservation(NEW_SPACE, | |
88 snapshot_impl_->context_new_space_used); | |
89 deserializer.AddReservation(OLD_POINTER_SPACE, | |
90 snapshot_impl_->context_pointer_space_used); | |
91 deserializer.AddReservation(OLD_DATA_SPACE, | |
92 snapshot_impl_->context_data_space_used); | |
93 deserializer.AddReservation(CODE_SPACE, | |
94 snapshot_impl_->context_code_space_used); | |
95 deserializer.AddReservation(MAP_SPACE, | |
96 snapshot_impl_->context_map_space_used); | |
97 deserializer.AddReservation(CELL_SPACE, | |
98 snapshot_impl_->context_cell_space_used); | |
99 deserializer.AddReservation(PROPERTY_CELL_SPACE, | |
100 snapshot_impl_->context_property_cell_space_used); | |
101 deserializer.AddReservation(LO_SPACE, snapshot_impl_->context_lo_space_used); | |
102 Object* root; | 57 Object* root; |
103 deserializer.DeserializePartial(isolate, &root); | 58 deserializer.DeserializePartial(isolate, &root); |
104 CHECK(root->IsContext()); | 59 CHECK(root->IsContext()); |
105 return Handle<Context>(Context::cast(root)); | 60 return Handle<Context>(Context::cast(root)); |
106 } | 61 } |
107 | 62 |
108 | 63 |
109 void SetSnapshotFromFile(StartupData* snapshot_blob) { | 64 void SetSnapshotFromFile(StartupData* snapshot_blob) { |
110 DCHECK(snapshot_blob); | 65 DCHECK(snapshot_blob); |
111 DCHECK(snapshot_blob->data); | 66 DCHECK(snapshot_blob->data); |
112 DCHECK(snapshot_blob->raw_size > 0); | 67 DCHECK(snapshot_blob->raw_size > 0); |
113 DCHECK(!snapshot_impl_); | 68 DCHECK(!snapshot_impl_); |
114 | 69 |
115 snapshot_impl_ = new SnapshotImpl; | 70 snapshot_impl_ = new SnapshotImpl; |
116 SnapshotByteSource source(reinterpret_cast<const byte*>(snapshot_blob->data), | 71 SnapshotByteSource source(reinterpret_cast<const byte*>(snapshot_blob->data), |
117 snapshot_blob->raw_size); | 72 snapshot_blob->raw_size); |
118 | |
119 bool success = source.GetBlob(&snapshot_impl_->data, | 73 bool success = source.GetBlob(&snapshot_impl_->data, |
120 &snapshot_impl_->size); | 74 &snapshot_impl_->size); |
121 snapshot_impl_->new_space_used = source.GetInt(); | |
122 snapshot_impl_->pointer_space_used = source.GetInt(); | |
123 snapshot_impl_->data_space_used = source.GetInt(); | |
124 snapshot_impl_->code_space_used = source.GetInt(); | |
125 snapshot_impl_->map_space_used = source.GetInt(); | |
126 snapshot_impl_->cell_space_used = source.GetInt(); | |
127 snapshot_impl_->property_cell_space_used = source.GetInt(); | |
128 snapshot_impl_->lo_space_used = source.GetInt(); | |
129 | |
130 success &= source.GetBlob(&snapshot_impl_->context_data, | 75 success &= source.GetBlob(&snapshot_impl_->context_data, |
131 &snapshot_impl_->context_size); | 76 &snapshot_impl_->context_size); |
132 snapshot_impl_->context_new_space_used = source.GetInt(); | |
133 snapshot_impl_->context_pointer_space_used = source.GetInt(); | |
134 snapshot_impl_->context_data_space_used = source.GetInt(); | |
135 snapshot_impl_->context_code_space_used = source.GetInt(); | |
136 snapshot_impl_->context_map_space_used = source.GetInt(); | |
137 snapshot_impl_->context_cell_space_used = source.GetInt(); | |
138 snapshot_impl_->context_property_cell_space_used = source.GetInt(); | |
139 snapshot_impl_->context_lo_space_used = source.GetInt(); | |
140 | |
141 DCHECK(success); | 77 DCHECK(success); |
142 } | 78 } |
143 | 79 |
144 } } // namespace v8::internal | 80 } } // namespace v8::internal |
OLD | NEW |