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

Side by Side Diff: src/serialize.cc

Issue 907013002: Add payload checksum to code cache data. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 10 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/serialize.h ('k') | test/cctest/test-serialize.cc » ('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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/api.h" 8 #include "src/api.h"
9 #include "src/base/platform/platform.h" 9 #include "src/base/platform/platform.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 2139 matching lines...) Expand 10 before | Expand all | Expand 10 after
2150 offset); 2150 offset);
2151 } 2151 }
2152 2152
2153 2153
2154 void Serializer::Pad() { 2154 void Serializer::Pad() {
2155 // The non-branching GetInt will read up to 3 bytes too far, so we need 2155 // The non-branching GetInt will read up to 3 bytes too far, so we need
2156 // to pad the snapshot to make sure we don't read over the end. 2156 // to pad the snapshot to make sure we don't read over the end.
2157 for (unsigned i = 0; i < sizeof(int32_t) - 1; i++) { 2157 for (unsigned i = 0; i < sizeof(int32_t) - 1; i++) {
2158 sink_->Put(kNop, "Padding"); 2158 sink_->Put(kNop, "Padding");
2159 } 2159 }
2160 // Pad up to pointer size for checksum.
2161 while (!IsAligned(sink_->Position(), kPointerAlignment)) {
2162 sink_->Put(kNop, "Padding");
2163 }
2160 } 2164 }
2161 2165
2162 2166
2163 void Serializer::InitializeCodeAddressMap() { 2167 void Serializer::InitializeCodeAddressMap() {
2164 isolate_->InitializeLoggingAndCounters(); 2168 isolate_->InitializeLoggingAndCounters();
2165 code_address_map_ = new CodeAddressMap(isolate_); 2169 code_address_map_ = new CodeAddressMap(isolate_);
2166 } 2170 }
2167 2171
2168 2172
2169 ScriptData* CodeSerializer::Serialize(Isolate* isolate, 2173 ScriptData* CodeSerializer::Serialize(Isolate* isolate,
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after
2475 2479
2476 Vector<const byte> SnapshotData::Payload() const { 2480 Vector<const byte> SnapshotData::Payload() const {
2477 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size; 2481 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size;
2478 const byte* payload = data_ + kHeaderSize + reservations_size; 2482 const byte* payload = data_ + kHeaderSize + reservations_size;
2479 int length = GetHeaderValue(kPayloadLengthOffset); 2483 int length = GetHeaderValue(kPayloadLengthOffset);
2480 DCHECK_EQ(data_ + size_, payload + length); 2484 DCHECK_EQ(data_ + size_, payload + length);
2481 return Vector<const byte>(payload, length); 2485 return Vector<const byte>(payload, length);
2482 } 2486 }
2483 2487
2484 2488
2489 class Checksum {
2490 public:
2491 Checksum(Vector<const byte> payload) {
jochen (gone - plz use gerrit) 2015/02/09 14:11:21 explicit
2492 // Fletcher's checksum. Modified to reduce 64-bit sums to 32-bit.
2493 uintptr_t a = 1;
2494 uintptr_t b = 0;
2495 const uintptr_t* cur = reinterpret_cast<const uintptr_t*>(payload.start());
2496 DCHECK(IsAligned(payload.length(), kIntptrSize));
2497 const uintptr_t* end = cur + payload.length() / kIntptrSize;
2498 while (cur < end) {
2499 // Unsigned overflow expected and intended.
2500 a += *cur++;
2501 b += a;
2502 }
2503 #if V8_HOST_ARCH_64_BIT
2504 a ^= a >> 32;
2505 b ^= b >> 32;
2506 #endif // V8_HOST_ARCH_64_BIT
2507 a_ = static_cast<uint32_t>(a);
2508 b_ = static_cast<uint32_t>(b);
2509 }
2510
2511 bool Check(uint32_t a, uint32_t b) const { return a == a_ && b == b_; }
2512
2513 uint32_t a() const { return a_; }
2514 uint32_t b() const { return b_; }
2515
2516 private:
2517 uint32_t a_;
2518 uint32_t b_;
2519 };
jochen (gone - plz use gerrit) 2015/02/09 14:11:21 DISALLOW_COPY_AND_ASSIGN()
jochen (gone - plz use gerrit) 2015/02/09 14:11:21 DISALLOW_COPY_AND_ASSIGN()
2520
2521
2485 SerializedCodeData::SerializedCodeData(const List<byte>& payload, 2522 SerializedCodeData::SerializedCodeData(const List<byte>& payload,
2486 const CodeSerializer& cs) { 2523 const CodeSerializer& cs) {
2487 DisallowHeapAllocation no_gc; 2524 DisallowHeapAllocation no_gc;
2488 const List<uint32_t>* stub_keys = cs.stub_keys(); 2525 const List<uint32_t>* stub_keys = cs.stub_keys();
2489 2526
2490 List<Reservation> reservations; 2527 List<Reservation> reservations;
2491 cs.EncodeReservations(&reservations); 2528 cs.EncodeReservations(&reservations);
2492 2529
2493 // Calculate sizes. 2530 // Calculate sizes.
2494 int reservation_size = reservations.length() * kInt32Size; 2531 int reservation_size = reservations.length() * kInt32Size;
2495 int num_stub_keys = stub_keys->length(); 2532 int num_stub_keys = stub_keys->length();
2496 int stub_keys_size = stub_keys->length() * kInt32Size; 2533 int stub_keys_size = stub_keys->length() * kInt32Size;
2497 int size = kHeaderSize + reservation_size + stub_keys_size + payload.length(); 2534 int size = kHeaderSize + reservation_size + stub_keys_size + payload.length();
2498 2535
2499 // Allocate backing store and create result data. 2536 // Allocate backing store and create result data.
2500 AllocateData(size); 2537 AllocateData(size);
2501 2538
2502 // Set header values. 2539 // Set header values.
2503 SetHeaderValue(kVersionHashOffset, Version::Hash()); 2540 SetHeaderValue(kVersionHashOffset, Version::Hash());
2504 SetHeaderValue(kSourceHashOffset, SourceHash(cs.source())); 2541 SetHeaderValue(kSourceHashOffset, SourceHash(cs.source()));
2505 SetHeaderValue(kCpuFeaturesOffset, 2542 SetHeaderValue(kCpuFeaturesOffset,
2506 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); 2543 static_cast<uint32_t>(CpuFeatures::SupportedFeatures()));
2507 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); 2544 SetHeaderValue(kFlagHashOffset, FlagList::Hash());
2508 SetHeaderValue(kNumInternalizedStringsOffset, cs.num_internalized_strings()); 2545 SetHeaderValue(kNumInternalizedStringsOffset, cs.num_internalized_strings());
2509 SetHeaderValue(kReservationsOffset, reservations.length()); 2546 SetHeaderValue(kReservationsOffset, reservations.length());
2510 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); 2547 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys);
2511 SetHeaderValue(kPayloadLengthOffset, payload.length()); 2548 SetHeaderValue(kPayloadLengthOffset, payload.length());
2512 2549
2550 Checksum checksum(payload.ToConstVector());
2551 SetHeaderValue(kChecksum1Offset, checksum.a());
2552 SetHeaderValue(kChecksum2Offset, checksum.b());
2553
2513 // Copy reservation chunk sizes. 2554 // Copy reservation chunk sizes.
2514 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), 2555 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()),
2515 reservation_size); 2556 reservation_size);
2516 2557
2517 // Copy code stub keys. 2558 // Copy code stub keys.
2518 CopyBytes(data_ + kHeaderSize + reservation_size, 2559 CopyBytes(data_ + kHeaderSize + reservation_size,
2519 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); 2560 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size);
2520 2561
2521 // Copy serialized data. 2562 // Copy serialized data.
2522 CopyBytes(data_ + kHeaderSize + reservation_size + stub_keys_size, 2563 CopyBytes(data_ + kHeaderSize + reservation_size + stub_keys_size,
2523 payload.begin(), static_cast<size_t>(payload.length())); 2564 payload.begin(), static_cast<size_t>(payload.length()));
2524 } 2565 }
2525 2566
2526 2567
2527 bool SerializedCodeData::IsSane(String* source) { 2568 bool SerializedCodeData::IsSane(String* source) const {
2528 return GetHeaderValue(kVersionHashOffset) == Version::Hash() && 2569 return GetHeaderValue(kVersionHashOffset) == Version::Hash() &&
2529 GetHeaderValue(kSourceHashOffset) == SourceHash(source) && 2570 GetHeaderValue(kSourceHashOffset) == SourceHash(source) &&
2530 GetHeaderValue(kCpuFeaturesOffset) == 2571 GetHeaderValue(kCpuFeaturesOffset) ==
2531 static_cast<uint32_t>(CpuFeatures::SupportedFeatures()) && 2572 static_cast<uint32_t>(CpuFeatures::SupportedFeatures()) &&
2532 GetHeaderValue(kFlagHashOffset) == FlagList::Hash() && 2573 GetHeaderValue(kFlagHashOffset) == FlagList::Hash() &&
2533 Payload().length() >= SharedFunctionInfo::kSize; 2574 Checksum(Payload()).Check(GetHeaderValue(kChecksum1Offset),
2575 GetHeaderValue(kChecksum2Offset));
2534 } 2576 }
2535 2577
2536 2578
2537 // Return ScriptData object and relinquish ownership over it to the caller. 2579 // Return ScriptData object and relinquish ownership over it to the caller.
2538 ScriptData* SerializedCodeData::GetScriptData() { 2580 ScriptData* SerializedCodeData::GetScriptData() {
2539 DCHECK(owns_data_); 2581 DCHECK(owns_data_);
2540 ScriptData* result = new ScriptData(data_, size_); 2582 ScriptData* result = new ScriptData(data_, size_);
2541 result->AcquireDataOwnership(); 2583 result->AcquireDataOwnership();
2542 owns_data_ = false; 2584 owns_data_ = false;
2543 data_ = NULL; 2585 data_ = NULL;
(...skipping 24 matching lines...) Expand all
2568 return GetHeaderValue(kNumInternalizedStringsOffset); 2610 return GetHeaderValue(kNumInternalizedStringsOffset);
2569 } 2611 }
2570 2612
2571 Vector<const uint32_t> SerializedCodeData::CodeStubKeys() const { 2613 Vector<const uint32_t> SerializedCodeData::CodeStubKeys() const {
2572 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size; 2614 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size;
2573 const byte* start = data_ + kHeaderSize + reservations_size; 2615 const byte* start = data_ + kHeaderSize + reservations_size;
2574 return Vector<const uint32_t>(reinterpret_cast<const uint32_t*>(start), 2616 return Vector<const uint32_t>(reinterpret_cast<const uint32_t*>(start),
2575 GetHeaderValue(kNumCodeStubKeysOffset)); 2617 GetHeaderValue(kNumCodeStubKeysOffset));
2576 } 2618 }
2577 } } // namespace v8::internal 2619 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | test/cctest/test-serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698