Reviewers: rossberg,

Message:
rossberg@: PTAL.
rafaelw@: FYI.

Description:
Handlify Heap::AllocateInitialMap method.

[email protected]
BUG=v8:2877

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

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

Affected files (+36, -56 lines):
  M src/factory.h
  M src/factory.cc
  M src/heap.h
  M src/heap.cc
  M src/objects.cc


Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index fb14663341c604a7ba546a4cd5a3b91904546386..69a41692c4fa991a290d9cc19db5f9f03d3a4ff6 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -580,12 +580,6 @@ Handle<JSObject> Factory::NewFunctionPrototype(Handle<JSFunction> function) {
 }


-Handle<Map> Factory::NewInitialMap(Handle<JSFunction> function) {
-  CALL_HEAP_FUNCTION(
-      isolate(), isolate()->heap()->AllocateInitialMap(*function), Map);
-}
-
-
Handle<Map> Factory::CopyWithPreallocatedFieldDescriptors(Handle<Map> src) {
   CALL_HEAP_FUNCTION(
       isolate(), src->CopyWithPreallocatedFieldDescriptors(), Map);
Index: src/factory.h
diff --git a/src/factory.h b/src/factory.h
index e5b8ce6de4276d474a511f33351c3687f4619103..94feed24a2adde61ae6666158f0a4eefb523c627 100644
--- a/src/factory.h
+++ b/src/factory.h
@@ -261,8 +261,6 @@ class Factory {

   Handle<JSObject> NewFunctionPrototype(Handle<JSFunction> function);

-  Handle<Map> NewInitialMap(Handle<JSFunction> function);
-
   Handle<Map> CopyWithPreallocatedFieldDescriptors(Handle<Map> map);

   // Copy the map adding more inobject properties if possible without
Index: src/heap.cc
diff --git a/src/heap.cc b/src/heap.cc
index 8737c574b2d1d83e13722bc3d1b614c2f04c88aa..5f9bd38f07d9ccaf29d81252a5d873f6fbf7bc08 100644
--- a/src/heap.cc
+++ b/src/heap.cc
@@ -4458,48 +4458,6 @@ MaybeObject* Heap::AllocateArgumentsObject(Object* callee, int length) {
 }


-MaybeObject* Heap::AllocateInitialMap(JSFunction* fun) {
-  ASSERT(!fun->has_initial_map());
-
- // First create a new map with the size and number of in-object properties
-  // suggested by the function.
-  InstanceType instance_type;
-  int instance_size;
-  int in_object_properties;
-  if (fun->shared()->is_generator()) {
-    instance_type = JS_GENERATOR_OBJECT_TYPE;
-    instance_size = JSGeneratorObject::kSize;
-    in_object_properties = 0;
-  } else {
-    instance_type = JS_OBJECT_TYPE;
-    instance_size = fun->shared()->CalculateInstanceSize();
-    in_object_properties = fun->shared()->CalculateInObjectProperties();
-  }
-  Map* map;
-  MaybeObject* maybe_map = AllocateMap(instance_type, instance_size);
-  if (!maybe_map->To(&map)) return maybe_map;
-
-  // Fetch or allocate prototype.
-  Object* prototype;
-  if (fun->has_instance_prototype()) {
-    prototype = fun->instance_prototype();
-  } else {
-    MaybeObject* maybe_prototype = AllocateFunctionPrototype(fun);
-    if (!maybe_prototype->To(&prototype)) return maybe_prototype;
-  }
-  map->set_inobject_properties(in_object_properties);
-  map->set_unused_property_fields(in_object_properties);
-  map->set_prototype(prototype);
-  ASSERT(map->has_fast_object_elements());
-
-  if (!fun->shared()->is_generator()) {
-    fun->shared()->StartInobjectSlackTracking(map);
-  }
-
-  return map;
-}
-
-
 void Heap::InitializeJSObjectFromMap(JSObject* obj,
                                      FixedArray* properties,
                                      Map* map) {
Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index ca9c1e6a03b132ef079c302b431de9e9936cfc8c..7e9cb4751634d68935403f26bf2d623a7e554c73 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -737,9 +737,6 @@ class Heap {
MUST_USE_RESULT MaybeObject* AllocatePartialMap(InstanceType instance_type,
                                                   int instance_size);

-  // Allocate a map for the specified function
-  MUST_USE_RESULT MaybeObject* AllocateInitialMap(JSFunction* fun);
-
   // Allocates an empty code cache.
   MUST_USE_RESULT MaybeObject* AllocateCodeCache();

Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 527a6ebc9569f579188bc93091c51d60d7ebd04f..99d8ad69a220d3ab235c61a09bfaa52cd69bb600 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -9895,9 +9895,42 @@ void JSFunction::RemovePrototype() {
 void JSFunction::EnsureHasInitialMap(Handle<JSFunction> function) {
   if (function->has_initial_map()) return;
   Isolate* isolate = function->GetIsolate();
-  Handle<Map> initial_map = isolate->factory()->NewInitialMap(function);
-  function->set_initial_map(*initial_map);
-  initial_map->set_constructor(*function);
+
+ // First create a new map with the size and number of in-object properties
+  // suggested by the function.
+  InstanceType instance_type;
+  int instance_size;
+  int in_object_properties;
+  if (function->shared()->is_generator()) {
+    instance_type = JS_GENERATOR_OBJECT_TYPE;
+    instance_size = JSGeneratorObject::kSize;
+    in_object_properties = 0;
+  } else {
+    instance_type = JS_OBJECT_TYPE;
+    instance_size = function->shared()->CalculateInstanceSize();
+ in_object_properties = function->shared()->CalculateInObjectProperties();
+  }
+ Handle<Map> map = isolate->factory()->NewMap(instance_type, instance_size);
+
+  // Fetch or allocate prototype.
+  Handle<Object> prototype;
+  if (function->has_instance_prototype()) {
+    prototype = handle(function->instance_prototype(), isolate);
+  } else {
+    prototype = isolate->factory()->NewFunctionPrototype(function);
+  }
+  map->set_inobject_properties(in_object_properties);
+  map->set_unused_property_fields(in_object_properties);
+  map->set_prototype(*prototype);
+  ASSERT(map->has_fast_object_elements());
+
+  if (!function->shared()->is_generator()) {
+    function->shared()->StartInobjectSlackTracking(*map);
+  }
+
+  // Finally link initial map and constructor function.
+  function->set_initial_map(*map);
+  map->set_constructor(*function);
 }




--
--
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/groups/opt_out.

Reply via email to