Revision: 17480
Author:   [email protected]
Date:     Tue Nov  5 12:11:27 2013 UTC
Log:      Introduce JSFunction::EnsureHasInitialMap method.

This change enforces explicit allocation of the initial map for each
JSFunction to introduce a proper layering between the JSFunction class
and the Heap class. A follow-up change will then handlify the two
functions AllocateInitialMap and AllocateFunctionPrototype.

[email protected]
BUG=v8:2877

Review URL: https://codereview.chromium.org/32323013
http://code.google.com/p/v8/source/detail?r=17480

Modified:
 /branches/bleeding_edge/src/factory.cc
 /branches/bleeding_edge/src/factory.h
 /branches/bleeding_edge/src/heap.cc
 /branches/bleeding_edge/src/heap.h
 /branches/bleeding_edge/src/objects.cc
 /branches/bleeding_edge/src/objects.h
 /branches/bleeding_edge/src/runtime.cc

=======================================
--- /branches/bleeding_edge/src/factory.cc      Tue Nov  5 11:47:11 2013 UTC
+++ /branches/bleeding_edge/src/factory.cc      Tue Nov  5 12:11:27 2013 UTC
@@ -581,6 +581,12 @@
       isolate()->heap()->AllocateFunctionPrototype(*function),
       JSObject);
 }
+
+
+Handle<Map> Factory::NewInitialMap(Handle<JSFunction> function) {
+  CALL_HEAP_FUNCTION(
+      isolate(), isolate()->heap()->AllocateInitialMap(*function), Map);
+}


Handle<Map> Factory::CopyWithPreallocatedFieldDescriptors(Handle<Map> src) {
@@ -1050,6 +1056,7 @@

 Handle<JSObject> Factory::NewJSObject(Handle<JSFunction> constructor,
                                       PretenureFlag pretenure) {
+  JSFunction::EnsureHasInitialMap(constructor);
   CALL_HEAP_FUNCTION(
       isolate(),
isolate()->heap()->AllocateJSObject(*constructor, pretenure), JSObject);
@@ -1194,6 +1201,19 @@
       isolate(),
       array->SetContent(*elements));
 }
