Chromium Code Reviews| Index: src/serialize.cc |
| diff --git a/src/serialize.cc b/src/serialize.cc |
| index 62b200581b466c6d44a7ec3b3472aa0f47ba2f46..da39ff0e5673108b52d922b0f2f081aef40077f7 100644 |
| --- a/src/serialize.cc |
| +++ b/src/serialize.cc |
| @@ -2569,6 +2569,7 @@ SerializedCodeData::SerializedCodeData(const List<byte>& payload, |
| AllocateData(size); |
| // Set header values. |
| + SetHeaderValue(kMagicNumberOffset, kMagicNumber); |
| SetHeaderValue(kVersionHashOffset, Version::Hash()); |
| SetHeaderValue(kSourceHashOffset, SourceHash(cs.source())); |
| SetHeaderValue(kCpuFeaturesOffset, |
| @@ -2599,14 +2600,24 @@ SerializedCodeData::SerializedCodeData(const List<byte>& payload, |
| } |
| -bool SerializedCodeData::IsSane(String* source) const { |
| - return GetHeaderValue(kVersionHashOffset) == Version::Hash() && |
| - GetHeaderValue(kSourceHashOffset) == SourceHash(source) && |
| - GetHeaderValue(kCpuFeaturesOffset) == |
| - static_cast<uint32_t>(CpuFeatures::SupportedFeatures()) && |
| - GetHeaderValue(kFlagHashOffset) == FlagList::Hash() && |
| - Checksum(Payload()).Check(GetHeaderValue(kChecksum1Offset), |
| - GetHeaderValue(kChecksum2Offset)); |
| +SerializedCodeData::SanityCheckResult SerializedCodeData::SanityCheck( |
| + String* source) const { |
| + uint32_t magic_number = GetHeaderValue(kMagicNumberOffset); |
| + uint32_t version_hash = GetHeaderValue(kVersionHashOffset); |
| + uint32_t source_hash = GetHeaderValue(kSourceHashOffset); |
| + uint32_t cpu_features = GetHeaderValue(kCpuFeaturesOffset); |
| + uint32_t flags_hash = GetHeaderValue(kFlagHashOffset); |
| + uint32_t c1 = GetHeaderValue(kChecksum1Offset); |
| + uint32_t c2 = GetHeaderValue(kChecksum2Offset); |
| + if (magic_number != kMagicNumber) return MAGIC_NUMBER_MISMATCH; |
| + if (version_hash != Version::Hash()) return VERSION_MISMATCH; |
| + if (source_hash != SourceHash(source)) return SOURCE_MISMATCH; |
| + if (cpu_features != static_cast<uint32_t>(CpuFeatures::SupportedFeatures())) { |
| + return CPU_FEATURES_MISMATCH; |
| + } |
| + if (flags_hash != FlagList::Hash()) return FLAGS_MISMATCH; |
| + if (!Checksum(Payload()).Check(c1, c2)) return CHECKSUM_MISMATCH; |
| + return CHECK_SUCCESS; |
| } |
| @@ -2662,8 +2673,10 @@ SerializedCodeData* SerializedCodeData::FromCachedData(ScriptData* cached_data, |
| String* source) { |
| DisallowHeapAllocation no_gc; |
| SerializedCodeData* scd = new SerializedCodeData(cached_data); |
| - if (scd->IsSane(source)) return scd; |
| + SanityCheckResult r = scd->SanityCheck(source); |
| + if (r == CHECK_SUCCESS) return scd; |
| cached_data->Reject(); |
| + 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
|
| delete scd; |
| return NULL; |
| } |