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 |
21 const byte* context_data; | 30 const byte* context_data; |
22 int context_size; | 31 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; |
23 }; | 40 }; |
24 | 41 |
25 | 42 |
26 static SnapshotImpl* snapshot_impl_ = NULL; | 43 static SnapshotImpl* snapshot_impl_ = NULL; |
27 | 44 |
28 | 45 |
29 bool Snapshot::HaveASnapshotToStartFrom() { | 46 bool Snapshot::HaveASnapshotToStartFrom() { |
30 return snapshot_impl_ != NULL; | 47 return snapshot_impl_ != NULL; |
31 } | 48 } |
32 | 49 |
33 | 50 |
34 bool Snapshot::Initialize(Isolate* isolate) { | 51 bool Snapshot::Initialize(Isolate* isolate) { |
35 if (!HaveASnapshotToStartFrom()) return false; | 52 if (!HaveASnapshotToStartFrom()) |
| 53 return false; |
| 54 |
36 base::ElapsedTimer timer; | 55 base::ElapsedTimer timer; |
37 if (FLAG_profile_deserialization) timer.Start(); | 56 if (FLAG_profile_deserialization) { |
38 | 57 timer.Start(); |
39 | 58 } |
40 SnapshotData snapshot_data(snapshot_impl_->data, snapshot_impl_->size); | 59 SnapshotByteSource source(snapshot_impl_->data, snapshot_impl_->size); |
41 Deserializer deserializer(&snapshot_data); | 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); |
42 bool success = isolate->Init(&deserializer); | 71 bool success = isolate->Init(&deserializer); |
43 if (FLAG_profile_deserialization) { | 72 if (FLAG_profile_deserialization) { |
44 double ms = timer.Elapsed().InMillisecondsF(); | 73 double ms = timer.Elapsed().InMillisecondsF(); |
45 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms); | 74 PrintF("[Snapshot loading and deserialization took %0.3f ms]\n", ms); |
46 } | 75 } |
47 return success; | 76 return success; |
48 } | 77 } |
49 | 78 |
50 | 79 |
51 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { | 80 Handle<Context> Snapshot::NewContextFromSnapshot(Isolate* isolate) { |
52 if (!HaveASnapshotToStartFrom()) return Handle<Context>(); | 81 if (!HaveASnapshotToStartFrom()) |
| 82 return Handle<Context>(); |
53 | 83 |
54 SnapshotData snapshot_data(snapshot_impl_->context_data, | 84 SnapshotByteSource source(snapshot_impl_->context_data, |
55 snapshot_impl_->context_size); | 85 snapshot_impl_->context_size); |
56 Deserializer deserializer(&snapshot_data); | 86 Deserializer deserializer(&source); |
| 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); |
57 Object* root; | 102 Object* root; |
58 deserializer.DeserializePartial(isolate, &root); | 103 deserializer.DeserializePartial(isolate, &root); |
59 CHECK(root->IsContext()); | 104 CHECK(root->IsContext()); |
60 return Handle<Context>(Context::cast(root)); | 105 return Handle<Context>(Context::cast(root)); |
61 } | 106 } |
62 | 107 |
63 | 108 |
64 void SetSnapshotFromFile(StartupData* snapshot_blob) { | 109 void SetSnapshotFromFile(StartupData* snapshot_blob) { |
65 DCHECK(snapshot_blob); | 110 DCHECK(snapshot_blob); |
66 DCHECK(snapshot_blob->data); | 111 DCHECK(snapshot_blob->data); |
67 DCHECK(snapshot_blob->raw_size > 0); | 112 DCHECK(snapshot_blob->raw_size > 0); |
68 DCHECK(!snapshot_impl_); | 113 DCHECK(!snapshot_impl_); |
69 | 114 |
70 snapshot_impl_ = new SnapshotImpl; | 115 snapshot_impl_ = new SnapshotImpl; |
71 SnapshotByteSource source(reinterpret_cast<const byte*>(snapshot_blob->data), | 116 SnapshotByteSource source(reinterpret_cast<const byte*>(snapshot_blob->data), |
72 snapshot_blob->raw_size); | 117 snapshot_blob->raw_size); |
| 118 |
73 bool success = source.GetBlob(&snapshot_impl_->data, | 119 bool success = source.GetBlob(&snapshot_impl_->data, |
74 &snapshot_impl_->size); | 120 &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 |
75 success &= source.GetBlob(&snapshot_impl_->context_data, | 130 success &= source.GetBlob(&snapshot_impl_->context_data, |
76 &snapshot_impl_->context_size); | 131 &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 |
77 DCHECK(success); | 141 DCHECK(success); |
78 } | 142 } |
79 | 143 |
80 } } // namespace v8::internal | 144 } } // namespace v8::internal |
OLD | NEW |