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