Revision: 20840
Author:   [email protected]
Date:     Thu Apr 17 11:50:22 2014 UTC
Log:      Select function map based on prototype and shared function info.

BUG=
[email protected]

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

Modified:
 /branches/bleeding_edge/src/factory.cc
 /branches/bleeding_edge/src/factory.h

=======================================
--- /branches/bleeding_edge/src/factory.cc      Thu Apr 17 08:33:18 2014 UTC
+++ /branches/bleeding_edge/src/factory.cc      Thu Apr 17 11:50:22 2014 UTC
@@ -973,37 +973,23 @@
     Handle<ConstantPoolArray> array) {
   CALL_HEAP_FUNCTION(isolate(), array->Copy(), ConstantPoolArray);
 }
-
-
-static Handle<Map> MapForNewFunction(Isolate *isolate,
- Handle<SharedFunctionInfo> function_info) {
-  Context *context = isolate->context()->native_context();
-  int map_index = Context::FunctionMapIndex(function_info->strict_mode(),
-                                            function_info->is_generator());
-  return Handle<Map>(Map::cast(context->get(map_index)));
-}


 Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
-    Handle<SharedFunctionInfo> function_info,
+    Handle<SharedFunctionInfo> info,
     Handle<Context> context,
     PretenureFlag pretenure) {
-  Handle<JSFunction> result = NewFunctionHelper(
-      MapForNewFunction(isolate(), function_info),
-      function_info,
-      the_hole_value(),
-      pretenure);
+  Handle<JSFunction> result = NewFunction(
+      info, context, the_hole_value(), pretenure);

-  if (function_info->ic_age() != isolate()->heap()->global_ic_age()) {
-    function_info->ResetForNewContext(isolate()->heap()->global_ic_age());
+  if (info->ic_age() != isolate()->heap()->global_ic_age()) {
+    info->ResetForNewContext(isolate()->heap()->global_ic_age());
   }

-  result->set_context(*context);
-
- int index = function_info->SearchOptimizedCodeMap(context->native_context(),
-                                                    BailoutId::None());
-  if (!function_info->bound() && index < 0) {
-    int number_of_literals = function_info->num_literals();
+  int index = info->SearchOptimizedCodeMap(context->native_context(),
+                                           BailoutId::None());
+  if (!info->bound() && index < 0) {
+    int number_of_literals = info->num_literals();
Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure);
     if (number_of_literals > 0) {
       // Store the native context in the literals array prefix. This
@@ -1017,10 +1003,9 @@

   if (index > 0) {
     // Caching of optimized code enabled and optimized code found.
-    FixedArray* literals =
-        function_info->GetLiteralsFromOptimizedCodeMap(index);
+    FixedArray* literals = info->GetLiteralsFromOptimizedCodeMap(index);
     if (literals != NULL) result->set_literals(literals);
-    Code* code = function_info->GetCodeFromOptimizedCodeMap(index);
+    Code* code = info->GetCodeFromOptimizedCodeMap(index);
     ASSERT(!code->marked_for_deoptimization());
     result->ReplaceCode(code);
     return result;
@@ -1029,9 +1014,9 @@
   if (isolate()->use_crankshaft() &&
       FLAG_always_opt &&
       result->is_compiled() &&
-      !function_info->is_toplevel() &&
-      function_info->allows_lazy_compilation() &&
-      !function_info->optimization_disabled() &&
+      !info->is_toplevel() &&
+      info->allows_lazy_compilation() &&
+      !info->optimization_disabled() &&
       !isolate()->DebuggerHasBreakPoints()) {
     result->MarkForOptimization();
   }
@@ -1752,8 +1737,9 @@
   if (type == JS_FUNCTION_TYPE) {
     map->set_function_with_prototype(true);
     Handle<JSFunction> js_function = Handle<JSFunction>::cast(object);
- InitializeFunction(js_function, shared.ToHandleChecked(), the_hole_value());
-    js_function->set_context(isolate()->context()->native_context());
+    Handle<Context> context(isolate()->context()->native_context());
+    InitializeFunction(js_function, shared.ToHandleChecked(),
+                       context, null_value());
   }

   // Put in filler if the new object is smaller than the old.
@@ -1983,52 +1969,68 @@


 void Factory::InitializeFunction(Handle<JSFunction> function,
-                                 Handle<SharedFunctionInfo> shared,
-                                 Handle<Object> prototype) {
-  ASSERT(!prototype->IsMap());
+                                 Handle<SharedFunctionInfo> info,
+                                 Handle<Context> context,
+                                 MaybeHandle<Object> maybe_prototype) {
   function->initialize_properties();
   function->initialize_elements();
-  function->set_shared(*shared);
-  function->set_code(shared->code());
+  function->set_shared(*info);
+  function->set_code(info->code());
+  function->set_context(*context);
+  Handle<Object> prototype;
+  if (maybe_prototype.ToHandle(&prototype)) {
+    ASSERT(!prototype->IsMap());
+  } else {
+    prototype = the_hole_value();
+  }
   function->set_prototype_or_initial_map(*prototype);
-  function->set_context(*undefined_value());
   function->set_literals_or_bindings(*empty_fixed_array());
   function->set_next_function_link(*undefined_value());
 }


-Handle<JSFunction> Factory::NewFunctionHelper(Handle<Map> function_map,
- Handle<SharedFunctionInfo> shared,
-                                              Handle<Object> prototype,
-                                              PretenureFlag pretenure) {
-  AllocationSpace space =
-      (pretenure == TENURED) ? OLD_POINTER_SPACE : NEW_SPACE;
-  Handle<JSFunction> fun = New<JSFunction>(function_map, space);
-  InitializeFunction(fun, shared, prototype);
-  return fun;
+static Handle<Map> MapForNewFunction(Isolate* isolate,
+ Handle<SharedFunctionInfo> function_info,
+                                     MaybeHandle<Object> maybe_prototype) {
+  if (maybe_prototype.is_null()) {
+    return function_info->strict_mode() == SLOPPY
+        ? isolate->sloppy_function_without_prototype_map()
+        : isolate->strict_function_without_prototype_map();
+  }
+
+  Context* context = isolate->context()->native_context();
+  int map_index = Context::FunctionMapIndex(function_info->strict_mode(),
+                                            function_info->is_generator());
+  return Handle<Map>(Map::cast(context->get(map_index)));
+}
+
+
+Handle<JSFunction> Factory::NewFunction(Handle<SharedFunctionInfo> info,
+                                        Handle<Context> context,
+ MaybeHandle<Object> maybe_prototype,
+                                        PretenureFlag pretenure) {
+  Handle<Map> map = MapForNewFunction(isolate(), info, maybe_prototype);
+ AllocationSpace space = pretenure == TENURED ? OLD_POINTER_SPACE : NEW_SPACE;
+  Handle<JSFunction> result = New<JSFunction>(map, space);
+  InitializeFunction(result, info, context, maybe_prototype);
+  return result;
 }


 Handle<JSFunction> Factory::NewFunction(Handle<String> name,
                                         Handle<Object> prototype) {
-  Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
-  Handle<JSFunction> fun = NewFunctionHelper(
-      isolate()->sloppy_function_map(), function_share, prototype);
-  fun->set_context(isolate()->context()->native_context());
-  return fun;
+  Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name);
+  Handle<Context> context(isolate()->context()->native_context());
+  return NewFunction(info, context, prototype);
 }


 Handle<JSFunction> Factory::NewFunctionWithoutPrototype(
     Handle<String> name,
     StrictMode strict_mode) {
-  Handle<SharedFunctionInfo> function_share = NewSharedFunctionInfo(name);
-  Handle<Map> map = strict_mode == SLOPPY
-      ? isolate()->sloppy_function_without_prototype_map()
-      : isolate()->strict_function_without_prototype_map();
-  Handle<JSFunction> fun =
-      NewFunctionHelper(map, function_share, the_hole_value());
-  fun->set_context(isolate()->context()->native_context());
+  Handle<SharedFunctionInfo> info = NewSharedFunctionInfo(name);
+  Handle<Context> context(isolate()->context()->native_context());
+ Handle<JSFunction> fun = NewFunction(info, context, MaybeHandle<Object>());
   return fun;
 }

@@ -2111,12 +2113,8 @@
       break;
   }

-  Handle<JSFunction> result =
-      NewFunction(Factory::empty_string(),
-                  type,
-                  instance_size,
-                  code,
-                  true);
+  Handle<JSFunction> result = NewFunction(
+      Factory::empty_string(), type, instance_size, code, true);

   // Set length.
   result->shared()->set_length(obj->length());
=======================================
--- /branches/bleeding_edge/src/factory.h       Wed Apr 16 21:19:25 2014 UTC
+++ /branches/bleeding_edge/src/factory.h       Thu Apr 17 11:50:22 2014 UTC
@@ -633,19 +633,19 @@
                 Handle<AllocationSite> allocation_site);

   // Initializes a function with a shared part and prototype.
-  // Note: this code was factored out of NewFunctionHelper such that
- // other parts of the VM could use it. Specifically, a function that creates - // instances of type JS_FUNCTION_TYPE benefit from the use of this function. + // Note: this code was factored out of NewFunction such that other parts of + // the VM could use it. Specifically, a function that creates instances of
+  // type JS_FUNCTION_TYPE benefit from the use of this function.
   inline void InitializeFunction(Handle<JSFunction> function,
-                                 Handle<SharedFunctionInfo> shared,
-                                 Handle<Object> prototype);
+                                 Handle<SharedFunctionInfo> info,
+                                 Handle<Context> context,
+                                 MaybeHandle<Object> maybe_prototype);

   // Creates a function initialized with a shared part.
-  inline Handle<JSFunction> NewFunctionHelper(
-      Handle<Map> function_map,
-      Handle<SharedFunctionInfo> shared,
-      Handle<Object> prototype,
-      PretenureFlag pretenure = TENURED);
+  inline Handle<JSFunction> NewFunction(Handle<SharedFunctionInfo> info,
+                                        Handle<Context> context,
+ MaybeHandle<Object> maybe_prototype,
+                                        PretenureFlag pretenure = TENURED);

   // Create a new map cache.
   Handle<MapCache> NewMapCache(int at_least_space_for);

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