Commit 6b1bddb4 authored by verwaest's avatar verwaest Committed by Commit bot

Remove NativeContext from Literal array, since we always create the literals...

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}
parent 24847156
...@@ -1385,13 +1385,6 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo( ...@@ -1385,13 +1385,6 @@ Handle<JSFunction> Factory::NewFunctionFromSharedFunctionInfo(
if (!info->bound() && index < 0) { if (!info->bound() && index < 0) {
int number_of_literals = info->num_literals(); int number_of_literals = info->num_literals();
Handle<FixedArray> literals = NewFixedArray(number_of_literals, pretenure); 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); result->set_literals(*literals);
} }
...@@ -2031,14 +2024,7 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo( ...@@ -2031,14 +2024,7 @@ Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
shared->set_scope_info(*scope_info); shared->set_scope_info(*scope_info);
shared->set_feedback_vector(*feedback_vector); shared->set_feedback_vector(*feedback_vector);
shared->set_kind(kind); shared->set_kind(kind);
int literals_array_size = number_of_literals; shared->set_num_literals(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);
if (IsGeneratorFunction(kind)) { if (IsGeneratorFunction(kind)) {
shared->set_instance_class_name(isolate()->heap()->Generator_string()); shared->set_instance_class_name(isolate()->heap()->Generator_string());
shared->DisableOptimization(kGenerator); shared->DisableOptimization(kGenerator);
......
...@@ -995,9 +995,6 @@ class LiteralFixer { ...@@ -995,9 +995,6 @@ class LiteralFixer {
Handle<SharedFunctionInfo> shared_info, Handle<SharedFunctionInfo> shared_info,
Isolate* isolate) { Isolate* isolate) {
int new_literal_count = compile_info_wrapper->GetLiteralCount(); 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(); int old_literal_count = shared_info->num_literals();
if (old_literal_count == new_literal_count) { if (old_literal_count == new_literal_count) {
...@@ -1013,21 +1010,8 @@ class LiteralFixer { ...@@ -1013,21 +1010,8 @@ class LiteralFixer {
CollectJSFunctions(shared_info, isolate); CollectJSFunctions(shared_info, isolate);
for (int i = 0; i < function_instances->length(); i++) { for (int i = 0; i < function_instances->length(); i++) {
Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i))); Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i)));
Handle<FixedArray> old_literals(fun->literals());
Handle<FixedArray> new_literals = Handle<FixedArray> new_literals =
isolate->factory()->NewFixedArray(new_literal_count); 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); fun->set_literals(*new_literals);
} }
...@@ -1075,7 +1059,7 @@ class LiteralFixer { ...@@ -1075,7 +1059,7 @@ class LiteralFixer {
void visit(JSFunction* fun) { void visit(JSFunction* fun) {
FixedArray* literals = fun->literals(); FixedArray* literals = fun->literals();
int len = literals->length(); int len = literals->length();
for (int j = JSFunction::kLiteralsPrefixSize; j < len; j++) { for (int j = 0; j < len; j++) {
literals->set_undefined(j); literals->set_undefined(j);
} }
} }
......
...@@ -10233,11 +10233,6 @@ void JSFunction::PrintName(FILE* out) { ...@@ -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: // The filter is a pattern that matches function names in this way:
// "*" all; the default // "*" all; the default
// "-" all but the top-level function // "-" all but the top-level function
......
...@@ -7573,9 +7573,6 @@ class JSFunction: public JSObject { ...@@ -7573,9 +7573,6 @@ class JSFunction: public JSObject {
// Returns the number of allocated literals. // Returns the number of allocated literals.
inline int NumberOfLiterals(); 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. // Used for flags such as --hydrogen-filter.
bool PassesFilter(const char* raw_filter); bool PassesFilter(const char* raw_filter);
...@@ -7592,10 +7589,6 @@ class JSFunction: public JSObject { ...@@ -7592,10 +7589,6 @@ class JSFunction: public JSObject {
static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset; static const int kNextFunctionLinkOffset = kNonWeakFieldsEndOffset;
static const int kSize = kNextFunctionLinkOffset + kPointerSize; 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. // Layout of the bound-function binding array.
static const int kBoundFunctionIndex = 0; static const int kBoundFunctionIndex = 0;
static const int kBoundThisIndex = 1; static const int kBoundThisIndex = 1;
......
...@@ -212,7 +212,7 @@ class ParserBase : public Traits { ...@@ -212,7 +212,7 @@ class ParserBase : public Traits {
return next_materialized_literal_index_++; return next_materialized_literal_index_++;
} }
int materialized_literal_count() { int materialized_literal_count() {
return next_materialized_literal_index_ - JSFunction::kLiteralsPrefixSize; return next_materialized_literal_index_;
} }
int NextHandlerIndex() { return next_handler_index_++; } int NextHandlerIndex() { return next_handler_index_++; }
...@@ -1658,7 +1658,7 @@ template <class Traits> ...@@ -1658,7 +1658,7 @@ template <class Traits>
ParserBase<Traits>::FunctionState::FunctionState( ParserBase<Traits>::FunctionState::FunctionState(
FunctionState** function_state_stack, Scope** scope_stack, Scope* scope, FunctionState** function_state_stack, Scope** scope_stack, Scope* scope,
FunctionKind kind, typename Traits::Type::Factory* factory) FunctionKind kind, typename Traits::Type::Factory* factory)
: next_materialized_literal_index_(JSFunction::kLiteralsPrefixSize), : next_materialized_literal_index_(0),
next_handler_index_(0), next_handler_index_(0),
expected_property_count_(0), expected_property_count_(0),
kind_(kind), kind_(kind),
......
...@@ -295,10 +295,6 @@ RUNTIME_FUNCTION(Runtime_SetCode) { ...@@ -295,10 +295,6 @@ RUNTIME_FUNCTION(Runtime_SetCode) {
int number_of_literals = source->NumberOfLiterals(); int number_of_literals = source->NumberOfLiterals();
Handle<FixedArray> literals = Handle<FixedArray> literals =
isolate->factory()->NewFixedArray(number_of_literals, TENURED); 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_context(*context);
target->set_literals(*literals); target->set_literals(*literals);
......
...@@ -42,14 +42,7 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate( ...@@ -42,14 +42,7 @@ MUST_USE_RESULT static MaybeHandle<Object> CreateObjectLiteralBoilerplate(
Isolate* isolate, Handle<FixedArray> literals, Isolate* isolate, Handle<FixedArray> literals,
Handle<FixedArray> constant_properties, bool should_have_fast_elements, Handle<FixedArray> constant_properties, bool should_have_fast_elements,
bool has_function_literal) { bool has_function_literal) {
// Get the native context from the literals array. This is the Handle<Context> context = isolate->native_context();
// 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));
// In case we have function literals, we want the object to be in // 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 // slow properties mode for now. We don't go in the map cache because
...@@ -146,8 +139,7 @@ MaybeHandle<Object> Runtime::CreateArrayLiteralBoilerplate( ...@@ -146,8 +139,7 @@ MaybeHandle<Object> Runtime::CreateArrayLiteralBoilerplate(
Isolate* isolate, Handle<FixedArray> literals, Isolate* isolate, Handle<FixedArray> literals,
Handle<FixedArray> elements) { Handle<FixedArray> elements) {
// Create the JSArray. // Create the JSArray.
Handle<JSFunction> constructor( Handle<JSFunction> constructor = isolate->array_function();
JSFunction::NativeContextFromLiterals(*literals)->array_function());
PretenureFlag pretenure_flag = PretenureFlag pretenure_flag =
isolate->heap()->InNewSpace(*literals) ? NOT_TENURED : TENURED; isolate->heap()->InNewSpace(*literals) ? NOT_TENURED : TENURED;
......
...@@ -925,13 +925,7 @@ RUNTIME_FUNCTION(Runtime_MaterializeRegExpLiteral) { ...@@ -925,13 +925,7 @@ RUNTIME_FUNCTION(Runtime_MaterializeRegExpLiteral) {
CONVERT_ARG_HANDLE_CHECKED(String, pattern, 2); CONVERT_ARG_HANDLE_CHECKED(String, pattern, 2);
CONVERT_ARG_HANDLE_CHECKED(String, flags, 3); CONVERT_ARG_HANDLE_CHECKED(String, flags, 3);
// Get the RegExp function from the context in the literals array. Handle<JSFunction> constructor = isolate->regexp_function();
// 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<JSFunction> constructor = Handle<JSFunction>(
JSFunction::NativeContextFromLiterals(*literals)->regexp_function());
// Compute the regular expression literal. // Compute the regular expression literal.
Handle<Object> regexp; Handle<Object> regexp;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION( ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
......
...@@ -2292,11 +2292,11 @@ TEST(AllocationSitesAreVisible) { ...@@ -2292,11 +2292,11 @@ TEST(AllocationSitesAreVisible) {
GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals"); GetProperty(fun_code, v8::HeapGraphEdge::kInternal, "literals");
CHECK(literals); CHECK(literals);
CHECK_EQ(v8::HeapGraphNode::kArray, literals->GetType()); 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. // after an AllocationSite.
const v8::HeapGraphEdge* prop = literals->GetChild(1); const v8::HeapGraphEdge* prop = literals->GetChild(0);
const v8::HeapGraphNode* allocation_site = prop->GetToNode(); const v8::HeapGraphNode* allocation_site = prop->GetToNode();
v8::String::Utf8Value name(allocation_site->GetName()); v8::String::Utf8Value name(allocation_site->GetName());
CHECK_EQ(0, strcmp("system / AllocationSite", *name)); CHECK_EQ(0, strcmp("system / AllocationSite", *name));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment