| 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 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 246 | 246 |
| 247 class ChunkSizeBits : public BitField<uint32_t, 0, 31> {}; | 247 class ChunkSizeBits : public BitField<uint32_t, 0, 31> {}; |
| 248 class IsLastChunkBits : public BitField<bool, 31, 1> {}; | 248 class IsLastChunkBits : public BitField<bool, 31, 1> {}; |
| 249 | 249 |
| 250 static uint32_t ComputeMagicNumber(ExternalReferenceTable* table) { | 250 static uint32_t ComputeMagicNumber(ExternalReferenceTable* table) { |
| 251 uint32_t external_refs = table->size(); | 251 uint32_t external_refs = table->size(); |
| 252 return 0xC0DE0000 ^ external_refs; | 252 return 0xC0DE0000 ^ external_refs; |
| 253 } | 253 } |
| 254 | 254 |
| 255 protected: | 255 protected: |
| 256 static void SetHeaderValueInBuffer(byte* buffer, int offset, uint32_t value) { |
| 257 uint32_t* address = reinterpret_cast<uint32_t*>(buffer + offset); |
| 258 memcpy(reinterpret_cast<uint32_t*>(address), &value, sizeof(value)); |
| 259 } |
| 260 |
| 256 void SetHeaderValue(int offset, uint32_t value) { | 261 void SetHeaderValue(int offset, uint32_t value) { |
| 257 uint32_t* address = reinterpret_cast<uint32_t*>(data_ + offset); | 262 SetHeaderValueInBuffer(data_, offset, value); |
| 258 memcpy(reinterpret_cast<uint32_t*>(address), &value, sizeof(value)); | |
| 259 } | 263 } |
| 260 | 264 |
| 261 uint32_t GetHeaderValue(int offset) const { | 265 uint32_t GetHeaderValue(int offset) const { |
| 262 uint32_t value; | 266 uint32_t value; |
| 263 memcpy(&value, reinterpret_cast<int*>(data_ + offset), sizeof(value)); | 267 memcpy(&value, reinterpret_cast<int*>(data_ + offset), sizeof(value)); |
| 264 return value; | 268 return value; |
| 265 } | 269 } |
| 266 | 270 |
| 267 void AllocateData(int size); | 271 void AllocateData(int size); |
| 268 | 272 |
| 269 static uint32_t ComputeMagicNumber(Isolate* isolate) { | 273 static uint32_t ComputeMagicNumber(Isolate* isolate) { |
| 270 return ComputeMagicNumber(ExternalReferenceTable::instance(isolate)); | 274 return ComputeMagicNumber(ExternalReferenceTable::instance(isolate)); |
| 271 } | 275 } |
| 272 | 276 |
| 273 void SetMagicNumber(Isolate* isolate) { | 277 void SetMagicNumber(Isolate* isolate) { |
| 274 SetHeaderValue(kMagicNumberOffset, ComputeMagicNumber(isolate)); | 278 SetHeaderValue(kMagicNumberOffset, ComputeMagicNumber(isolate)); |
| 275 } | 279 } |
| 276 | 280 |
| 277 static const int kMagicNumberOffset = 0; | 281 static const int kMagicNumberOffset = 0; |
| 278 | 282 |
| 279 byte* data_; | 283 byte* data_; |
| 280 int size_; | 284 int size_; |
| 281 bool owns_data_; | 285 bool owns_data_; |
| 282 }; | 286 }; |
| 283 | 287 |
| 284 } // namespace internal | 288 } // namespace internal |
| 285 } // namespace v8 | 289 } // namespace v8 |
| 286 | 290 |
| 287 #endif // V8_SNAPSHOT_SERIALIZER_COMMON_H_ | 291 #endif // V8_SNAPSHOT_SERIALIZER_COMMON_H_ |
| OLD | NEW |