| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 // Calculate sizes. | 189 // Calculate sizes. |
| 190 int reservation_size = reservations.length() * kInt32Size; | 190 int reservation_size = reservations.length() * kInt32Size; |
| 191 int size = kHeaderSize + reservation_size + payload->length(); | 191 int size = kHeaderSize + reservation_size + payload->length(); |
| 192 | 192 |
| 193 // Allocate backing store and create result data. | 193 // Allocate backing store and create result data. |
| 194 AllocateData(size); | 194 AllocateData(size); |
| 195 | 195 |
| 196 // Set header values. | 196 // Set header values. |
| 197 SetMagicNumber(serializer->isolate()); | 197 SetMagicNumber(serializer->isolate()); |
| 198 SetHeaderValue(kCheckSumOffset, Version::Hash()); | 198 SetHeaderValue(kVersionHashOffset, Version::Hash()); |
| 199 SetHeaderValue(kNumReservationsOffset, reservations.length()); | 199 SetHeaderValue(kNumReservationsOffset, reservations.length()); |
| 200 SetHeaderValue(kPayloadLengthOffset, payload->length()); | 200 SetHeaderValue(kPayloadLengthOffset, payload->length()); |
| 201 | 201 |
| 202 // Copy reservation chunk sizes. | 202 // Copy reservation chunk sizes. |
| 203 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), | 203 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), |
| 204 reservation_size); | 204 reservation_size); |
| 205 | 205 |
| 206 // Copy serialized data. | 206 // Copy serialized data. |
| 207 CopyBytes(data_ + kHeaderSize + reservation_size, payload->begin(), | 207 CopyBytes(data_ + kHeaderSize + reservation_size, payload->begin(), |
| 208 static_cast<size_t>(payload->length())); | 208 static_cast<size_t>(payload->length())); |
| 209 } | 209 } |
| 210 | 210 |
| 211 bool SnapshotData::IsSane() { | 211 bool SnapshotData::IsSane() { |
| 212 return GetHeaderValue(kCheckSumOffset) == Version::Hash(); | 212 return GetHeaderValue(kVersionHashOffset) == Version::Hash(); |
| 213 } | 213 } |
| 214 | 214 |
| 215 Vector<const SerializedData::Reservation> SnapshotData::Reservations() const { | 215 Vector<const SerializedData::Reservation> SnapshotData::Reservations() const { |
| 216 return Vector<const Reservation>( | 216 return Vector<const Reservation>( |
| 217 reinterpret_cast<const Reservation*>(data_ + kHeaderSize), | 217 reinterpret_cast<const Reservation*>(data_ + kHeaderSize), |
| 218 GetHeaderValue(kNumReservationsOffset)); | 218 GetHeaderValue(kNumReservationsOffset)); |
| 219 } | 219 } |
| 220 | 220 |
| 221 Vector<const byte> SnapshotData::Payload() const { | 221 Vector<const byte> SnapshotData::Payload() const { |
| 222 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; | 222 int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size; |
| 223 const byte* payload = data_ + kHeaderSize + reservations_size; | 223 const byte* payload = data_ + kHeaderSize + reservations_size; |
| 224 int length = GetHeaderValue(kPayloadLengthOffset); | 224 int length = GetHeaderValue(kPayloadLengthOffset); |
| 225 DCHECK_EQ(data_ + size_, payload + length); | 225 DCHECK_EQ(data_ + size_, payload + length); |
| 226 return Vector<const byte>(payload, length); | 226 return Vector<const byte>(payload, length); |
| 227 } | 227 } |
| 228 | 228 |
| 229 } // namespace internal | 229 } // namespace internal |
| 230 } // namespace v8 | 230 } // namespace v8 |
| OLD | NEW |