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

Side by Side Diff: src/snapshot/serialize.cc

Issue 1183483006: Serializer: clear string hash for code serializer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 6 months 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/snapshot/serialize.h ('k') | no next file » | 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 696 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 return handle(string_, isolate); 707 return handle(string_, isolate);
708 } 708 }
709 709
710 String* string_; 710 String* string_;
711 uint32_t hash_; 711 uint32_t hash_;
712 }; 712 };
713 713
714 714
715 HeapObject* Deserializer::PostProcessNewObject(HeapObject* obj, int space) { 715 HeapObject* Deserializer::PostProcessNewObject(HeapObject* obj, int space) {
716 if (deserializing_user_code()) { 716 if (deserializing_user_code()) {
717 if (obj->IsString()) { 717 if (obj->IsInternalizedString()) {
718 // Canonicalize the internalized string. If it already exists in the
719 // string table, set it to forward to the existing one.
720 DisallowHeapAllocation no_gc;
718 String* string = String::cast(obj); 721 String* string = String::cast(obj);
719 // Uninitialize hash field as the hash seed may have changed. 722 HandleScope scope(isolate_);
720 string->set_hash_field(String::kEmptyHashField); 723 StringTableInsertionKey key(string);
721 if (string->IsInternalizedString()) { 724 String* canonical = *StringTable::LookupKey(isolate_, &key);
722 // Canonicalize the internalized string. If it already exists in the 725 string->SetForwardedInternalizedString(canonical);
723 // string table, set it to forward to the existing one. 726 return canonical;
724 DisallowHeapAllocation no_gc;
725 HandleScope scope(isolate_);
726 StringTableInsertionKey key(string);
727 String* canonical = *StringTable::LookupKey(isolate_, &key);
728 string->SetForwardedInternalizedString(canonical);
729 return canonical;
730 }
731 } else if (obj->IsScript()) { 727 } else if (obj->IsScript()) {
732 // Assign a new script id to avoid collision. 728 // Assign a new script id to avoid collision.
733 Script::cast(obj)->set_id(isolate_->heap()->NextScriptId()); 729 Script::cast(obj)->set_id(isolate_->heap()->NextScriptId());
734 } else { 730 } else {
735 DCHECK(CanBeDeferred(obj)); 731 DCHECK(CanBeDeferred(obj));
736 } 732 }
737 } 733 }
738 if (obj->IsAllocationSite()) { 734 if (obj->IsAllocationSite()) {
739 DCHECK(obj->IsAllocationSite()); 735 DCHECK(obj->IsAllocationSite());
740 // Allocation sites are present in the snapshot, and must be linked into 736 // Allocation sites are present in the snapshot, and must be linked into
(...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after
2297 // We expect no instantiated function objects or contexts. 2293 // We expect no instantiated function objects or contexts.
2298 CHECK(!obj->IsJSFunction() && !obj->IsContext()); 2294 CHECK(!obj->IsJSFunction() && !obj->IsContext());
2299 2295
2300 SerializeGeneric(obj, how_to_code, where_to_point); 2296 SerializeGeneric(obj, how_to_code, where_to_point);
2301 } 2297 }
2302 2298
2303 2299
2304 void CodeSerializer::SerializeGeneric(HeapObject* heap_object, 2300 void CodeSerializer::SerializeGeneric(HeapObject* heap_object,
2305 HowToCode how_to_code, 2301 HowToCode how_to_code,
2306 WhereToPoint where_to_point) { 2302 WhereToPoint where_to_point) {
2307 if (heap_object->IsInternalizedString()) num_internalized_strings_++; 2303 int string_hash = String::kEmptyHashField;
2304 if (heap_object->IsString()) {
2305 String* string = String::cast(heap_object);
2306 if (string->IsInternalizedString()) num_internalized_strings_++;
2307 // Temporarily clear string hash.
2308 string_hash = string->hash_field();
2309 string->set_hash_field(String::kEmptyHashField);
2310 }
2308 2311
2309 // Object has not yet been serialized. Serialize it here. 2312 // Object has not yet been serialized. Serialize it here.
2310 ObjectSerializer serializer(this, heap_object, sink_, how_to_code, 2313 ObjectSerializer serializer(this, heap_object, sink_, how_to_code,
2311 where_to_point); 2314 where_to_point);
2312 serializer.Serialize(); 2315 serializer.Serialize();
2316
2317 if (string_hash != String::kEmptyHashField) {
2318 // Restore string hash.
2319 String::cast(heap_object)->set_hash_field(String::kEmptyHashField);
2320 }
2313 } 2321 }
2314 2322
2315 2323
2316 void CodeSerializer::SerializeBuiltin(int builtin_index, HowToCode how_to_code, 2324 void CodeSerializer::SerializeBuiltin(int builtin_index, HowToCode how_to_code,
2317 WhereToPoint where_to_point) { 2325 WhereToPoint where_to_point) {
2318 DCHECK((how_to_code == kPlain && where_to_point == kStartOfObject) || 2326 DCHECK((how_to_code == kPlain && where_to_point == kStartOfObject) ||
2319 (how_to_code == kPlain && where_to_point == kInnerPointer) || 2327 (how_to_code == kPlain && where_to_point == kInnerPointer) ||
2320 (how_to_code == kFromCode && where_to_point == kInnerPointer)); 2328 (how_to_code == kFromCode && where_to_point == kInnerPointer));
2321 DCHECK_LT(builtin_index, Builtins::builtin_count); 2329 DCHECK_LT(builtin_index, Builtins::builtin_count);
2322 DCHECK_LE(0, builtin_index); 2330 DCHECK_LE(0, builtin_index);
(...skipping 367 matching lines...) Expand 10 before | Expand all | Expand 10 after
2690 SerializedCodeData* scd = new SerializedCodeData(cached_data); 2698 SerializedCodeData* scd = new SerializedCodeData(cached_data);
2691 SanityCheckResult r = scd->SanityCheck(isolate, source); 2699 SanityCheckResult r = scd->SanityCheck(isolate, source);
2692 if (r == CHECK_SUCCESS) return scd; 2700 if (r == CHECK_SUCCESS) return scd;
2693 cached_data->Reject(); 2701 cached_data->Reject();
2694 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r); 2702 source->GetIsolate()->counters()->code_cache_reject_reason()->AddSample(r);
2695 delete scd; 2703 delete scd;
2696 return NULL; 2704 return NULL;
2697 } 2705 }
2698 } // namespace internal 2706 } // namespace internal
2699 } // namespace v8 2707 } // namespace v8
OLDNEW
« no previous file with comments | « src/snapshot/serialize.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698