Reviewers: Michael Starzinger,

Message:
PTAL

Description:
Remove NativeContext from Literal array, since we always create the literals in
the native context of the current closure.

BUG=

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

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+9, -60 lines):
  M src/factory.cc
  M src/liveedit.cc
  M src/objects.h
  M src/objects.cc
  M src/preparser.h
  M src/runtime/runtime-function.cc
  M src/runtime/runtime-literals.cc
  M src/runtime/runtime-regexp.cc
  M test/cctest/test-heap-profiler.cc


Index: src/factory.cc
diff --git a/src/factory.cc b/src/factory.cc
index bf249067ed0fc3bf93f92c1f6597c52839be4d3a..36154c6b7aef6771464773dafafd74a56e160b7f 100644
--- a/src/factory.cc
+++ b/src/factory.cc
@@ -1385,13 +1385,6 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
   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
-      // context will be used when creating object, regexp and array
-      // literals in this function.
-      literals->set(JSFunction::kLiteralNativeContextIndex,
-                    context->native_context());
-    }
     result->set_literals(*literals);
   }

@@ -2031,14 +2024,7 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
   shared->set_scope_info(*scope_info);
   shared->set_feedback_vector(*feedback_vector);
   shared->set_kind(kind);
-  int literals_array_size = number_of_literals;
-  // If the function contains object, regexp or array literals,
-  // allocate extra space for a literals array prefix containing the
-  // context.
-  if (number_of_literals > 0) {
-    literals_array_size += JSFunction::kLiteralsPrefixSize;
-  }
-  shared->set_num_literals(literals_array_size);
+  shared->set_num_literals(number_of_literals);
   if (IsGeneratorFunction(kind)) {
     shared->set_instance_class_name(isolate()->heap()->Generator_string());
     shared->DisableOptimization(kGenerator);
Index: src/liveedit.cc
diff --git a/src/liveedit.cc b/src/liveedit.cc
index 8da3d52f555b78e23451bfbfeffacb9454e83f8f..458bcfb653e4f4f7821cfcdc8f7df86b262113f1 100644
--- a/src/liveedit.cc
+++ b/src/liveedit.cc
@@ -995,9 +995,6 @@ class LiteralFixer {
                             Handle<SharedFunctionInfo> shared_info,
                             Isolate* isolate) {
     int new_literal_count = compile_info_wrapper->GetLiteralCount();
-    if (new_literal_count > 0) {
-      new_literal_count += JSFunction::kLiteralsPrefixSize;
-    }
     int old_literal_count = shared_info->num_literals();

     if (old_literal_count == new_literal_count) {
@@ -1016,18 +1013,6 @@ class LiteralFixer {
         Handle<FixedArray> old_literals(fun->literals());
         Handle<FixedArray> new_literals =
             isolate->factory()->NewFixedArray(new_literal_count);
-        if (new_literal_count > 0) {
-          Handle<Context> native_context;
-          if (old_literals->length() >
-              JSFunction::kLiteralNativeContextIndex) {
-            native_context = Handle<Context>(
-                JSFunction::NativeContextFromLiterals(fun->literals()));
-          } else {
- native_context = Handle<Context>(fun->context()->native_context());
-          }
-          new_literals->set(JSFunction::kLiteralNativeContextIndex,
-              *native_context);
-        }
         fun->set_literals(*new_literals);
       }

@@ -1075,7 +1060,7 @@ class LiteralFixer {
     void visit(JSFunction* fun) {
       FixedArray* literals = fun->literals();
       int len = literals->length();
-      for (int j = JSFunction::kLiteralsPrefixSize; j < len; j++) {
+      for (int j = 0; j < len; j++) {
         literals->set_undefined(j);
       }
     }
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 504474fe3ad283908f7089af6ea939d0d4ab258a..fe25c6b071549856cc1574187b6d7d1a2ac43214 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -10233,11 +10233,6 @@ void JSFunction::PrintName(FILE* out) {
 }


-Context* JSFunction::NativeContextFromLiterals(FixedArray* literals) {
- return Context::cast(literals->get(JSFunction::kLiteralNativeContextIndex));
-}
-
-
 // The filter is a pattern that matches function names in this way:
 //   "*"      all; the default
 //   "-"      all but the top-level function
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 7ad1c29854a86bfe24691d4cec300ac0ce11f534..c70252084d45e45306df919c19265547f9e8d945 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -7592,10 +7592,6 @@ class JSFunction: public JSObject {
   static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset;
   static const int kSize = kNextFunctionLinkOffset + kPointerSize;

-  // Layout of the literals array.
-  static const int kLiteralsPrefixSize = 1;
-  static const int kLiteralNativeContextIndex = 0;
-
   // Layout of the bound-function binding array.
   static const int kBoundFunctionIndex = 0;
   static const int kBoundThisIndex = 1;
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 41b3a31f0e1169068eaf2968fe55b67fc3904ee4..48e57116f8877e93563920ebb1abea7c1c3c4371 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -212,7 +212,7 @@ class ParserBase : public Traits {
       return next_materialized_literal_index_++;
     }
     int materialized_literal_count() {
- return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize;
+      return next_materialized_literal_index_;
     }

     int NextHandlerIndex() { return next_handler_index_++; }
@@ -1664,7 +1664,7 @@ template <class Traits>
 ParserBase<Traits>::FunctionState::FunctionState(
FunctionState** function_state_stack, Scope** scope_stack, Scope* scope,
     FunctionKind kind, typename Traits::Type::Factory* factory)
-    : next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize),
+    : next_materialized_literal_index_(0),
       next_handler_index_(0),
       expected_property_count_(0),
       kind_(kind),
Index: src/runtime/runtime-function.cc
diff --git a/src/runtime/runtime-function.cc b/src/runtime/runtime-function.cc index 75aeed74bed77f96de8da9cb4014bdabd73e84d5..e8b160d1c529353134ad2a045faec0d5d1f040a5 100644
--- a/src/runtime/runtime-function.cc
+++ b/src/runtime/runtime-function.cc
@@ -295,10 +295,6 @@ RUNTIME_FUNCTION(Runtime_SetCode) {
   int number_of_literals = source->NumberOfLiterals();
   Handle<FixedArray> literals =
       isolate->factory()->NewFixedArray(number_of_literals, TENURED);
-  if (number_of_literals > 0) {
-    literals->set(JSFunction::kLiteralNativeContextIndex,
-                  context->native_context());
-  }
   target->set_context(*context);
   target->set_literals(*literals);

Index: src/runtime/runtime-literals.cc
diff --git a/src/runtime/runtime-literals.cc b/src/runtime/runtime-literals.cc index 8bbe0eeddb0da455bc92903e026a81a558e11b4c..83a2fcf45f7e30aff887225bb387395d89272cf7 100644
--- a/src/runtime/runtime-literals.cc
+++ b/src/runtime/runtime-literals.cc
@@ -42,14 +42,7 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate(
     Isolate* isolate, Handle<FixedArray> literals,
     Handle<FixedArray> constant_properties, bool should_have_fast_elements,
     bool has_function_literal) {
-  // Get the native context from the literals array.  This is the
-  // context in which the function was created and we use the object
-  // function from this context to create the object literal.  We do
-  // not use the object function from the current native context
-  // because this might be the object function from another context
-  // which we should not have access to.
-  Handle<Context> context =
-      Handle<Context>(JSFunction::NativeContextFromLiterals(*literals));
+  Handle<Context> context = isolate->native_context();

   // In case we have function literals, we want the object to be in
   // slow properties mode for now. We don't go in the map cache because
@@ -146,8 +139,7 @@ MaybeHandle<Object> Runtime::CreateArrayLiteralBoilerplate(
     Isolate* isolate, Handle<FixedArray> literals,
     Handle<FixedArray> elements) {
   // Create the JSArray.
-  Handle<JSFunction> constructor(
-      JSFunction::NativeContextFromLiterals(*literals)->array_function());
+  Handle<JSFunction> constructor = isolate->array_function();

   PretenureFlag pretenure_flag =
       isolate->heap()->InNewSpace(*literals) ? NOT_TENURED : TENURED;
Index: src/runtime/runtime-regexp.cc
diff --git a/src/runtime/runtime-regexp.cc b/src/runtime/runtime-regexp.cc
index 932ebbb05941b0aee4ca11fec040eccb18ba8aa8..3d218f7fb8f233cdfb27fb117e553c7473cbf3c8 100644
--- a/src/runtime/runtime-regexp.cc
+++ b/src/runtime/runtime-regexp.cc
@@ -930,8 +930,7 @@ RUNTIME_FUNCTION(Runtime_MaterializeRegExpLiteral) {
   // function was created.  We do not use the RegExp function from the
   // current native context because this might be the RegExp function
   // from another context which we should not have access to.
-  Handle<JSFunction> constructor = Handle<JSFunction>(
-      JSFunction::NativeContextFromLiterals(*literals)->regexp_function());
+  Handle<JSFunction> constructor = isolate->regexp_function();
   // Compute the regular expression literal.
   Handle<Object> regexp;
   ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
Index: test/cctest/test-heap-profiler.cc
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index 5c9d2e69f075418a7d6f79cb7386f4fd3bcbaccb..80fb17b1356e72f81e389d592bf4a3c423c669d5 100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -2292,11 +2292,11 @@ TEST(AllocationSitesAreVisible) {
       GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals");
   CHECK(literals);
   CHECK_EQ(v8::HeapGraphNode::kArray, literals->GetType());
-  CHECK_EQ(2, literals->GetChildrenCount());
+  CHECK_EQ(1, literals->GetChildrenCount());

   // The second value in the literals array should be the boilerplate,
   // after an AllocationSite.
-  const v8::HeapGraphEdge* prop = literals->GetChild(1);
+  const v8::HeapGraphEdge* prop = literals->GetChild(0);
   const v8::HeapGraphNode* allocation_site = prop->GetToNode();
   v8::String::Utf8Value name(allocation_site->GetName());
   CHECK_EQ(0, strcmp("system / AllocationSite", *name));


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