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

Unified Diff: src/snapshot/serialize.cc

Issue 1204863006: Serializer: commit new internalized strings after deserialization. (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/snapshot/serialize.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/snapshot/serialize.cc
diff --git a/src/snapshot/serialize.cc b/src/snapshot/serialize.cc
index 66da378617571ccb915303bb828cd01fe0e8448d..c466128545c74de8a647bcbd08900d10f963d80d 100644
--- a/src/snapshot/serialize.cc
+++ b/src/snapshot/serialize.cc
@@ -642,11 +642,18 @@ MaybeHandle<SharedFunctionInfo> Deserializer::DeserializeCode(
return Handle<SharedFunctionInfo>();
} else {
deserializing_user_code_ = true;
- DisallowHeapAllocation no_gc;
- Object* root;
- VisitPointer(&root);
- DeserializeDeferredObjects();
- return Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(root));
+ NewInternalizedStrings new_internalized_strings(isolate);
+ new_internalized_strings_ = &new_internalized_strings;
+ Handle<SharedFunctionInfo> result;
+ {
+ DisallowHeapAllocation no_gc;
+ Object* root;
+ VisitPointer(&root);
+ DeserializeDeferredObjects();
+ result = Handle<SharedFunctionInfo>(SharedFunctionInfo::cast(root));
+ }
+ new_internalized_strings.Commit(isolate);
+ return result;
}
}
@@ -711,8 +718,10 @@ class StringTableInsertionKey : public HashTableKey {
return handle(string_, isolate);
}
+ private:
String* string_;
uint32_t hash_;
+ DisallowHeapAllocation no_gc;
};
@@ -725,12 +734,15 @@ HeapObject* Deserializer::PostProcessNewObject(HeapObject* obj, int space) {
if (string->IsInternalizedString()) {
// Canonicalize the internalized string. If it already exists in the
// string table, set it to forward to the existing one.
- DisallowHeapAllocation no_gc;
- HandleScope scope(isolate_);
StringTableInsertionKey key(string);
- String* canonical = *StringTable::LookupKey(isolate_, &key);
- string->SetForwardedInternalizedString(canonical);
- return canonical;
+ String* canonical = StringTable::LookupKeyIfExists(isolate_, &key);
+ if (canonical == NULL) {
+ new_internalized_strings_->Add(string);
+ return string;
+ } else {
+ string->SetForwardedInternalizedString(canonical);
+ return canonical;
+ }
}
} else if (obj->IsScript()) {
// Assign a new script id to avoid collision.
@@ -767,6 +779,16 @@ HeapObject* Deserializer::PostProcessNewObject(HeapObject* obj, int space) {
}
+void Deserializer::NewInternalizedStrings::Commit(Isolate* isolate) {
ulan 2015/06/25 09:49:42 Please handlify strings before ensuring capacity,
+ StringTable::EnsureCapacityForDeserialization(isolate, strings_.length());
+ for (String* string : strings_) {
+ StringTableInsertionKey key(string);
+ DCHECK_NULL(StringTable::LookupKeyIfExists(isolate, &key));
+ StringTable::LookupKey(isolate, &key);
+ }
+}
+
+
HeapObject* Deserializer::GetBackReferencedObject(int space) {
HeapObject* obj;
BackReference back_reference(source_.GetInt());
@@ -2348,8 +2370,6 @@ void CodeSerializer::SerializeObject(HeapObject* obj, HowToCode how_to_code,
void CodeSerializer::SerializeGeneric(HeapObject* heap_object,
HowToCode how_to_code,
WhereToPoint where_to_point) {
- if (heap_object->IsInternalizedString()) num_internalized_strings_++;
-
// Object has not yet been serialized. Serialize it here.
ObjectSerializer serializer(this, heap_object, sink_, how_to_code,
where_to_point);
@@ -2471,10 +2491,6 @@ MaybeHandle<SharedFunctionInfo> CodeSerializer::Deserialize(
CodeStub::GetCode(isolate, code_stub_keys[i]).ToHandleChecked();
}
- // Eagerly expand string table to avoid allocations during deserialization.
- StringTable::EnsureCapacityForDeserialization(isolate,
- scd->NumInternalizedStrings());
-
Deserializer deserializer(scd.get());
deserializer.SetAttachedObjects(attached_objects);
@@ -2633,7 +2649,6 @@ SerializedCodeData::SerializedCodeData(const List<byte>& payload,
SetHeaderValue(kCpuFeaturesOffset,
static_cast<uint32_t>(CpuFeatures::SupportedFeatures()));
SetHeaderValue(kFlagHashOffset, FlagList::Hash());
- SetHeaderValue(kNumInternalizedStringsOffset, cs.num_internalized_strings());
SetHeaderValue(kNumReservationsOffset, reservations.length());
SetHeaderValue(kNumCodeStubKeysOffset, num_stub_keys);
SetHeaderValue(kPayloadLengthOffset, payload.length());
@@ -2711,10 +2726,6 @@ Vector<const byte> SerializedCodeData::Payload() const {
}
-int SerializedCodeData::NumInternalizedStrings() const {
- return GetHeaderValue(kNumInternalizedStringsOffset);
-}
-
Vector<const uint32_t> SerializedCodeData::CodeStubKeys() const {
int reservations_size = GetHeaderValue(kNumReservationsOffset) * kInt32Size;
const byte* start = data_ + kHeaderSize + reservations_size;
« 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