Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(99)

Side by Side Diff: src/snapshot/serializer-common.h

Issue 2736923002: SnapshotCreator: start from existing snapshot if we have one (Closed)
Patch Set: addressed comments Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/snapshot/deserializer.cc ('k') | src/snapshot/snapshot.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 }
262
263 static const int kMagicNumberOffset = 0;
264 static const int kExtraExternalReferencesOffset =
265 kMagicNumberOffset + kInt32Size;
266 static const int kVersionHashOffset =
267 kExtraExternalReferencesOffset + kInt32Size;
256 268
257 protected: 269 protected:
258 void SetHeaderValue(int offset, uint32_t value) { 270 void SetHeaderValue(int offset, uint32_t value) {
259 uint32_t* address = reinterpret_cast<uint32_t*>(data_ + offset); 271 uint32_t* address = reinterpret_cast<uint32_t*>(data_ + offset);
260 memcpy(reinterpret_cast<uint32_t*>(address), &value, sizeof(value)); 272 memcpy(reinterpret_cast<uint32_t*>(address), &value, sizeof(value));
261 } 273 }
262 274
263 uint32_t GetHeaderValue(int offset) const { 275 uint32_t GetHeaderValue(int offset) const {
264 uint32_t value; 276 uint32_t value;
265 memcpy(&value, reinterpret_cast<int*>(data_ + offset), sizeof(value)); 277 memcpy(&value, reinterpret_cast<int*>(data_ + offset), sizeof(value));
266 return value; 278 return value;
267 } 279 }
268 280
269 void AllocateData(int size); 281 void AllocateData(int size);
270 282
271 static uint32_t ComputeMagicNumber(Isolate* isolate) { 283 static uint32_t ComputeMagicNumber(Isolate* isolate) {
272 return ComputeMagicNumber(ExternalReferenceTable::instance(isolate)); 284 return ComputeMagicNumber(ExternalReferenceTable::instance(isolate));
273 } 285 }
286 static uint32_t GetExtraReferences(Isolate* isolate) {
287 return GetExtraReferences(ExternalReferenceTable::instance(isolate));
288 }
274 289
275 void SetMagicNumber(Isolate* isolate) { 290 void SetMagicNumber(Isolate* isolate) {
276 SetHeaderValue(kMagicNumberOffset, ComputeMagicNumber(isolate)); 291 SetHeaderValue(kMagicNumberOffset, ComputeMagicNumber(isolate));
292 SetHeaderValue(kExtraExternalReferencesOffset, GetExtraReferences(isolate));
277 } 293 }
278 294
279 static const int kMagicNumberOffset = 0;
280
281 byte* data_; 295 byte* data_;
282 int size_; 296 int size_;
283 bool owns_data_; 297 bool owns_data_;
284 }; 298 };
285 299
286 } // namespace internal 300 } // namespace internal
287 } // namespace v8 301 } // namespace v8
288 302
289 #endif // V8_SNAPSHOT_SERIALIZER_COMMON_H_ 303 #endif // V8_SNAPSHOT_SERIALIZER_COMMON_H_
OLDNEW
« no previous file with comments | « src/snapshot/deserializer.cc ('k') | src/snapshot/snapshot.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698