Chromium Code Reviews| OLD | NEW | 
|---|---|
| 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 2551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2562 int num_stub_keys = stub_keys->length(); | 2562 int num_stub_keys = stub_keys->length(); | 
| 2563 int stub_keys_size = stub_keys->length() * kInt32Size; | 2563 int stub_keys_size = stub_keys->length() * kInt32Size; | 
| 2564 int payload_offset = kHeaderSize + reservation_size + stub_keys_size; | 2564 int payload_offset = kHeaderSize + reservation_size + stub_keys_size; | 
| 2565 int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset); | 2565 int padded_payload_offset = POINTER_SIZE_ALIGN(payload_offset); | 
| 2566 int size = padded_payload_offset + payload.length(); | 2566 int size = padded_payload_offset + payload.length(); | 
| 2567 | 2567 | 
| 2568 // Allocate backing store and create result data. | 2568 // Allocate backing store and create result data. | 
| 2569 AllocateData(size); | 2569 AllocateData(size); | 
| 2570 | 2570 | 
| 2571 // Set header values. | 2571 // Set header values. | 
| 2572 SetHeaderValue(kMagicNumberOffset, kMagicNumber); | |
| 2572 SetHeaderValue(kVersionHashOffset, Version::Hash()); | 2573 SetHeaderValue(kVersionHashOffset, Version::Hash()); | 
| 2573 SetHeaderValue(kSourceHashOffset, SourceHash(cs.source())); | 2574 SetHeaderValue(kSourceHashOffset, SourceHash(cs.source())); | 
| 2574 SetHeaderValue(kCpuFeaturesOffset, | 2575 SetHeaderValue(kCpuFeaturesOffset, | 
| 2575 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); | 2576 static_cast<uint32_t>(CpuFeatures::SupportedFeatures())); | 
| 2576 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); | 2577 SetHeaderValue(kFlagHashOffset, FlagList::Hash()); | 
| 2577 SetHeaderValue(kNumInternalizedStringsOffset, cs.num_internalized_strings()); | 2578 SetHeaderValue(kNumInternalizedStringsOffset, cs.num_internalized_strings()); | 
| 2578 SetHeaderValue(kNumReservationsOffset, reservations.length()); | 2579 SetHeaderValue(kNumReservationsOffset, reservations.length()); | 
| 2579 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); | 2580 SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys); | 
| 2580 SetHeaderValue(kPayloadLengthOffset, payload.length()); | 2581 SetHeaderValue(kPayloadLengthOffset, payload.length()); | 
| 2581 | 2582 | 
| (...skipping 10 matching lines...) Expand all Loading... | |
| 2592 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); | 2593 reinterpret_cast<byte*>(stub_keys->begin()), stub_keys_size); | 
| 2593 | 2594 | 
| 2594 memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset); | 2595 memset(data_ + payload_offset, 0, padded_payload_offset - payload_offset); | 
| 2595 | 2596 | 
| 2596 // Copy serialized data. | 2597 // Copy serialized data. | 
| 2597 CopyBytes(data_ + padded_payload_offset, payload.begin(), | 2598 CopyBytes(data_ + padded_payload_offset, payload.begin(), | 
| 2598 static_cast<size_t>(payload.length())); | 2599 static_cast<size_t>(payload.length())); | 
| 2599 } | 2600 } | 
| 2600 | 2601 | 
| 2601 | 2602 | 
| 2602 bool SerializedCodeData::IsSane(String* source) const { | 2603 SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck( | 
| 2603 return GetHeaderValue(kVersionHashOffset) == Version::Hash() && | 2604 String* source) const { | 
| 2604 GetHeaderValue(kSourceHashOffset) == SourceHash(source) && | 2605 uint32_t magic_number = GetHeaderValue(kMagicNumberOffset); | 
| 2605 GetHeaderValue(kCpuFeaturesOffset) == | 2606 uint32_t version_hash = GetHeaderValue(kVersionHashOffset); | 
| 2606 static_cast<uint32_t>(CpuFeatures::SupportedFeatures()) && | 2607 uint32_t source_hash = GetHeaderValue(kSourceHashOffset); | 
| 2607 GetHeaderValue(kFlagHashOffset) == FlagList::Hash() && | 2608 uint32_t cpu_features = GetHeaderValue(kCpuFeaturesOffset); | 
| 2608 Checksum(Payload()).Check(GetHeaderValue(kChecksum1Offset), | 2609 uint32_t flags_hash = GetHeaderValue(kFlagHashOffset); | 
| 2609 GetHeaderValue(kChecksum2Offset)); | 2610 uint32_t c1 = GetHeaderValue(kChecksum1Offset); | 
| 2611 uint32_t c2 = GetHeaderValue(kChecksum2Offset); | |
| 2612 if (magic_number != kMagicNumber) return MAGIC_NUMBER_MISMATCH; | |
| 2613 if (version_hash != Version::Hash()) return VERSION_MISMATCH; | |
| 2614 if (source_hash != SourceHash(source)) return SOURCE_MISMATCH; | |
| 2615 if (cpu_features != static_cast<uint32_t>(CpuFeatures::SupportedFeatures())) { | |
| 2616 return CPU_FEATURES_MISMATCH; | |
| 2617 } | |
| 2618 if (flags_hash != FlagList::Hash()) return FLAGS_MISMATCH; | |
| 2619 if (!Checksum(Payload()).Check(c1, c2)) return CHECKSUM_MISMATCH; | |
| 2620 return CHECK_SUCCESS; | |
| 2610 } | 2621 } | 
| 2611 | 2622 | 
| 2612 | 2623 | 
| 2613 // Return ScriptData object and relinquish ownership over it to the caller. | 2624 // Return ScriptData object and relinquish ownership over it to the caller. | 
| 2614 ScriptData* SerializedCodeData::GetScriptData() { | 2625 ScriptData* SerializedCodeData::GetScriptData() { | 
| 2615 DCHECK(owns_data_); | 2626 DCHECK(owns_data_); | 
| 2616 ScriptData* result = new ScriptData(data_, size_); | 2627 ScriptData* result = new ScriptData(data_, size_); | 
| 2617 result->AcquireDataOwnership(); | 2628 result->AcquireDataOwnership(); | 
| 2618 owns_data_ = false; | 2629 owns_data_ = false; | 
| 2619 data_ = NULL; | 2630 data_ = NULL; | 
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2655 | 2666 | 
| 2656 | 2667 | 
| 2657 SerializedCodeData::SerializedCodeData(ScriptData* data) | 2668 SerializedCodeData::SerializedCodeData(ScriptData* data) | 
| 2658 : SerializedData(const_cast<byte*>(data->data()), data->length()) {} | 2669 : SerializedData(const_cast<byte*>(data->data()), data->length()) {} | 
| 2659 | 2670 | 
| 2660 | 2671 | 
| 2661 SerializedCodeData* SerializedCodeData::FromCachedData(ScriptData* cached_data, | 2672 SerializedCodeData* SerializedCodeData::FromCachedData(ScriptData* cached_data, | 
| 2662 String* source) { | 2673 String* source) { | 
| 2663 DisallowHeapAllocation no_gc; | 2674 DisallowHeapAllocation no_gc; | 
| 2664 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 2675 SerializedCodeData* scd = new SerializedCodeData(cached_data); | 
| 2665 if (scd->IsSane(source)) return scd; | 2676 SanityCheckResult r = scd->SanityCheck(source); | 
| 2677 if (r == CHECK_SUCCESS) return scd; | |
| 2666 cached_data->Reject(); | 2678 cached_data->Reject(); | 
| 2679 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); | |
| 
 
vogelheim
2015/02/16 12:01:36
Just curious: Why count only the failures, and not
 
 | |
| 2667 delete scd; | 2680 delete scd; | 
| 2668 return NULL; | 2681 return NULL; | 
| 2669 } | 2682 } | 
| 2670 } } // namespace v8::internal | 2683 } } // namespace v8::internal | 
| OLD | NEW |