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

Side by Side Diff: src/serialize.cc

Issue 724053004: Revert "Soft fail for invalid cache data." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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* cached_data, Handle<String> source) { 2188 Isolate* isolate, ScriptData* 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 = 2197 SerializedCodeData scd(data, *source);
2198 SerializedCodeData::FromCachedData(cached_data, *source); 2198 SnapshotByteSource payload(scd.Payload(), scd.PayloadLength());
2199 if (scd == NULL) {
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());
2205 Deserializer deserializer(&payload); 2199 Deserializer deserializer(&payload);
2206 2200
2207 // Eagerly expand string table to avoid allocations during deserialization. 2201 // Eagerly expand string table to avoid allocations during deserialization.
2208 StringTable::EnsureCapacityForDeserialization( 2202 StringTable::EnsureCapacityForDeserialization(isolate,
2209 isolate, scd->NumInternalizedStrings()); 2203 scd.NumInternalizedStrings());
2210 2204
2211 // Set reservations. 2205 // Set reservations.
2212 STATIC_ASSERT(NEW_SPACE == 0); 2206 STATIC_ASSERT(NEW_SPACE == 0);
2213 int current_space = NEW_SPACE; 2207 int current_space = NEW_SPACE;
2214 Vector<const SerializedCodeData::Reservation> res = scd->Reservations(); 2208 Vector<const SerializedCodeData::Reservation> res = scd.Reservations();
2215 for (const auto& r : res) { 2209 for (const auto& r : res) {
2216 deserializer.AddReservation(current_space, r.chunk_size()); 2210 deserializer.AddReservation(current_space, r.chunk_size());
2217 if (r.is_last_chunk()) current_space++; 2211 if (r.is_last_chunk()) current_space++;
2218 } 2212 }
2219 DCHECK_EQ(kNumberOfSpaces, current_space); 2213 DCHECK_EQ(kNumberOfSpaces, current_space);
2220 2214
2221 // Prepare and register list of attached objects. 2215 // Prepare and register list of attached objects.
2222 Vector<const uint32_t> code_stub_keys = scd->CodeStubKeys(); 2216 Vector<const uint32_t> code_stub_keys = scd.CodeStubKeys();
2223 Vector<Handle<Object> > attached_objects = Vector<Handle<Object> >::New( 2217 Vector<Handle<Object> > attached_objects = Vector<Handle<Object> >::New(
2224 code_stub_keys.length() + kCodeStubsBaseIndex); 2218 code_stub_keys.length() + kCodeStubsBaseIndex);
2225 attached_objects[kSourceObjectIndex] = source; 2219 attached_objects[kSourceObjectIndex] = source;
2226 for (int i = 0; i < code_stub_keys.length(); i++) { 2220 for (int i = 0; i < code_stub_keys.length(); i++) {
2227 attached_objects[i + kCodeStubsBaseIndex] = 2221 attached_objects[i + kCodeStubsBaseIndex] =
2228 CodeStub::GetCode(isolate, code_stub_keys[i]).ToHandleChecked(); 2222 CodeStub::GetCode(isolate, code_stub_keys[i]).ToHandleChecked();
2229 } 2223 }
2230 deserializer.SetAttachedObjects(&attached_objects); 2224 deserializer.SetAttachedObjects(&attached_objects);
2231 2225
2232 // Deserialize. 2226 // Deserialize.
2233 deserializer.DeserializePartial(isolate, &root, Deserializer::NULL_ON_OOM); 2227 deserializer.DeserializePartial(isolate, &root, Deserializer::NULL_ON_OOM);
2234 if (root == NULL) { 2228 if (root == NULL) {
2235 // Deserializing may fail if the reservations cannot be fulfilled. 2229 // Deserializing may fail if the reservations cannot be fulfilled.
2236 if (FLAG_profile_deserialization) PrintF("[Deserializing failed]\n"); 2230 if (FLAG_profile_deserialization) PrintF("[Deserializing failed]\n");
2237 return MaybeHandle<SharedFunctionInfo>(); 2231 return MaybeHandle<SharedFunctionInfo>();
2238 } 2232 }
2239 deserializer.FlushICacheForNewCodeObjects(); 2233 deserializer.FlushICacheForNewCodeObjects();
2240 } 2234 }
2241 2235
2242 if (FLAG_profile_deserialization) { 2236 if (FLAG_profile_deserialization) {
2243 double ms = timer.Elapsed().InMillisecondsF(); 2237 double ms = timer.Elapsed().InMillisecondsF();
2244 int length = cached_data->length(); 2238 int length = data->length();
2245 PrintF("[Deserializing from %d bytes took %0.3f ms]\n", length, ms); 2239 PrintF("[Deserializing from %d bytes took %0.3f ms]\n", length, ms);
2246 } 2240 }
2247 Handle<SharedFunctionInfo> result(SharedFunctionInfo::cast(root), isolate); 2241 Handle<SharedFunctionInfo> result(SharedFunctionInfo::cast(root), isolate);
2248 result->set_deserialized(true); 2242 result->set_deserialized(true);
2249 2243
2250 if (isolate->logger()->is_logging_code_events() || 2244 if (isolate->logger()->is_logging_code_events() ||
2251 isolate->cpu_profiler()->is_profiling()) { 2245 isolate->cpu_profiler()->is_profiling()) {
2252 String* name = isolate->heap()->empty_string(); 2246 String* name = isolate->heap()->empty_string();
2253 if (result->script()->IsScript()) { 2247 if (result->script()->IsScript()) {
2254 Script* script = Script::cast(result->script()); 2248 Script* script = Script::cast(result->script());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
2314 } 2308 }
2315 2309
2316 2310
2317 bool SerializedCodeData::IsSane(String* source) { 2311 bool SerializedCodeData::IsSane(String* source) {
2318 return GetHeaderValue(kCheckSumOffset) == CheckSum(source) && 2312 return GetHeaderValue(kCheckSumOffset) == CheckSum(source) &&
2319 PayloadLength() >= SharedFunctionInfo::kSize; 2313 PayloadLength() >= SharedFunctionInfo::kSize;
2320 } 2314 }
2321 2315
2322 2316
2323 int SerializedCodeData::CheckSum(String* string) { 2317 int SerializedCodeData::CheckSum(String* string) {
2324 return Version::Hash() ^ string->length(); 2318 int checksum = Version::Hash();
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;
2325 } 2324 }
2326 } } // namespace v8::internal 2325 } } // 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