Reviewers: Jakob,

Message:
PTAL

Description:
Make Map::Create always use the Object function, and remove the unused inobject
properties

BUG=

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

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+26, -33 lines):
  M src/bootstrapper.cc
  M src/factory.cc
  M src/objects.h
  M src/objects.cc
  M src/runtime.cc
  M test/cctest/test-heap.cc


Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index 65b21e09bc5fbe43a5029c05894238ee20aaf97d..250562a2aa17a0a8c47dfc8567b449b5ccade0f0 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1156,7 +1156,11 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> global_object,
     STATIC_ASSERT(JSGeneratorObject::kResultPropertyCount == 2);
Handle<JSFunction> object_function(native_context()->object_function());
     Handle<Map> iterator_result_map =
- Map::Create(object_function, JSGeneratorObject::kResultPropertyCount);
+        Map::Create(isolate, JSGeneratorObject::kResultPropertyCount);
+    DCHECK_EQ(JSGeneratorObject::kResultSize,
+              iterator_result_map->instance_size());
+    DCHECK_EQ(JSGeneratorObject::kResultPropertyCount,
+              iterator_result_map->inobject_properties());
     Map::EnsureDescriptorSlack(iterator_result_map,
                                JSGeneratorObject::kResultPropertyCount);

@@ -1170,14 +1174,9 @@ void Genesis::InitializeGlobal(Handle<GlobalObject> global_object,
                                NONE, Representation::Tagged());
     iterator_result_map->AppendDescriptor(&done_descr);

-    iterator_result_map->set_instance_size(JSGeneratorObject::kResultSize);
     iterator_result_map->set_unused_property_fields(0);
-    iterator_result_map->set_inobject_properties(
-        JSGeneratorObject::kResultPropertyCount);
     iterator_result_map->set_pre_allocated_property_fields(
         JSGeneratorObject::kResultPropertyCount);
-    iterator_result_map->set_visitor_id(
-        StaticVisitorBase::GetVisitorId(*iterator_result_map));
     DCHECK_EQ(JSGeneratorObject::kResultSize,
               iterator_result_map->instance_size());
     native_context()->set_iterator_result_map(*iterator_result_map);
@@ -1929,8 +1928,7 @@ bool Genesis::InstallNatives() {
         *strict_generator_function_map);

Handle<JSFunction> object_function(native_context()->object_function());
-    Handle<Map> generator_object_prototype_map =
-        Map::Create(object_function, 0);
+    Handle<Map> generator_object_prototype_map = Map::Create(isolate(), 0);
generator_object_prototype_map->set_prototype(*generator_object_prototype);
     native_context()->set_generator_object_prototype_map(
         *generator_object_prototype_map);
Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index 4e5b5592dd2b8307af94869e577462c629be849d..45a79c1b3cc4477be0bdc3cfdc4825ba35cd1e1a 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -2331,9 +2331,9 @@ Handle<Map> Factory::ObjectLiteralMapFromCache(Handle<Context> context,
   int length = keys->length();
   // Create a new map and add it to the cache. Reuse the initial map of the
   // Object function if the literal has no predeclared properties.
-  Handle<Map> map =
-      length == 0 ? handle(context->object_function()->initial_map())
- : Map::Create(handle(context->object_function()), length);
+  Handle<Map> map = length == 0
+                        ? handle(context->object_function()->initial_map())
+                        : Map::Create(isolate(), length);
   AddToMapCache(context, keys, map);
   return map;
 }
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index d645b4efc009e018c28a7ba98ab8f9ed9358da1a..cc685577ce37cb029d57c98fb058bcd919fcc3bc 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -6660,30 +6660,26 @@ Handle<Map> Map::Copy(Handle<Map> map) {
 }


