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

Side by Side Diff: src/serialize.cc

Issue 733023003: Reland "Soft fail for invalid cache data." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix leak Created 6 years, 1 month 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') | test/cctest/test-api.cc » ('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 2167 matching lines...) Expand 10 before | Expand all | Expand 10 after
2178 WhereToPoint where_to_point) { 2178 WhereToPoint where_to_point) {
2179 if (FLAG_trace_code_serializer) PrintF(" Encoding source object\n"); 2179 if (FLAG_trace_code_serializer) PrintF(" Encoding source object\n");
2180 2180
2181 DCHECK(how_to_code == kPlain && where_to_point == kStartOfObject); 2181 DCHECK(how_to_code == kPlain && where_to_point == kStartOfObject);
2182 sink_->Put(kAttachedReference + how_to_code + where_to_point, "Source"); 2182 sink_->Put(kAttachedReference + how_to_code + where_to_point, "Source");
2183 sink_->PutInt(kSourceObjectIndex, "kSourceObjectIndex"); 2183 sink_->PutInt(kSourceObjectIndex, "kSourceObjectIndex");
2184 } 2184 }
2185 2185
2186 2186
2187 MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize( 2187 MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
2188 Isolate* isolate, ScriptData* data, Handle<String> source) { 2188 Isolate* isolate, ScriptData* cached_data, Handle<String> source) {
2189 base::ElapsedTimer timer; 2189 base::ElapsedTimer timer;
2190 if (FLAG_profile_deserialization) timer.Start(); 2190 if (FLAG_profile_deserialization) timer.Start();
2191 2191
2192 Object* root; 2192 Object* root;
2193 2193
2194 { 2194 {
2195 HandleScope scope(isolate); 2195 HandleScope scope(isolate);
2196 2196
2197 SerializedCodeData scd(data, *source); 2197 SmartPointer<SerializedCodeData> scd(
2198 SnapshotByteSource payload(scd.Payload(), scd.PayloadLength()); 2198 SerializedCodeData::FromCachedData(cached_data, *source));
2199 if (scd.is_empty()) {
2200 if (FLAG_profile_deserialization) PrintF("[Cached code failed check]\n");
2201 DCHECK(cached_data->rejected());
2202 return MaybeHandle<SharedFunctionInfo>();
2203 }
2204 SnapshotByteSource payload(scd->Payload(), scd->PayloadLength());
2199 Deserializer deserializer(&payload); 2205 Deserializer deserializer(&payload);
2200 2206
2201 // Eagerly expand string table to avoid allocations during deserialization. 2207 // Eagerly expand string table to avoid allocations during deserialization.
2202 StringTable::EnsureCapacityForDeserialization(isolate, 2208 StringTable::EnsureCapacityForDeserialization(
2203 scd.NumInternalizedStrings()); 2209 isolate, scd->NumInternalizedStrings());
2204 2210
2205 // Set reservations. 2211 // Set reservations.
2206 STATIC_ASSERT(NEW_SPACE == 0); 2212 STATIC_ASSERT(NEW_SPACE == 0);
2207 int current_space = NEW_SPACE; 2213 int current_space = NEW_SPACE;
2208 Vector<const SerializedCodeData::Reservation> res = scd.Reservations(); 2214 Vector<const SerializedCodeData::Reservation> res = scd->Reservations();
2209 for (const auto& r : res) { 2215 for (const auto& r : res) {
2210 deserializer.AddReservation(current_space, r.chunk_size()); 2216 deserializer.AddReservation(current_space, r.chunk_size());
2211 if (r.is_last_chunk()) current_space++; 2217 if (r.is_last_chunk()) current_space++;
2212 } 2218 }
2213 DCHECK_EQ(kNumberOfSpaces, current_space); 2219 DCHECK_EQ(kNumberOfSpaces, current_space);
2214 2220
2215 // Prepare and register list of attached objects. 2221 // Prepare and register list of attached objects.
2216 Vector<const uint32_t> code_stub_keys = scd.CodeStubKeys(); 2222 Vector<const uint32_t> code_stub_keys = scd->CodeStubKeys();
2217 Vector<Handle<Object> > attached_objects = Vector<Handle<Object> >::New( 2223 Vector<Handle<Object> > attached_objects = Vector<Handle<Object> >::New(
2218 code_stub_keys.length() + kCodeStubsBaseIndex); 2224 code_stub_keys.length() + kCodeStubsBaseIndex);
2219 attached_objects[kSourceObjectIndex] = source; 2225 attached_objects[kSourceObjectIndex] = source;
2220 for (int i = 0; i < code_stub_keys.length(); i++) { 2226 for (int i = 0; i < code_stub_keys.length(); i++) {
2221 attached_objects[i + kCodeStubsBaseIndex] = 2227 attached_objects[i + kCodeStubsBaseIndex] =
2222 CodeStub::GetCode(isolate, code_stub_keys[i]).ToHandleChecked(); 2228 CodeStub::GetCode(isolate, code_stub_keys[i]).ToHandleChecked();
2223 } 2229 }
2224 deserializer.SetAttachedObjects(&attached_objects); 2230 deserializer.SetAttachedObjects(&attached_objects);
2225 2231
2226 // Deserialize. 2232 // Deserialize.
2227 deserializer.DeserializePartial(isolate, &root, Deserializer::NULL_ON_OOM); 2233 deserializer.DeserializePartial(isolate, &root, Deserializer::NULL_ON_OOM);
2228 if (root == NULL) { 2234 if (root == NULL) {
2229 // Deserializing may fail if the reservations cannot be fulfilled. 2235 // Deserializing may fail if the reservations cannot be fulfilled.
2230 if (FLAG_profile_deserialization) PrintF("[Deserializing failed]\n"); 2236 if (FLAG_profile_deserialization) PrintF("[Deserializing failed]\n");
2231 return MaybeHandle<SharedFunctionInfo>(); 2237 return MaybeHandle<SharedFunctionInfo>();
2232 } 2238 }
2233 deserializer.FlushICacheForNewCodeObjects(); 2239 deserializer.FlushICacheForNewCodeObjects();
2234 } 2240 }
2235 2241
2236 if (FLAG_profile_deserialization) { 2242 if (FLAG_profile_deserialization) {
2237 double ms = timer.Elapsed().InMillisecondsF(); 2243 double ms = timer.Elapsed().InMillisecondsF();
2238 int length = data->length(); 2244 int length = cached_data->length();
2239 PrintF("[Deserializing from %d bytes took %0.3f ms]\n", length, ms); 2245 PrintF("[Deserializing from %d bytes took %0.3f ms]\n", length, ms);
2240 } 2246 }
2241 Handle<SharedFunctionInfo> result(SharedFunctionInfo::cast(root), isolate); 2247 Handle<SharedFunctionInfo> result(SharedFunctionInfo::cast(root), isolate);
2242 result->set_deserialized(true); 2248 result->set_deserialized(true);
2243 2249
2244 if (isolate->logger()->is_logging_code_events() || 2250 if (isolate->logger()->is_logging_code_events() ||
2245 isolate->cpu_profiler()->is_profiling()) { 2251 isolate->cpu_profiler()->is_profiling()) {
2246 String* name = isolate->heap()->empty_string(); 2252 String* name = isolate->heap()->empty_string();
2247 if (result->script()->IsScript()) { 2253 if (result->script()->IsScript()) {
2248 Script* script = Script::cast(result->script()); 2254 Script* script = Script::cast(result->script());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2308 } 2314 }
2309 2315
2310 2316
2311 bool SerializedCodeData::IsSane(String* source) { 2317 bool SerializedCodeData::IsSane(String* source) {
2312 return GetHeaderValue(kCheckSumOffset) == CheckSum(source) && 2318 return GetHeaderValue(kCheckSumOffset) == CheckSum(source) &&
2313 PayloadLength() >= SharedFunctionInfo::kSize; 2319 PayloadLength() >= SharedFunctionInfo::kSize;
2314 } 2320 }
2315 2321
2316 2322
2317 int SerializedCodeData::CheckSum(String* string) { 2323 int SerializedCodeData::CheckSum(String* string) {
2318 int checksum = Version::Hash(); 2324 return Version::Hash() ^ string->length();
2319 #ifdef DEBUG
2320 uint32_t seed = static_cast<uint32_t>(checksum);
2321 checksum = static_cast<int>(IteratingStringHasher::Hash(string, seed));
2322 #endif // DEBUG
2323 return checksum;
2324 } 2325 }
2325 } } // namespace v8::internal 2326 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.h ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698