| 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" |
| 11 #include "src/deoptimizer.h" | 11 #include "src/deoptimizer.h" |
| 12 #include "src/execution.h" | 12 #include "src/execution.h" |
| 13 #include "src/global-handles.h" | 13 #include "src/global-handles.h" |
| 14 #include "src/ic-inl.h" | 14 #include "src/ic-inl.h" |
| 15 #include "src/natives.h" | 15 #include "src/natives.h" |
| 16 #include "src/objects.h" |
| 16 #include "src/runtime.h" | 17 #include "src/runtime.h" |
| 17 #include "src/serialize.h" | 18 #include "src/serialize.h" |
| 18 #include "src/snapshot.h" | 19 #include "src/snapshot.h" |
| 19 #include "src/snapshot-source-sink.h" | 20 #include "src/snapshot-source-sink.h" |
| 20 #include "src/stub-cache.h" | 21 #include "src/stub-cache.h" |
| 21 #include "src/v8threads.h" | 22 #include "src/v8threads.h" |
| 22 #include "src/version.h" | 23 #include "src/version.h" |
| 23 | 24 |
| 24 namespace v8 { | 25 namespace v8 { |
| 25 namespace internal { | 26 namespace internal { |
| (...skipping 1960 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1986 | 1987 |
| 1987 ASSERT(how_to_code == kPlain && where_to_point == kStartOfObject); | 1988 ASSERT(how_to_code == kPlain && where_to_point == kStartOfObject); |
| 1988 sink_->Put(kAttachedReference + how_to_code + where_to_point, "Source"); | 1989 sink_->Put(kAttachedReference + how_to_code + where_to_point, "Source"); |
| 1989 sink_->PutInt(kSourceObjectIndex, "kSourceObjectIndex"); | 1990 sink_->PutInt(kSourceObjectIndex, "kSourceObjectIndex"); |
| 1990 } | 1991 } |
| 1991 | 1992 |
| 1992 | 1993 |
| 1993 Handle<SharedFunctionInfo> CodeSerializer::Deserialize(Isolate* isolate, | 1994 Handle<SharedFunctionInfo> CodeSerializer::Deserialize(Isolate* isolate, |
| 1994 ScriptData* data, | 1995 ScriptData* data, |
| 1995 Handle<String> source) { | 1996 Handle<String> source) { |
| 1996 SerializedCodeData scd(data); | 1997 SerializedCodeData scd(data, *source); |
| 1997 SnapshotByteSource payload(scd.Payload(), scd.PayloadLength()); | 1998 SnapshotByteSource payload(scd.Payload(), scd.PayloadLength()); |
| 1998 Deserializer deserializer(&payload); | 1999 Deserializer deserializer(&payload); |
| 1999 STATIC_ASSERT(NEW_SPACE == 0); | 2000 STATIC_ASSERT(NEW_SPACE == 0); |
| 2000 // TODO(yangguo) what happens if remaining new space is too small? | 2001 // TODO(yangguo) what happens if remaining new space is too small? |
| 2001 for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) { | 2002 for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) { |
| 2002 deserializer.set_reservation(i, scd.GetReservation(i)); | 2003 deserializer.set_reservation(i, scd.GetReservation(i)); |
| 2003 } | 2004 } |
| 2004 DisallowHeapAllocation no_gc; | 2005 DisallowHeapAllocation no_gc; |
| 2005 | 2006 |
| 2006 // Prepare and register list of attached objects. | 2007 // Prepare and register list of attached objects. |
| 2007 Vector<Object*> attached_objects = Vector<Object*>::New(1); | 2008 Vector<Object*> attached_objects = Vector<Object*>::New(1); |
| 2008 attached_objects[kSourceObjectIndex] = *source; | 2009 attached_objects[kSourceObjectIndex] = *source; |
| 2009 deserializer.SetAttachedObjects(&attached_objects); | 2010 deserializer.SetAttachedObjects(&attached_objects); |
| 2010 | 2011 |
| 2011 Object* root; | 2012 Object* root; |
| 2012 deserializer.DeserializePartial(isolate, &root); | 2013 deserializer.DeserializePartial(isolate, &root); |
| 2013 deserializer.FlushICacheForNewCodeObjects(); | 2014 deserializer.FlushICacheForNewCodeObjects(); |
| 2014 return Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(root), isolate); | 2015 return Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(root), isolate); |
| 2015 } | 2016 } |
| 2016 | 2017 |
| 2017 | 2018 |
| 2018 SerializedCodeData::SerializedCodeData(List<byte>* payload, CodeSerializer* cs) | 2019 SerializedCodeData::SerializedCodeData(List<byte>* payload, CodeSerializer* cs) |
| 2019 : owns_script_data_(true) { | 2020 : owns_script_data_(true) { |
| 2021 DisallowHeapAllocation no_gc; |
| 2020 int data_length = payload->length() + kHeaderEntries * kIntSize; | 2022 int data_length = payload->length() + kHeaderEntries * kIntSize; |
| 2021 byte* data = NewArray<byte>(data_length); | 2023 byte* data = NewArray<byte>(data_length); |
| 2022 ASSERT(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)); | 2024 ASSERT(IsAligned(reinterpret_cast<intptr_t>(data), kPointerAlignment)); |
| 2023 CopyBytes(data + kHeaderEntries * kIntSize, payload->begin(), | 2025 CopyBytes(data + kHeaderEntries * kIntSize, payload->begin(), |
| 2024 static_cast<size_t>(payload->length())); | 2026 static_cast<size_t>(payload->length())); |
| 2025 script_data_ = new ScriptData(data, data_length); | 2027 script_data_ = new ScriptData(data, data_length); |
| 2026 script_data_->AcquireDataOwnership(); | 2028 script_data_->AcquireDataOwnership(); |
| 2027 SetHeaderValue(kVersionHashOffset, Version::Hash()); | 2029 SetHeaderValue(kCheckSumOffset, CheckSum(cs->source())); |
| 2028 STATIC_ASSERT(NEW_SPACE == 0); | 2030 STATIC_ASSERT(NEW_SPACE == 0); |
| 2029 for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) { | 2031 for (int i = NEW_SPACE; i <= PROPERTY_CELL_SPACE; i++) { |
| 2030 SetHeaderValue(kReservationsOffset + i, cs->CurrentAllocationAddress(i)); | 2032 SetHeaderValue(kReservationsOffset + i, cs->CurrentAllocationAddress(i)); |
| 2031 } | 2033 } |
| 2032 } | 2034 } |
| 2033 | 2035 |
| 2034 | 2036 |
| 2035 bool SerializedCodeData::IsSane() { | 2037 bool SerializedCodeData::IsSane(String* source) { |
| 2036 return GetHeaderValue(kVersionHashOffset) == Version::Hash() && | 2038 return GetHeaderValue(kCheckSumOffset) == CheckSum(source) && |
| 2037 PayloadLength() >= SharedFunctionInfo::kSize; | 2039 PayloadLength() >= SharedFunctionInfo::kSize; |
| 2038 } | 2040 } |
| 2041 |
| 2042 |
| 2043 int SerializedCodeData::CheckSum(String* string) { |
| 2044 int checksum = Version::Hash(); |
| 2045 #ifdef DEBUG |
| 2046 uint32_t seed = static_cast<uint32_t>(checksum); |
| 2047 checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed)); |
| 2048 #endif // DEBUG |
| 2049 return checksum; |
| 2050 } |
| 2039 } } // namespace v8::internal | 2051 } } // namespace v8::internal |
| OLD | NEW |