-Handle<Map> Map::Create(Handle<JSFunction> constructor,
-                        int extra_inobject_properties) {
-  Handle<Map> copy = Copy(handle(constructor->initial_map()));
+Handle<Map> Map::Create(Isolate* isolate, int inobject_properties) {
+ Handle<Map> copy = Copy(handle(isolate->object_function()->initial_map()));

-  // Check that we do not overflow the instance size when adding the
-  // extra inobject properties.
-  int instance_size_delta = extra_inobject_properties * kPointerSize;
-  int max_instance_size_delta =
-      JSObject::kMaxInstanceSize - copy->instance_size();
-  int max_extra_properties = max_instance_size_delta >> kPointerSizeLog2;
+  // Check that we do not overflow the instance size when adding the extra
+ // inobject properties. If the instance size overflows, we allocate as many
+  // properties as we can as inobject properties.
+  int max_extra_properties =
+ (JSObject::kMaxInstanceSize - JSObject::kHeaderSize) >> kPointerSizeLog2;

- // If the instance size overflows, we allocate as many properties as we can as
-  // inobject properties.
-  if (extra_inobject_properties > max_extra_properties) {
-    instance_size_delta = max_instance_size_delta;
-    extra_inobject_properties = max_extra_properties;
+  if (inobject_properties > max_extra_properties) {
+    inobject_properties = max_extra_properties;
   }

+  int new_instance_size =
+      JSObject::kHeaderSize + kPointerSize * inobject_properties;
+
   // Adjust the map with the extra inobject properties.
-  int inobject_properties =
-      copy->inobject_properties() + extra_inobject_properties;
   copy->set_inobject_properties(inobject_properties);
   copy->set_unused_property_fields(inobject_properties);
-  copy->set_instance_size(copy->instance_size() + instance_size_delta);
+  copy->set_instance_size(new_instance_size);
   copy->set_visitor_id(StaticVisitorBase::GetVisitorId(*copy));
   return copy;
 }
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index a2f9c80b0e61ad2c79c6125e1736cf0c4139ab69..d88240d370db6e49f265a137e6ce1fcec69d202b 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -6379,8 +6379,7 @@ class Map: public HeapObject {
   // Returns a copy of the map, with all transitions dropped from the
   // instance descriptors.
   static Handle<Map> Copy(Handle<Map> map);
-  static Handle<Map> Create(Handle<JSFunction> constructor,
-                            int extra_inobject_properties);
+  static Handle<Map> Create(Isolate* isolate, int inobject_properties);

   // Returns the next free property index (only valid for FAST MODE).
   int NextFreePropertyIndex();
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 45dd9a4cd5128abfdf2e42c1d5ba5fc12d5684a0..3acbb81d89dff0c0d2c21003762bb785c6a7df85 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -207,7 +207,7 @@ static Handle<Map> ComputeObjectLiteralMap(
     return isolate->factory()->ObjectLiteralMapFromCache(context, keys);
   }
   *is_result_from_cache = false;
- return Map::Create(handle(context->object_function()), number_of_properties);
+  return Map::Create(isolate, number_of_properties);
 }


Index: test/cctest/test-heap.cc
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
index baa1e30b366ccc11f75fdf607616a883df063527..cbb113912355bf4976626e31fc973e82ab8d6756 100644
--- a/test/cctest/test-heap.cc
+++ b/test/cctest/test-heap.cc
@@ -996,7 +996,7 @@ TEST(Regression39128) {
       CcTest::i_isolate()->native_context()->object_function());
   CHECK(object_ctor->has_initial_map());
   // Create a map with single inobject property.
-  Handle<Map> my_map = Map::Create(object_ctor, 1);
+  Handle<Map> my_map = Map::Create(CcTest::i_isolate(), 1);
   int n_properties = my_map->inobject_properties();
   CHECK_GT(n_properties, 0);

@@ -4461,7 +4461,7 @@ TEST(Regress388880) {
   Factory* factory = isolate->factory();
   Heap* heap = isolate->heap();

-  Handle<Map> map1 = Map::Create(isolate->object_function(), 1);
+  Handle<Map> map1 = Map::Create(isolate, 1);
   Handle<Map> map2 =
       Map::CopyWithField(map1, factory->NewStringFromStaticChars("foo"),
HeapType::Any(isolate), NONE, Representation::Tagged(),


--
--
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