OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #ifndef V8_SNAPSHOT_SERIALIZER_COMMON_H_ | 5 #ifndef V8_SNAPSHOT_SERIALIZER_COMMON_H_ |
6 #define V8_SNAPSHOT_SERIALIZER_COMMON_H_ | 6 #define V8_SNAPSHOT_SERIALIZER_COMMON_H_ |
7 | 7 |
8 #include "src/address-map.h" | 8 #include "src/address-map.h" |
9 #include "src/external-reference-table.h" | 9 #include "src/external-reference-table.h" |
10 #include "src/globals.h" | 10 #include "src/globals.h" |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 | 238 |
239 SerializedData(byte* data, int size) | 239 SerializedData(byte* data, int size) |
240 : data_(data), size_(size), owns_data_(false) {} | 240 : data_(data), size_(size), owns_data_(false) {} |
241 SerializedData() : data_(NULL), size_(0), owns_data_(false) {} | 241 SerializedData() : data_(NULL), size_(0), owns_data_(false) {} |
242 | 242 |
243 ~SerializedData() { | 243 ~SerializedData() { |
244 if (owns_data_) DeleteArray<byte>(data_); | 244 if (owns_data_) DeleteArray<byte>(data_); |
245 } | 245 } |
246 | 246 |
247 uint32_t GetMagicNumber() const { return GetHeaderValue(kMagicNumberOffset); } | 247 uint32_t GetMagicNumber() const { return GetHeaderValue(kMagicNumberOffset); } |
| 248 uint32_t GetExtraReferences() const { |
| 249 return GetHeaderValue(kExtraExternalReferencesOffset); |
| 250 } |
248 | 251 |
249 class ChunkSizeBits : public BitField<uint32_t, 0, 31> {}; | 252 class ChunkSizeBits : public BitField<uint32_t, 0, 31> {}; |
250 class IsLastChunkBits : public BitField<bool, 31, 1> {}; | 253 class IsLastChunkBits : public BitField<bool, 31, 1> {}; |
251 | 254 |
252 static uint32_t ComputeMagicNumber(ExternalReferenceTable* table) { | 255 static uint32_t ComputeMagicNumber(ExternalReferenceTable* table) { |
253 uint32_t external_refs = table->size(); | 256 uint32_t external_refs = table->size() - table->num_api_references(); |
254 return 0xC0DE0000 ^ external_refs; | 257 return 0xC0DE0000 ^ external_refs; |
255 } | 258 } |
| 259 static uint32_t GetExtraReferences(ExternalReferenceTable* table) { |
| 260 return table->num_api_references(); |
| 261 } |
256 | 262 |
257 protected: | 263 protected: |
258 void SetHeaderValue(int offset, uint32_t value) { | 264 void SetHeaderValue(int offset, uint32_t value) { |
259 uint32_t* address = reinterpret_cast<uint32_t*>(data_ + offset); | 265 uint32_t* address = reinterpret_cast<uint32_t*>(data_ + offset); |
260 memcpy(reinterpret_cast<uint32_t*>(address), &value, sizeof(value)); | 266 memcpy(reinterpret_cast<uint32_t*>(address), &value, sizeof(value)); |
261 } | 267 } |
262 | 268 |
263 uint32_t GetHeaderValue(int offset) const { | 269 uint32_t GetHeaderValue(int offset) const { |
264 uint32_t value; | 270 uint32_t value; |
265 memcpy(&value, reinterpret_cast<int*>(data_ + offset), sizeof(value)); | 271 memcpy(&value, reinterpret_cast<int*>(data_ + offset), sizeof(value)); |
266 return value; | 272 return value; |
267 } | 273 } |
268 | 274 |
269 void AllocateData(int size); | 275 void AllocateData(int size); |
270 | 276 |
271 static uint32_t ComputeMagicNumber(Isolate* isolate) { | 277 static uint32_t ComputeMagicNumber(Isolate* isolate) { |
272 return ComputeMagicNumber(ExternalReferenceTable::instance(isolate)); | 278 return ComputeMagicNumber(ExternalReferenceTable::instance(isolate)); |
273 } | 279 } |
| 280 static uint32_t GetExtraReferences(Isolate* isolate) { |
| 281 return GetExtraReferences(ExternalReferenceTable::instance(isolate)); |
| 282 } |
274 | 283 |
275 void SetMagicNumber(Isolate* isolate) { | 284 void SetMagicNumber(Isolate* isolate) { |
276 SetHeaderValue(kMagicNumberOffset, ComputeMagicNumber(isolate)); | 285 SetHeaderValue(kMagicNumberOffset, ComputeMagicNumber(isolate)); |
| 286 SetHeaderValue(kExtraExternalReferencesOffset, GetExtraReferences(isolate)); |
277 } | 287 } |
278 | 288 |
279 static const int kMagicNumberOffset = 0; | 289 static const int kMagicNumberOffset = 0; |
| 290 static const int kExtraExternalReferencesOffset = |
| 291 kMagicNumberOffset + kInt32Size; |
280 | 292 |
281 byte* data_; | 293 byte* data_; |
282 int size_; | 294 int size_; |
283 bool owns_data_; | 295 bool owns_data_; |
284 }; | 296 }; |
285 | 297 |
286 } // namespace internal | 298 } // namespace internal |
287 } // namespace v8 | 299 } // namespace v8 |
288 | 300 |
289 #endif // V8_SNAPSHOT_SERIALIZER_COMMON_H_ | 301 #endif // V8_SNAPSHOT_SERIALIZER_COMMON_H_ |
OLD | NEW |