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

Side by Side Diff: src/snapshot/code-serializer.cc

Issue 2736923002: SnapshotCreator: start from existing snapshot if we have one (Closed)
Patch Set: 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
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 #include "src/snapshot/code-serializer.h" 5 #include "src/snapshot/code-serializer.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/counters.h" 10 #include "src/counters.h"
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
363 const List<uint32_t>* stub_keys = cs->stub_keys(); 363 const List<uint32_t>* stub_keys = cs->stub_keys();
364 364
365 List<Reservation> reservations; 365 List<Reservation> reservations;
366 cs->EncodeReservations(&reservations); 366 cs->EncodeReservations(&reservations);
367 367
368 // Calculate sizes. 368 // Calculate sizes.
369 int reservation_size = reservations.length() * kInt32Size; 369 int reservation_size = reservations.length() * kInt32Size;
370 int num_stub_keys = stub_keys->length(); 370 int num_stub_keys = stub_keys->length();
371 int stub_keys_size = stub_keys->length() * kInt32Size; 371 int stub_keys_size = stub_keys->length() * kInt32Size;
372 int payload_offset = kHeaderSize + reservation_size + stub_keys_size; 372 int payload_offset = kHeaderSize + reservation_size + stub_keys_size;
373 int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset); 373 int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset);
Yang 2017/03/07 11:28:11 The reason we aligned is for checksum computation.
Jakob Kummerow 2017/03/07 12:39:15 As discussed offline, checksumming still relies on
374 int size = padded_payload_offset + payload->length(); 374 int size = padded_payload_offset + payload->length();
375 375
376 // Allocate backing store and create result data. 376 // Allocate backing store and create result data.
377 AllocateData(size); 377 AllocateData(size);
378 378
379 // Set header values. 379 // Set header values.
380 SetMagicNumber(cs->isolate()); 380 SetMagicNumber(cs->isolate());
381 SetHeaderValue(kVersionHashOffset, Version::Hash()); 381 SetHeaderValue(kVersionHashOffset, Version::Hash());
382 SetHeaderValue(kSourceHashOffset, cs->source_hash()); 382 SetHeaderValue(kSourceHashOffset, cs->source_hash());
383 SetHeaderValue(kCpuFeaturesOffset, 383 SetHeaderValue(kCpuFeaturesOffset,
(...skipping 20 matching lines...) Expand all
404 Checksum checksum(DataWithoutHeader()); 404 Checksum checksum(DataWithoutHeader());
405 SetHeaderValue(kChecksum1Offset, checksum.a()); 405 SetHeaderValue(kChecksum1Offset, checksum.a());
406 SetHeaderValue(kChecksum2Offset, checksum.b()); 406 SetHeaderValue(kChecksum2Offset, checksum.b());
407 } 407 }
408 408
409 SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck( 409 SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck(
410 Isolate* isolate, uint32_t expected_source_hash) const { 410 Isolate* isolate, uint32_t expected_source_hash) const {
411 if (this->size_ < kHeaderSize) return INVALID_HEADER; 411 if (this->size_ < kHeaderSize) return INVALID_HEADER;
412 uint32_t magic_number = GetMagicNumber(); 412 uint32_t magic_number = GetMagicNumber();
413 if (magic_number != ComputeMagicNumber(isolate)) return MAGIC_NUMBER_MISMATCH; 413 if (magic_number != ComputeMagicNumber(isolate)) return MAGIC_NUMBER_MISMATCH;
414 if (GetExtraReferences() > GetExtraReferences(isolate)) {
415 return MAGIC_NUMBER_MISMATCH;
416 }
414 uint32_t version_hash = GetHeaderValue(kVersionHashOffset); 417 uint32_t version_hash = GetHeaderValue(kVersionHashOffset);
415 uint32_t source_hash = GetHeaderValue(kSourceHashOffset); 418 uint32_t source_hash = GetHeaderValue(kSourceHashOffset);
416 uint32_t cpu_features = GetHeaderValue(kCpuFeaturesOffset); 419 uint32_t cpu_features = GetHeaderValue(kCpuFeaturesOffset);
417 uint32_t flags_hash = GetHeaderValue(kFlagHashOffset); 420 uint32_t flags_hash = GetHeaderValue(kFlagHashOffset);
421 uint32_t payload_length = GetHeaderValue(kPayloadLengthOffset);
418 uint32_t c1 = GetHeaderValue(kChecksum1Offset); 422 uint32_t c1 = GetHeaderValue(kChecksum1Offset);
419 uint32_t c2 = GetHeaderValue(kChecksum2Offset); 423 uint32_t c2 = GetHeaderValue(kChecksum2Offset);
420 if (version_hash != Version::Hash()) return VERSION_MISMATCH; 424 if (version_hash != Version::Hash()) return VERSION_MISMATCH;
421 if (source_hash != expected_source_hash) return SOURCE_MISMATCH; 425 if (source_hash != expected_source_hash) return SOURCE_MISMATCH;
422 if (cpu_features != static_cast<uint32_t>(CpuFeatures::SupportedFeatures())) { 426 if (cpu_features != static_cast<uint32_t>(CpuFeatures::SupportedFeatures())) {
423 return CPU_FEATURES_MISMATCH; 427 return CPU_FEATURES_MISMATCH;
424 } 428 }
425 if (flags_hash != FlagList::Hash()) return FLAGS_MISMATCH; 429 if (flags_hash != FlagList::Hash()) return FLAGS_MISMATCH;
430 uint32_t max_payload_length =
431 this->size_ -
432 POINTER_SIZE_ALIGN(kHeaderSize +
Yang 2017/03/07 11:28:11 See above. Let's not align.
Jakob Kummerow 2017/03/07 12:39:15 See above -- if we align one, we need to align the
433 GetHeaderValue(kNumReservationsOffset) * kInt32Size +
434 GetHeaderValue(kNumCodeStubKeysOffset) * kInt32Size);
435 if (payload_length > max_payload_length) return LENGTH_MISMATCH;
426 if (!Checksum(DataWithoutHeader()).Check(c1, c2)) return CHECKSUM_MISMATCH; 436 if (!Checksum(DataWithoutHeader()).Check(c1, c2)) return CHECKSUM_MISMATCH;
427 return CHECK_SUCCESS; 437 return CHECK_SUCCESS;
428 } 438 }
429 439
430 uint32_t SerializedCodeData::SourceHash(Handle<String> source) { 440 uint32_t SerializedCodeData::SourceHash(Handle<String> source) {
431 return source->length(); 441 return source->length();
432 } 442 }
433 443
434 // Return ScriptData object and relinquish ownership over it to the caller. 444 // Return ScriptData object and relinquish ownership over it to the caller.
435 ScriptData* SerializedCodeData::GetScriptData() { 445 ScriptData* SerializedCodeData::GetScriptData() {
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 *rejection_result = scd.SanityCheck(isolate, expected_source_hash); 488 *rejection_result = scd.SanityCheck(isolate, expected_source_hash);
479 if (*rejection_result != CHECK_SUCCESS) { 489 if (*rejection_result != CHECK_SUCCESS) {
480 cached_data->Reject(); 490 cached_data->Reject();
481 return SerializedCodeData(nullptr, 0); 491 return SerializedCodeData(nullptr, 0);
482 } 492 }
483 return scd; 493 return scd;
484 } 494 }
485 495
486 } // namespace internal 496 } // namespace internal
487 } // namespace v8 497 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698