Index: src/serialize.cc |
diff --git a/src/serialize.cc b/src/serialize.cc |
index eedbab4cd6e0f50053288dfa73d2f69056f9a2da..6937e5b1d918efc5a8015cd3cfe3a00f26ba5815 100644 |
--- a/src/serialize.cc |
+++ b/src/serialize.cc |
@@ -13,6 +13,7 @@ |
#include "src/global-handles.h" |
#include "src/ic-inl.h" |
#include "src/natives.h" |
+#include "src/objects.h" |
#include "src/runtime.h" |
#include "src/serialize.h" |
#include "src/snapshot.h" |
@@ -1993,7 +1994,7 @@ void CodeSerializer::SerializeSourceObject(HowToCode how_to_code, |
Handle<SharedFunctionInfo> CodeSerializer::Deserialize(Isolate* isolate, |
ScriptData* data, |
Handle<String> source) { |
- SerializedCodeData scd(data); |
+ SerializedCodeData scd(data, *source); |
SnapshotByteSource payload(scd.Payload(), scd.PayloadLength()); |
Deserializer deserializer(&payload); |
STATIC_ASSERT(NEW_SPACE == 0); |
@@ -2017,6 +2018,7 @@ Handle<SharedFunctionInfo> CodeSerializer::Deserialize(Isolate* isolate, |
SerializedCodeData::SerializedCodeData(List<byte>* payload, CodeSerializer* cs) |
: owns_script_data_(true) { |
+ DisallowHeapAllocation no_gc; |
int data_length = payload->length() + kHeaderEntries * kIntSize; |
byte* data = NewArray<byte>(data_length); |
ASSERT(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)); |
@@ -2024,7 +2026,7 @@ SerializedCodeData::SerializedCodeData(List<byte>* payload, CodeSerializer* cs) |
static_cast<size_t>(payload->length())); |
script_data_ = new ScriptData(data, data_length); |
script_data_->AcquireDataOwnership(); |
- SetHeaderValue(kVersionHashOffset, Version::Hash()); |
+ SetHeaderValue(kCheckSumOffset, CheckSum(cs->source())); |
STATIC_ASSERT(NEW_SPACE == 0); |
for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) { |
SetHeaderValue(kReservationsOffset + i, cs->CurrentAllocationAddress(i)); |
@@ -2032,8 +2034,18 @@ SerializedCodeData::SerializedCodeData(List<byte>* payload, CodeSerializer* cs) |
} |
-bool SerializedCodeData::IsSane() { |
- return GetHeaderValue(kVersionHashOffset) == Version::Hash() && |
+bool SerializedCodeData::IsSane(String* source) { |
+ return GetHeaderValue(kCheckSumOffset) == CheckSum(source) && |
PayloadLength() >= SharedFunctionInfo::kSize; |
} |
+ |
+ |
+int SerializedCodeData::CheckSum(String* string) { |
+ int checksum = Version::Hash(); |
+#ifdef DEBUG |
+ uint32_t seed = static_cast<uint32_t>(checksum); |
+ checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed)); |
+#endif // DEBUG |
+ return checksum; |
+} |
} } // namespace v8::internal |