From 6b1bddb454bd1887e3c3e7aae785447f015c492b Mon Sep 17 00:00:00 2001 From: verwaest Date: Wed, 25 Feb 2015 14:41:40 -0800 Subject: [PATCH] Remove NativeContext from Literal array, since we always create the literals in the native context of the current closure. BUG= Review URL: https://codereview.chromium.org/952303002 Cr-Commit-Position: refs/heads/master@{#26867} --- src/factory.cc | 16 +--------------- src/liveedit.cc | 18 +----------------- src/objects.cc | 5 ----- src/objects.h | 7 ------- src/preparser.h | 4 ++-- src/runtime/runtime-function.cc | 4 ---- src/runtime/runtime-literals.cc | 12 ++---------- src/runtime/runtime-regexp.cc | 8 +------- test/cctest/test-heap-profiler.cc | 6 +++--- 9 files changed, 10 insertions(+), 70 deletions(-) diff --git a/src/factory.cc b/src/factory.cc index bf24906..36154c6 100644 --- a/src/factory.cc +++ b/src/factory.cc @@ -1385,13 +1385,6 @@ Handle Factory::NewFunctionFromSharedFunctionInfo( if (!info->bound() && index < 0) { int number_of_literals = info->num_literals(); Handle 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 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); diff --git a/src/liveedit.cc b/src/liveedit.cc index 8da3d52..b6cc124 100644 --- a/src/liveedit.cc +++ b/src/liveedit.cc @@ -995,9 +995,6 @@ class LiteralFixer { Handle 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) { @@ -1013,21 +1010,8 @@ class LiteralFixer { CollectJSFunctions(shared_info, isolate); for (int i = 0; i < function_instances->length(); i++) { Handle fun(JSFunction::cast(function_instances->get(i))); - Handle old_literals(fun->literals()); Handle new_literals = isolate->factory()->NewFixedArray(new_literal_count); - if (new_literal_count > 0) { - Handle native_context; - if (old_literals->length() > - JSFunction::kLiteralNativeContextIndex) { - native_context = Handle( - JSFunction::NativeContextFromLiterals(fun->literals())); - } else { - native_context = Handle(fun->context()->native_context()); - } - new_literals->set(JSFunction::kLiteralNativeContextIndex, - *native_context); - } fun->set_literals(*new_literals); } @@ -1075,7 +1059,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); } } diff --git a/src/objects.cc b/src/objects.cc index 504474f..fe25c6b 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 diff --git a/src/objects.h b/src/objects.h index 7ad1c29..4ead848 100644 --- a/src/objects.h +++ b/src/objects.h @@ -7573,9 +7573,6 @@ class JSFunction: public JSObject { // Returns the number of allocated literals. inline int NumberOfLiterals(); - // Retrieve the native context from a function's literal array. - static Context* NativeContextFromLiterals(FixedArray* literals); - // Used for flags such as --hydrogen-filter. bool PassesFilter(const char* raw_filter); @@ -7592,10 +7589,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; diff --git a/src/preparser.h b/src/preparser.h index ee7c98b..443ed0c 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_++; } @@ -1658,7 +1658,7 @@ template ParserBase::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), diff --git a/src/runtime/runtime-function.cc b/src/runtime/runtime-function.cc index 75aeed7..e8b160d 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 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); diff --git a/src/runtime/runtime-literals.cc b/src/runtime/runtime-literals.cc index 8bbe0ee..83a2fcf 100644 --- a/src/runtime/runtime-literals.cc +++ b/src/runtime/runtime-literals.cc @@ -42,14 +42,7 @@ MUST_USE_RESULT static MaybeHandle CreateObjectLiteralBoilerplate( Isolate* isolate, Handle literals, Handle 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 = - Handle(JSFunction::NativeContextFromLiterals(*literals)); + Handle 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 Runtime::CreateArrayLiteralBoilerplate( Isolate* isolate, Handle literals, Handle elements) { // Create the JSArray. - Handle constructor( - JSFunction::NativeContextFromLiterals(*literals)->array_function()); + Handle constructor = isolate->array_function(); PretenureFlag pretenure_flag = isolate->heap()->InNewSpace(*literals) ? NOT_TENURED : TENURED; diff --git a/src/runtime/runtime-regexp.cc b/src/runtime/runtime-regexp.cc index 932ebbb..69d0d9b 100644 --- a/src/runtime/runtime-regexp.cc +++ b/src/runtime/runtime-regexp.cc @@ -925,13 +925,7 @@ RUNTIME_FUNCTION(Runtime_MaterializeRegExpLiteral) { CONVERT_ARG_HANDLE_CHECKED(String, pattern, 2); CONVERT_ARG_HANDLE_CHECKED(String, flags, 3); - // Get the RegExp function from the context in the literals array. - // This is the RegExp function from the context in which the - // 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 constructor = Handle( - JSFunction::NativeContextFromLiterals(*literals)->regexp_function()); + Handle constructor = isolate->regexp_function(); // Compute the regular expression literal. Handle regexp; ASSIGN_RETURN_FAILURE_ON_EXCEPTION( diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index 5c9d2e6..a26edd5 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, + // The first 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)); -- 2.7.4