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

Side by Side Diff: src/serialize.cc

Issue 909473002: Add hash fields to code cache header. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix test case 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') | src/version.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 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 2482 matching lines...) Expand 10 before | Expand all | Expand 10 after
2493 // Calculate sizes. 2493 // Calculate sizes.
2494 int reservation_size = reservations.length() * kInt32Size; 2494 int reservation_size = reservations.length() * kInt32Size;
2495 int num_stub_keys = stub_keys->length(); 2495 int num_stub_keys = stub_keys->length();
2496 int stub_keys_size = stub_keys->length() * kInt32Size; 2496 int stub_keys_size = stub_keys->length() * kInt32Size;
2497 int size = kHeaderSize + reservation_size + stub_keys_size + payload.length(); 2497 int size = kHeaderSize + reservation_size + stub_keys_size + payload.length();
2498 2498
2499 // Allocate backing store and create result data. 2499 // Allocate backing store and create result data.
2500 AllocateData(size); 2500 AllocateData(size);
2501 2501
2502 // Set header values. 2502 // Set header values.
2503 SetHeaderValue(kCheckSumOffset, CheckSum(cs.source())); 2503 SetHeaderValue(kVersionHashOffset, Version::Hash());
2504 SetHeaderValue(kSourceHashOffset, SourceHash(cs.source()));
2505 SetHeaderValue(kCpuFeaturesOffset,
2506 static_cast<uint32_t>(CpuFeatures::SupportedFeatures()));
2507 SetHeaderValue(kFlagHashOffset, FlagList::Hash());
2504 SetHeaderValue(kNumInternalizedStringsOffset, cs.num_internalized_strings()); 2508 SetHeaderValue(kNumInternalizedStringsOffset, cs.num_internalized_strings());
2505 SetHeaderValue(kReservationsOffset, reservations.length()); 2509 SetHeaderValue(kReservationsOffset, reservations.length());
2506 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); 2510 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys);
2507 SetHeaderValue(kPayloadLengthOffset, payload.length()); 2511 SetHeaderValue(kPayloadLengthOffset, payload.length());
2508 2512
2509 // Copy reservation chunk sizes. 2513 // Copy reservation chunk sizes.
2510 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()), 2514 CopyBytes(data_ + kHeaderSize, reinterpret_cast<byte*>(reservations.begin()),
2511 reservation_size); 2515 reservation_size);
2512 2516
2513 // Copy code stub keys. 2517 // Copy code stub keys.
2514 CopyBytes(data_ + kHeaderSize + reservation_size, 2518 CopyBytes(data_ + kHeaderSize + reservation_size,
2515 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); 2519 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size);
2516 2520
2517 // Copy serialized data. 2521 // Copy serialized data.
2518 CopyBytes(data_ + kHeaderSize + reservation_size + stub_keys_size, 2522 CopyBytes(data_ + kHeaderSize + reservation_size + stub_keys_size,
2519 payload.begin(), static_cast<size_t>(payload.length())); 2523 payload.begin(), static_cast<size_t>(payload.length()));
2520 } 2524 }
2521 2525
2522 2526
2523 bool SerializedCodeData::IsSane(String* source) { 2527 bool SerializedCodeData::IsSane(String* source) {
2524 return GetHeaderValue(kCheckSumOffset) == CheckSum(source) && 2528 return GetHeaderValue(kVersionHashOffset) == Version::Hash() &&
2529 GetHeaderValue(kSourceHashOffset) == SourceHash(source) &&
2530 GetHeaderValue(kCpuFeaturesOffset) ==
2531 static_cast<uint32_t>(CpuFeatures::SupportedFeatures()) &&
2532 GetHeaderValue(kFlagHashOffset) == FlagList::Hash() &&
2525 Payload().length() >= SharedFunctionInfo::kSize; 2533 Payload().length() >= SharedFunctionInfo::kSize;
2526 } 2534 }
2527 2535
2528 2536
2529 int SerializedCodeData::CheckSum(String* string) {
2530 return Version::Hash() ^ string->length();
2531 }
2532
2533
2534 // Return ScriptData object and relinquish ownership over it to the caller. 2537 // Return ScriptData object and relinquish ownership over it to the caller.
2535 ScriptData* SerializedCodeData::GetScriptData() { 2538 ScriptData* SerializedCodeData::GetScriptData() {
2536 DCHECK(owns_data_); 2539 DCHECK(owns_data_);
2537 ScriptData* result = new ScriptData(data_, size_); 2540 ScriptData* result = new ScriptData(data_, size_);
2538 result->AcquireDataOwnership(); 2541 result->AcquireDataOwnership();
2539 owns_data_ = false; 2542 owns_data_ = false;
2540 data_ = NULL; 2543 data_ = NULL;
2541 return result; 2544 return result;
2542 } 2545 }
2543 2546
(...skipping 21 matching lines...) Expand all
2565 return GetHeaderValue(kNumInternalizedStringsOffset); 2568 return GetHeaderValue(kNumInternalizedStringsOffset);
2566 } 2569 }
2567 2570
2568 Vector<const uint32_t> SerializedCodeData::CodeStubKeys() const { 2571 Vector<const uint32_t> SerializedCodeData::CodeStubKeys() const {
2569 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size; 2572 int reservations_size = GetHeaderValue(kReservationsOffset) * kInt32Size;
2570 const byte* start = data_ + kHeaderSize + reservations_size; 2573 const byte* start = data_ + kHeaderSize + reservations_size;
2571 return Vector<const uint32_t>(reinterpret_cast<const uint32_t*>(start), 2574 return Vector<const uint32_t>(reinterpret_cast<const uint32_t*>(start),
2572 GetHeaderValue(kNumCodeStubKeysOffset)); 2575 GetHeaderValue(kNumCodeStubKeysOffset));
2573 } 2576 }
2574 } } // namespace v8::internal 2577 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | src/version.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698