Revision: 12202
Author:   [email protected]
Date:     Thu Jul 26 06:48:34 2012
Log:      Set LastAdded to kNoneAdded in RawCopy.

This ensures it is properly initialized if no descriptors are later set.

Review URL: https://chromiumcodereview.appspot.com/10833033
http://code.google.com/p/v8/source/detail?r=12202

Modified:
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/objects-inl.h
 /branches/bleeding_edge/src/objects.cc

=======================================
--- /branches/bleeding_edge/src/heap.cc Fri Jul 20 07:06:24 2012
+++ /branches/bleeding_edge/src/heap.cc Thu Jul 26 06:48:34 2012
@@ -4125,13 +4125,11 @@
int initial_size = map->instance_type() == JS_GLOBAL_OBJECT_TYPE ? 64 : 512;

   // Allocate a dictionary object for backing storage.
-  Object* obj;
-  { MaybeObject* maybe_obj =
-        StringDictionary::Allocate(
-            map->NumberOfDescribedProperties() * 2 + initial_size);
-    if (!maybe_obj->ToObject(&obj)) return maybe_obj;
-  }
-  StringDictionary* dictionary = StringDictionary::cast(obj);
+  StringDictionary* dictionary;
+  MaybeObject* maybe_dictionary =
+      StringDictionary::Allocate(
+          map->NumberOfDescribedProperties() * 2 + initial_size);
+  if (!maybe_dictionary->To(&dictionary)) return maybe_dictionary;

// The global object might be created from an object template with accessors.
   // Fill these accessors into the dictionary.
@@ -4142,29 +4140,26 @@
     PropertyDetails d =
         PropertyDetails(details.attributes(), CALLBACKS, details.index());
     Object* value = descs->GetCallbacksObject(i);
-    { MaybeObject* maybe_value = AllocateJSGlobalPropertyCell(value);
-      if (!maybe_value->ToObject(&value)) return maybe_value;
-    }
-
-    Object* result;
- { MaybeObject* maybe_result = dictionary->Add(descs->GetKey(i), value, d);
-      if (!maybe_result->ToObject(&result)) return maybe_result;
-    }
-    dictionary = StringDictionary::cast(result);
+    MaybeObject* maybe_value = AllocateJSGlobalPropertyCell(value);
+    if (!maybe_value->ToObject(&value)) return maybe_value;
+
+    MaybeObject* maybe_added = dictionary->Add(descs->GetKey(i), value, d);
+    if (!maybe_added->To(&dictionary)) return maybe_added;
   }

   // Allocate the global object and initialize it with the backing store.
-  { MaybeObject* maybe_obj = Allocate(map, OLD_POINTER_SPACE);
-    if (!maybe_obj->ToObject(&obj)) return maybe_obj;
-  }
-  JSObject* global = JSObject::cast(obj);
+  JSObject* global;
+  MaybeObject* maybe_global = Allocate(map, OLD_POINTER_SPACE);
+  if (!maybe_global->To(&global)) return maybe_global;
+
   InitializeJSObjectFromMap(global, dictionary, map);

   // Create a new map for the global object.
   Map* new_map;
-  { MaybeObject* maybe_map = map->CopyDropDescriptors();
-    if (!maybe_map->To(&new_map)) return maybe_map;
-  }
+  MaybeObject* maybe_map = map->CopyDropDescriptors();
+  if (!maybe_map->To(&new_map)) return maybe_map;
+
+  ASSERT(new_map->LastAdded() == Map::kNoneAdded);

   // Set up the global object as a normalized object.
   global->set_map(new_map);
=======================================
--- /branches/bleeding_edge/src/objects-inl.h   Thu Jul 26 01:27:20 2012
+++ /branches/bleeding_edge/src/objects-inl.h   Thu Jul 26 06:48:34 2012
@@ -3523,7 +3523,7 @@
     }
   }

-  ASSERT(len == 0 ||
+  ASSERT((len == 0 && LastAdded() == kNoneAdded) ||
          len == descriptors->GetDetails(LastAdded()).index());
 }

=======================================
--- /branches/bleeding_edge/src/objects.cc      Thu Jul 26 01:27:20 2012
+++ /branches/bleeding_edge/src/objects.cc      Thu Jul 26 06:48:34 2012
@@ -4805,16 +4805,16 @@

 MaybeObject* Map::RawCopy(int instance_size) {
   Map* result;
-  { MaybeObject* maybe_result =
-        GetHeap()->AllocateMap(instance_type(), instance_size);
-    if (!maybe_result->To(&result)) return maybe_result;
-  }
+  MaybeObject* maybe_result =
+      GetHeap()->AllocateMap(instance_type(), instance_size);
+  if (!maybe_result->To(&result)) return maybe_result;

   result->set_prototype(prototype());
   result->set_constructor(constructor());
   result->set_bit_field(bit_field());
   result->set_bit_field2(bit_field2());
   result->set_bit_field3(bit_field3());
+  result->SetLastAdded(kNoneAdded);
   return result;
 }

@@ -4834,12 +4834,11 @@
     result->set_inobject_properties(inobject_properties());
   }

-  result->SetLastAdded(kNoneAdded);
   result->set_code_cache(code_cache());
   result->set_is_shared(sharing == SHARED_NORMALIZED_MAP);

 #ifdef DEBUG
-  if (FLAG_verify_heap && Map::cast(result)->is_shared()) {
+  if (FLAG_verify_heap && result->is_shared()) {
     result->SharedMapVerify();
   }
 #endif
@@ -4938,9 +4937,7 @@
       initial_descriptors->Copy(DescriptorArray::MAY_BE_SHARED);
   if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors;

-  int last_added = initial_descriptors->IsEmpty()
-      ? kNoneAdded
-      : initial_map->LastAdded();
+  int last_added = initial_map->LastAdded();

return CopyReplaceDescriptors(descriptors, NULL, last_added, OMIT_TRANSITION);
 }
@@ -4952,7 +4949,7 @@
   MaybeObject* maybe_descriptors = source_descriptors->Copy(shared_mode);
   if (!maybe_descriptors->To(&descriptors)) return maybe_descriptors;

- int last_added = source_descriptors->IsEmpty() ? kNoneAdded : LastAdded();
+  int last_added = LastAdded();

return CopyReplaceDescriptors(descriptors, NULL, last_added, OMIT_TRANSITION);
 }

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to