+
+
+Handle<JSGeneratorObject> Factory::NewJSGeneratorObject(
+    Handle<JSFunction> function) {
+  ASSERT(function->shared()->is_generator());
+  JSFunction::EnsureHasInitialMap(function);
+  Handle<Map> map(function->initial_map());
+  ASSERT(map->instance_type() == JS_GENERATOR_OBJECT_TYPE);
+  CALL_HEAP_FUNCTION(
+      isolate(),
+      isolate()->heap()->AllocateJSObjectFromMap(*map),
+      JSGeneratorObject);
+}


 Handle<JSArrayBuffer> Factory::NewJSArrayBuffer() {
=======================================
--- /branches/bleeding_edge/src/factory.h       Tue Nov  5 11:47:11 2013 UTC
+++ /branches/bleeding_edge/src/factory.h       Tue Nov  5 12:11:27 2013 UTC
@@ -263,6 +263,8 @@

   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
@@ -343,6 +345,8 @@

   void SetContent(Handle<JSArray> array, Handle<FixedArrayBase> elements);

+ Handle<JSGeneratorObject> NewJSGeneratorObject(Handle<JSFunction> function);
+
   Handle<JSArrayBuffer> NewJSArrayBuffer();

   Handle<JSTypedArray> NewJSTypedArray(ExternalArrayType type);
=======================================
--- /branches/bleeding_edge/src/heap.cc Tue Nov  5 11:59:42 2013 UTC
+++ /branches/bleeding_edge/src/heap.cc Tue Nov  5 12:11:27 2013 UTC
@@ -4640,15 +4640,7 @@

 MaybeObject* Heap::AllocateJSObject(JSFunction* constructor,
                                     PretenureFlag pretenure) {
-  // Allocate the initial map if absent.
-  if (!constructor->has_initial_map()) {
-    Object* initial_map;
-    { MaybeObject* maybe_initial_map = AllocateInitialMap(constructor);
- if (!maybe_initial_map->ToObject(&initial_map)) return maybe_initial_map;
-    }
-    constructor->set_initial_map(Map::cast(initial_map));
-    Map::cast(initial_map)->set_constructor(constructor);
-  }
+  ASSERT(constructor->has_initial_map());
   // Allocate the object based on the constructors initial map.
   MaybeObject* result = AllocateJSObjectFromMap(
       constructor->initial_map(), pretenure);
@@ -4663,15 +4655,7 @@

MaybeObject* Heap::AllocateJSObjectWithAllocationSite(JSFunction* constructor,
     Handle<AllocationSite> allocation_site) {
-  // Allocate the initial map if absent.
-  if (!constructor->has_initial_map()) {
-    Object* initial_map;
-    { MaybeObject* maybe_initial_map = AllocateInitialMap(constructor);
- if (!maybe_initial_map->ToObject(&initial_map)) return maybe_initial_map;
-    }
-    constructor->set_initial_map(Map::cast(initial_map));
-    Map::cast(initial_map)->set_constructor(constructor);
-  }
+  ASSERT(constructor->has_initial_map());
// Allocate the object based on the constructors initial map, or the payload
   // advice
   Map* initial_map = constructor->initial_map();
@@ -4701,23 +4685,6 @@
 #endif
   return result;
 }
-
-
-MaybeObject* Heap::AllocateJSGeneratorObject(JSFunction *function) {
-  ASSERT(function->shared()->is_generator());
-  Map *map;
-  if (function->has_initial_map()) {
-    map = function->initial_map();
-  } else {
-    // Allocate the initial map if absent.
-    MaybeObject* maybe_map = AllocateInitialMap(function);
-    if (!maybe_map->To(&map)) return maybe_map;
-    function->set_initial_map(map);
-    map->set_constructor(function);
-  }
-  ASSERT(map->instance_type() == JS_GENERATOR_OBJECT_TYPE);
-  return AllocateJSObjectFromMap(map);
-}


MaybeObject* Heap::AllocateJSModule(Context* context, ScopeInfo* scope_info) {
=======================================
--- /branches/bleeding_edge/src/heap.h  Tue Nov  5 11:59:42 2013 UTC
+++ /branches/bleeding_edge/src/heap.h  Tue Nov  5 12:11:27 2013 UTC
@@ -631,9 +631,6 @@
       JSFunction* constructor,
       Handle<AllocationSite> allocation_site);

-  MUST_USE_RESULT MaybeObject* AllocateJSGeneratorObject(
-      JSFunction* function);
-
   MUST_USE_RESULT MaybeObject* AllocateJSModule(Context* context,
                                                 ScopeInfo* scope_info);

=======================================
--- /branches/bleeding_edge/src/objects.cc      Tue Nov  5 11:47:11 2013 UTC
+++ /branches/bleeding_edge/src/objects.cc      Tue Nov  5 12:11:27 2013 UTC
@@ -9883,6 +9883,15 @@
   set_map(no_prototype_map);
set_prototype_or_initial_map(no_prototype_map->GetHeap()->the_hole_value());
 }
+
+
+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);
+}


 void JSFunction::SetInstanceClassName(String* name) {
=======================================
--- /branches/bleeding_edge/src/objects.h       Tue Nov  5 11:47:11 2013 UTC
+++ /branches/bleeding_edge/src/objects.h       Tue Nov  5 12:11:27 2013 UTC
@@ -7279,6 +7279,7 @@
   inline Map* initial_map();
   inline void set_initial_map(Map* value);
   inline bool has_initial_map();
+  static void EnsureHasInitialMap(Handle<JSFunction> function);

   // Get and set the prototype property on a JSFunction. If the
   // function has an initial map the prototype is set on the initial
=======================================
--- /branches/bleeding_edge/src/runtime.cc      Tue Nov  5 11:47:11 2013 UTC
+++ /branches/bleeding_edge/src/runtime.cc      Tue Nov  5 12:11:27 2013 UTC
@@ -2974,30 +2974,28 @@


 RUNTIME_FUNCTION(MaybeObject*, Runtime_CreateJSGeneratorObject) {
-  SealHandleScope shs(isolate);
+  HandleScope scope(isolate);
   ASSERT(args.length() == 0);

   JavaScriptFrameIterator it(isolate);
   JavaScriptFrame* frame = it.frame();
-  JSFunction* function = frame->function();
+  Handle<JSFunction> function(frame->function());
   RUNTIME_ASSERT(function->shared()->is_generator());

-  JSGeneratorObject* generator;
+  Handle<JSGeneratorObject> generator;
   if (frame->IsConstructor()) {
-    generator = JSGeneratorObject::cast(frame->receiver());
+    generator = handle(JSGeneratorObject::cast(frame->receiver()));
   } else {
-    MaybeObject* maybe_generator =
-        isolate->heap()->AllocateJSGeneratorObject(function);
-    if (!maybe_generator->To(&generator)) return maybe_generator;
+    generator = isolate->factory()->NewJSGeneratorObject(function);
   }
-  generator->set_function(function);
+  generator->set_function(*function);
   generator->set_context(Context::cast(frame->context()));
   generator->set_receiver(frame->receiver());
   generator->set_continuation(0);
   generator->set_operand_stack(isolate->heap()->empty_fixed_array());
   generator->set_stack_handler_index(-1);

-  return generator;
+  return *generator;
 }


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