Reviewers: jochen,

Description:
Serializer: clear string hash for code serializer.

[email protected]
BUG=v8:4179
LOG=N

Please review this at https://codereview.chromium.org/1183483006/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+23, -15 lines):
  M src/snapshot/serialize.h
  M src/snapshot/serialize.cc


Index: src/snapshot/serialize.cc
diff --git a/src/snapshot/serialize.cc b/src/snapshot/serialize.cc
index 57092e1b46238336fff16a11e9a510324fbceea4..8b382c09fb1a3c047a1c22f02dd2dc3ad9703b42 100644
--- a/src/snapshot/serialize.cc
+++ b/src/snapshot/serialize.cc
@@ -714,20 +714,16 @@ class StringTableInsertionKey : public HashTableKey {

HeapObject* Deserializer::PostProcessNewObject(HeapObject* obj, int space) {
   if (deserializing_user_code()) {
-    if (obj->IsString()) {
+    if (obj->IsInternalizedString()) {
+      // Canonicalize the internalized string. If it already exists in the
+      // string table, set it to forward to the existing one.
+      DisallowHeapAllocation no_gc;
       String* string = String::cast(obj);
-      // Uninitialize hash field as the hash seed may have changed.
-      string->set_hash_field(String::kEmptyHashField);
-      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;
-      }
+      HandleScope scope(isolate_);
+      StringTableInsertionKey key(string);
+      String* canonical = *StringTable::LookupKey(isolate_, &key);
+      string->SetForwardedInternalizedString(canonical);
+      return canonical;
     } else if (obj->IsScript()) {
       // Assign a new script id to avoid collision.
       Script::cast(obj)->set_id(isolate_->heap()->NextScriptId());
@@ -2304,12 +2300,24 @@ 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_++;
+  int string_hash = String::kEmptyHashField;
+  if (heap_object->IsString()) {
+    String* string = String::cast(heap_object);
+    if (string->IsInternalizedString()) num_internalized_strings_++;
+    // Temporarily clear string hash.
+    string_hash = string->hash_field();
+    string->set_hash_field(String::kEmptyHashField);
+  }

   // Object has not yet been serialized.  Serialize it here.
   ObjectSerializer serializer(this, heap_object, sink_, how_to_code,
                               where_to_point);
   serializer.Serialize();
+
+  if (string_hash != String::kEmptyHashField) {
+    // Restore string hash.
+    String::cast(heap_object)->set_hash_field(String::kEmptyHashField);
+  }
 }


Index: src/snapshot/serialize.h
diff --git a/src/snapshot/serialize.h b/src/snapshot/serialize.h
index 775658285835248bf116f776cb9b6d2da72feb2b..089c323b7de7db8588fc666e43e27a1528cdf4d9 100644
--- a/src/snapshot/serialize.h
+++ b/src/snapshot/serialize.h
@@ -307,7 +307,7 @@ class SerializerDeserializer: public ObjectVisitor {

  protected:
   static bool CanBeDeferred(HeapObject* o) {
-    return !o->IsString() && !o->IsScript();
+    return !o->IsInternalizedString() && !o->IsScript();
   }

   // ---------- byte code range 0x00..0x7f ----------


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to