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(
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);
......
......@@ -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) {
......@@ -1013,21 +1010,8 @@ class LiteralFixer {
CollectJSFunctions(shared_info, isolate);
for (int i = 0; i < function_instances->length(); i++) {
Handle<JSFunction> fun(JSFunction::cast(function_instances->get(i)));
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 +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);
}
}
......
......@@ -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
......
......@@ -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;
......
......@@ -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 <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),
......
......@@ -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);
......
......@@ -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;
......
......@@ -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<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(
......
......@@ -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));
......
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