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" |
11 #include "src/full-codegen/full-codegen.h" | 11 #include "src/full-codegen/full-codegen.h" |
| 12 #include "src/snapshot/deserializer.h" |
| 13 #include "src/snapshot/snapshot-source-sink.h" |
| 14 #include "src/version.h" |
12 | 15 |
13 namespace v8 { | 16 namespace v8 { |
14 namespace internal { | 17 namespace internal { |
15 | 18 |
16 #ifdef DEBUG | 19 #ifdef DEBUG |
17 bool Snapshot::SnapshotIsValid(v8::StartupData* snapshot_blob) { | 20 bool Snapshot::SnapshotIsValid(v8::StartupData* snapshot_blob) { |
18 return !Snapshot::ExtractStartupData(snapshot_blob).is_empty() && | 21 return !Snapshot::ExtractStartupData(snapshot_blob).is_empty() && |
19 !Snapshot::ExtractContextData(snapshot_blob).is_empty(); | 22 !Snapshot::ExtractContextData(snapshot_blob).is_empty(); |
20 } | 23 } |
21 #endif // DEBUG | 24 #endif // DEBUG |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
221 DCHECK_LT(kIntSize, data->raw_size); | 224 DCHECK_LT(kIntSize, data->raw_size); |
222 int startup_length; | 225 int startup_length; |
223 memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize); | 226 memcpy(&startup_length, data->data + kStartupLengthOffset, kIntSize); |
224 int context_offset = ContextOffset(startup_length); | 227 int context_offset = ContextOffset(startup_length); |
225 const byte* context_data = | 228 const byte* context_data = |
226 reinterpret_cast<const byte*>(data->data + context_offset); | 229 reinterpret_cast<const byte*>(data->data + context_offset); |
227 DCHECK_LT(context_offset, data->raw_size); | 230 DCHECK_LT(context_offset, data->raw_size); |
228 int context_length = data->raw_size - context_offset; | 231 int context_length = data->raw_size - context_offset; |
229 return Vector<const byte>(context_data, context_length); | 232 return Vector<const byte>(context_data, context_length); |
230 } | 233 } |
| 234 |
| 235 SnapshotData::SnapshotData(const Serializer& ser) { |
| 236 DisallowHeapAllocation no_gc; |
| 237 List<Reservation> reservations; |
| 238 ser.EncodeReservations(&reservations); |
| 239 const List<byte>& payload = ser.sink()->data(); |
| 240 |
| 241 // Calculate sizes. |
| 242 int reservation_size = reservations.length() * kInt32Size; |
| 243 int size = kHeaderSize + reservation_size + payload.length(); |
| 244 |
| 245 // Allocate backing store and create result data. |
| 246 AllocateData(size); |
| 247 |
| 248 // Set header values. |
| 249 SetMagicNumber(ser.isolate()); |
| 250 SetHeaderValue(kCheckSumOffset, Version::Hash()); |
| 251 SetHeaderValue(kNumReservationsOffset, reservations.length()); |
| 252 SetHeaderValue(kPayloadLengthOffset, payload.length()); |
| 253 |
| 254 // Copy reservation chunk sizes. |
| 255 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), |
| 256 reservation_size); |
| 257 |
| 258 // Copy serialized data. |
| 259 CopyBytes(data_ + kHeaderSize + reservation_size, payload.begin(), |
| 260 static_cast<size_t>(payload.length())); |
| 261 } |
| 262 |
| 263 bool SnapshotData::IsSane() { |
| 264 return GetHeaderValue(kCheckSumOffset) == Version::Hash(); |
| 265 } |
| 266 |
| 267 Vector<const SerializedData::Reservation> SnapshotData::Reservations() const { |
| 268 return Vector<const Reservation>( |
| 269 reinterpret_cast<const Reservation*>(data_ + kHeaderSize), |
| 270 GetHeaderValue(kNumReservationsOffset)); |
| 271 } |
| 272 |
| 273 Vector<const byte> SnapshotData::Payload() const { |
| 274 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; |
| 275 const byte* payload = data_ + kHeaderSize + reservations_size; |
| 276 int length = GetHeaderValue(kPayloadLengthOffset); |
| 277 DCHECK_EQ(data_ + size_, payload + length); |
| 278 return Vector<const byte>(payload, length); |
| 279 } |
| 280 |
231 } // namespace internal | 281 } // namespace internal |
232 } // namespace v8 | 282 } // namespace v8 |
OLD | NEW |