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/snapshot/snapshot.h" | 7 #include "src/snapshot/snapshot.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" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 if (!maybe_context.ToHandle(&result)) return MaybeHandle<Context>(); | 79 if (!maybe_context.ToHandle(&result)) return MaybeHandle<Context>(); |
80 CHECK(result->IsContext()); | 80 CHECK(result->IsContext()); |
81 if (FLAG_profile_deserialization) { | 81 if (FLAG_profile_deserialization) { |
82 double ms = timer.Elapsed().InMillisecondsF(); | 82 double ms = timer.Elapsed().InMillisecondsF(); |
83 int bytes = context_data.length(); | 83 int bytes = context_data.length(); |
84 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms); | 84 PrintF("[Deserializing context (%d bytes) took %0.3f ms]\n", bytes, ms); |
85 } | 85 } |
86 return Handle<Context>::cast(result); | 86 return Handle<Context>::cast(result); |
87 } | 87 } |
88 | 88 |
89 void CalculateFirstPageSizes(const SnapshotData& startup_snapshot, | 89 void CalculateFirstPageSizes(const SnapshotData* startup_snapshot, |
90 const SnapshotData& context_snapshot, | 90 const SnapshotData* context_snapshot, |
91 uint32_t* sizes_out) { | 91 uint32_t* sizes_out) { |
92 Vector<const SerializedData::Reservation> startup_reservations = | 92 Vector<const SerializedData::Reservation> startup_reservations = |
93 startup_snapshot.Reservations(); | 93 startup_snapshot->Reservations(); |
94 Vector<const SerializedData::Reservation> context_reservations = | 94 Vector<const SerializedData::Reservation> context_reservations = |
95 context_snapshot.Reservations(); | 95 context_snapshot->Reservations(); |
96 int startup_index = 0; | 96 int startup_index = 0; |
97 int context_index = 0; | 97 int context_index = 0; |
98 | 98 |
99 if (FLAG_profile_deserialization) { | 99 if (FLAG_profile_deserialization) { |
100 int startup_total = 0; | 100 int startup_total = 0; |
101 int context_total = 0; | 101 int context_total = 0; |
102 for (auto& reservation : startup_reservations) { | 102 for (const auto& reservation : startup_reservations) { |
103 startup_total += reservation.chunk_size(); | 103 startup_total += reservation.chunk_size(); |
104 } | 104 } |
105 for (auto& reservation : context_reservations) { | 105 for (const auto& reservation : context_reservations) { |
106 context_total += reservation.chunk_size(); | 106 context_total += reservation.chunk_size(); |
107 } | 107 } |
108 PrintF( | 108 PrintF( |
109 "Deserialization will reserve:\n" | 109 "Deserialization will reserve:\n" |
110 "%10d bytes per isolate\n" | 110 "%10d bytes per isolate\n" |
111 "%10d bytes per context\n", | 111 "%10d bytes per context\n", |
112 startup_total, context_total); | 112 startup_total, context_total); |
113 } | 113 } |
114 | 114 |
115 for (int space = 0; space < i::Serializer::kNumberOfSpaces; space++) { | 115 for (int space = 0; space < i::Serializer::kNumberOfSpaces; space++) { |
(...skipping 29 matching lines...) Expand all Loading... |
145 } | 145 } |
146 startup_index++; | 146 startup_index++; |
147 context_index++; | 147 context_index++; |
148 } | 148 } |
149 | 149 |
150 DCHECK_EQ(startup_reservations.length(), startup_index); | 150 DCHECK_EQ(startup_reservations.length(), startup_index); |
151 DCHECK_EQ(context_reservations.length(), context_index); | 151 DCHECK_EQ(context_reservations.length(), context_index); |
152 } | 152 } |
153 | 153 |
154 v8::StartupData Snapshot::CreateSnapshotBlob( | 154 v8::StartupData Snapshot::CreateSnapshotBlob( |
155 const i::StartupSerializer& startup_ser, | 155 const StartupSerializer* startup_serializer, |
156 const i::PartialSerializer& context_ser) { | 156 const PartialSerializer* context_serializer) { |
157 SnapshotData startup_snapshot(startup_ser); | 157 SnapshotData startup_snapshot(startup_serializer); |
158 SnapshotData context_snapshot(context_ser); | 158 SnapshotData context_snapshot(context_serializer); |
159 Vector<const byte> startup_data = startup_snapshot.RawData(); | 159 Vector<const byte> startup_data = startup_snapshot.RawData(); |
160 Vector<const byte> context_data = context_snapshot.RawData(); | 160 Vector<const byte> context_data = context_snapshot.RawData(); |
161 | 161 |
162 uint32_t first_page_sizes[kNumPagedSpaces]; | 162 uint32_t first_page_sizes[kNumPagedSpaces]; |
163 | 163 |
164 CalculateFirstPageSizes(startup_snapshot, context_snapshot, first_page_sizes); | 164 CalculateFirstPageSizes(&startup_snapshot, &context_snapshot, |
| 165 first_page_sizes); |
165 | 166 |
166 int startup_length = startup_data.length(); | 167 int startup_length = startup_data.length(); |
167 int context_length = context_data.length(); | 168 int context_length = context_data.length(); |
168 int context_offset = ContextOffset(startup_length); | 169 int context_offset = ContextOffset(startup_length); |
169 | 170 |
170 int length = context_offset + context_length; | 171 int length = context_offset + context_length; |
171 char* data = new char[length]; | 172 char* data = new char[length]; |
172 | 173 |
173 memcpy(data + kFirstPageSizesOffset, first_page_sizes, | 174 memcpy(data + kFirstPageSizesOffset, first_page_sizes, |
174 kNumPagedSpaces * kInt32Size); | 175 kNumPagedSpaces * kInt32Size); |
(...skipping 28 matching lines...) Expand all Loading... |
203 int startup_length; | 204 int startup_length; |
204 memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize); | 205 memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize); |
205 int context_offset = ContextOffset(startup_length); | 206 int context_offset = ContextOffset(startup_length); |
206 const byte* context_data = | 207 const byte* context_data = |
207 reinterpret_cast<const byte*>(data->data + context_offset); | 208 reinterpret_cast<const byte*>(data->data + context_offset); |
208 DCHECK_LT(context_offset, data->raw_size); | 209 DCHECK_LT(context_offset, data->raw_size); |
209 int context_length = data->raw_size - context_offset; | 210 int context_length = data->raw_size - context_offset; |
210 return Vector<const byte>(context_data, context_length); | 211 return Vector<const byte>(context_data, context_length); |
211 } | 212 } |
212 | 213 |
213 SnapshotData::SnapshotData(const Serializer& ser) { | 214 SnapshotData::SnapshotData(const Serializer* serializer) { |
214 DisallowHeapAllocation no_gc; | 215 DisallowHeapAllocation no_gc; |
215 List<Reservation> reservations; | 216 List<Reservation> reservations; |
216 ser.EncodeReservations(&reservations); | 217 serializer->EncodeReservations(&reservations); |
217 const List<byte>& payload = ser.sink()->data(); | 218 const List<byte>* payload = serializer->sink()->data(); |
218 | 219 |
219 // Calculate sizes. | 220 // Calculate sizes. |
220 int reservation_size = reservations.length() * kInt32Size; | 221 int reservation_size = reservations.length() * kInt32Size; |
221 int size = kHeaderSize + reservation_size + payload.length(); | 222 int size = kHeaderSize + reservation_size + payload->length(); |
222 | 223 |
223 // Allocate backing store and create result data. | 224 // Allocate backing store and create result data. |
224 AllocateData(size); | 225 AllocateData(size); |
225 | 226 |
226 // Set header values. | 227 // Set header values. |
227 SetMagicNumber(ser.isolate()); | 228 SetMagicNumber(serializer->isolate()); |
228 SetHeaderValue(kCheckSumOffset, Version::Hash()); | 229 SetHeaderValue(kCheckSumOffset, Version::Hash()); |
229 SetHeaderValue(kNumReservationsOffset, reservations.length()); | 230 SetHeaderValue(kNumReservationsOffset, reservations.length()); |
230 SetHeaderValue(kPayloadLengthOffset, payload.length()); | 231 SetHeaderValue(kPayloadLengthOffset, payload->length()); |
231 | 232 |
232 // Copy reservation chunk sizes. | 233 // Copy reservation chunk sizes. |
233 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), | 234 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), |
234 reservation_size); | 235 reservation_size); |
235 | 236 |
236 // Copy serialized data. | 237 // Copy serialized data. |
237 CopyBytes(data_ + kHeaderSize + reservation_size, payload.begin(), | 238 CopyBytes(data_ + kHeaderSize + reservation_size, payload->begin(), |
238 static_cast<size_t>(payload.length())); | 239 static_cast<size_t>(payload->length())); |
239 } | 240 } |
240 | 241 |
241 bool SnapshotData::IsSane() { | 242 bool SnapshotData::IsSane() { |
242 return GetHeaderValue(kCheckSumOffset) == Version::Hash(); | 243 return GetHeaderValue(kCheckSumOffset) == Version::Hash(); |
243 } | 244 } |
244 | 245 |
245 Vector<const SerializedData::Reservation> SnapshotData::Reservations() const { | 246 Vector<const SerializedData::Reservation> SnapshotData::Reservations() const { |
246 return Vector<const Reservation>( | 247 return Vector<const Reservation>( |
247 reinterpret_cast<const Reservation*>(data_ + kHeaderSize), | 248 reinterpret_cast<const Reservation*>(data_ + kHeaderSize), |
248 GetHeaderValue(kNumReservationsOffset)); | 249 GetHeaderValue(kNumReservationsOffset)); |
249 } | 250 } |
250 | 251 |
251 Vector<const byte> SnapshotData::Payload() const { | 252 Vector<const byte> SnapshotData::Payload() const { |
252 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; | 253 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; |
253 const byte* payload = data_ + kHeaderSize + reservations_size; | 254 const byte* payload = data_ + kHeaderSize + reservations_size; |
254 int length = GetHeaderValue(kPayloadLengthOffset); | 255 int length = GetHeaderValue(kPayloadLengthOffset); |
255 DCHECK_EQ(data_ + size_, payload + length); | 256 DCHECK_EQ(data_ + size_, payload + length); |
256 return Vector<const byte>(payload, length); | 257 return Vector<const byte>(payload, length); |
257 } | 258 } |
258 | 259 |
259 } // namespace internal | 260 } // namespace internal |
260 } // namespace v8 | 261 } // namespace v8 |
OLD | NEW |