Commit 01488b9c authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[runtime] Always store the name in a function's ScopeInfo

This CL will temporarily regress memory since we will store the name
both on the SFI and the ScopInfo. Future CLs will do the following:
- Collapse the name field on SFI with the scopeInfo field
- Store the ScopeInfo on the Context instead of the closure so we
  don't strongly hold on to the closure unnecessary

Drive-by-fix:
 - Mark ScopeInfo accessors as const

Bug: v8:7066
Change-Id: I7ef47d858352bb0bb76ad105f194eabce06938ed
Reviewed-on: https://chromium-review.googlesource.com/939476Reviewed-by: 's avatarIgor Sheludko <ishell@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#51680}
parent b8bc26d0
......@@ -296,8 +296,15 @@ void InstallUnoptimizedCode(CompilationInfo* compilation_info,
Handle<ScopeInfo> scope_info = compilation_info->scope()->scope_info();
shared->set_scope_info(*scope_info);
Scope* outer_scope = compilation_info->scope()->GetOuterScopeWithContext();
if (outer_scope) {
shared->set_outer_scope_info(*outer_scope->scope_info());
if (outer_scope) shared->set_outer_scope_info(*outer_scope->scope_info());
if (scope_info->HasFunctionName()) {
if (scope_info->HasPendingFunctionName()) {
scope_info->SetPendingFunctionName(shared->name());
} else {
DCHECK_EQ(shared->name(), scope_info->FunctionName());
}
} else {
DCHECK_EQ(shared->name(), isolate->heap()->empty_string());
}
DCHECK(!compilation_info->code().is_null());
......
......@@ -2498,25 +2498,15 @@ void Factory::ReinitializeJSGlobalProxy(Handle<JSGlobalProxy> object,
heap->InitializeJSObjectFromMap(*object, *raw_properties_or_hash, *map);
}
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfo(
MaybeHandle<String> name, FunctionKind kind, Handle<Code> code,
Handle<ScopeInfo> scope_info) {
Handle<SharedFunctionInfo> shared =
NewSharedFunctionInfo(name, code, IsConstructable(kind), kind);
shared->set_scope_info(*scope_info);
shared->set_outer_scope_info(*the_hole_value());
return shared;
}
Handle<SharedFunctionInfo> Factory::NewSharedFunctionInfoForLiteral(
FunctionLiteral* literal, Handle<Script> script) {
Handle<Code> code = BUILTIN_CODE(isolate(), CompileLazy);
Handle<ScopeInfo> scope_info(ScopeInfo::Empty(isolate()));
Handle<SharedFunctionInfo> result =
NewSharedFunctionInfo(literal->name(), literal->kind(), code, scope_info);
SharedFunctionInfo::InitFromFunctionLiteral(result, literal);
SharedFunctionInfo::SetScript(result, script, false);
return result;
FunctionKind kind = literal->kind();
Handle<SharedFunctionInfo> shared =
NewSharedFunctionInfo(literal->name(), code, IsConstructable(kind), kind);
SharedFunctionInfo::InitFromFunctionLiteral(shared, literal);
SharedFunctionInfo::SetScript(shared, script, false);
return shared;
}
Handle<JSMessageObject> Factory::NewJSMessageObject(
......
......@@ -773,9 +773,6 @@ class V8_EXPORT_PRIVATE Factory final {
#undef ACCESSOR_INFO_ACCESSOR
// Allocates a new SharedFunctionInfo object.
Handle<SharedFunctionInfo> NewSharedFunctionInfo(
MaybeHandle<String> name, FunctionKind kind, Handle<Code> code,
Handle<ScopeInfo> scope_info);
Handle<SharedFunctionInfo> NewSharedFunctionInfo(
MaybeHandle<String> name, MaybeHandle<Code> code, bool is_constructor,
FunctionKind kind = kNormalFunction,
......
......@@ -3471,15 +3471,15 @@ ACCESSORS(JSAsyncFromSyncIterator, next, Object, kNextOffset)
ACCESSORS(JSStringIterator, string, String, kStringOffset)
SMI_ACCESSORS(JSStringIterator, index, kNextIndexOffset)
bool ScopeInfo::IsAsmModule() { return AsmModuleField::decode(Flags()); }
bool ScopeInfo::IsAsmModule() const { return AsmModuleField::decode(Flags()); }
bool ScopeInfo::HasSimpleParameters() {
bool ScopeInfo::HasSimpleParameters() const {
return HasSimpleParametersField::decode(Flags());
}
#define FIELD_ACCESSORS(name) \
void ScopeInfo::Set##name(int value) { set(k##name, Smi::FromInt(value)); } \
int ScopeInfo::name() { \
int ScopeInfo::name() const { \
if (length() > 0) { \
return Smi::ToInt(get(k##name)); \
} else { \
......
This diff is collapsed.
......@@ -38,26 +38,26 @@ class ScopeInfo : public FixedArray {
DECL_PRINTER(ScopeInfo)
// Return the type of this scope.
ScopeType scope_type();
ScopeType scope_type() const;
// Return the language mode of this scope.
LanguageMode language_mode();
LanguageMode language_mode() const;
// True if this scope is a (var) declaration scope.
bool is_declaration_scope();
bool is_declaration_scope() const;
// Does this scope make a sloppy eval call?
bool CallsSloppyEval();
bool CallsSloppyEval() const;
// Return the total number of locals allocated on the stack and in the
// context. This includes the parameters that are allocated in the context.
int LocalCount();
int LocalCount() const;
// Return the number of stack slots for code. This number consists of two
// parts:
// 1. One stack slot per stack allocated local.
// 2. One stack slot for the function name if it is stack allocated.
int StackSlotCount();
int StackSlotCount() const;
// Return the number of context slots for code if a context is allocated. This
// number consists of three parts:
......@@ -66,57 +66,60 @@ class ScopeInfo : public FixedArray {
// 3. One context slot for the function name if it is context allocated.
// Parameters allocated in the context count as context allocated locals. If
// no contexts are allocated for this scope ContextLength returns 0.
int ContextLength();
int ContextLength() const;
// Does this scope declare a "this" binding?
bool HasReceiver();
bool HasReceiver() const;
// Does this scope declare a "this" binding, and the "this" binding is stack-
// or context-allocated?
bool HasAllocatedReceiver();
bool HasAllocatedReceiver() const;
// Does this scope declare a "new.target" binding?
bool HasNewTarget();
bool HasNewTarget() const;
// Is this scope the scope of a named function expression?
bool HasFunctionName();
bool HasFunctionName() const;
bool HasPendingFunctionName() const;
void SetPendingFunctionName(String* name);
// Return if contexts are allocated for this scope.
bool HasContext();
bool HasContext() const;
// Return if this is a function scope with "use asm".
inline bool IsAsmModule();
inline bool IsAsmModule() const;
inline bool HasSimpleParameters();
inline bool HasSimpleParameters() const;
// Return the function_name if present.
String* FunctionName();
String* FunctionName() const;
ModuleInfo* ModuleDescriptorInfo();
ModuleInfo* ModuleDescriptorInfo() const;
// Return the name of the given parameter.
String* ParameterName(int var);
String* ParameterName(int var) const;
// Return the name of the given local.
String* LocalName(int var);
String* LocalName(int var) const;
// Return the name of the given stack local.
String* StackLocalName(int var);
String* StackLocalName(int var) const;
// Return the name of the given stack local.
int StackLocalIndex(int var);
int StackLocalIndex(int var) const;
// Return the name of the given context local.
String* ContextLocalName(int var);
String* ContextLocalName(int var) const;
// Return the mode of the given context local.
VariableMode ContextLocalMode(int var);
VariableMode ContextLocalMode(int var) const;
// Return the initialization flag of the given context local.
InitializationFlag ContextLocalInitFlag(int var);
InitializationFlag ContextLocalInitFlag(int var) const;
// Return the initialization flag of the given context local.
MaybeAssignedFlag ContextLocalMaybeAssignedFlag(int var);
MaybeAssignedFlag ContextLocalMaybeAssignedFlag(int var) const;
// Return true if this local was introduced by the compiler, and should not be
// exposed to the user in a debugger.
......@@ -126,7 +129,7 @@ class ScopeInfo : public FixedArray {
// the stack slot index for a given slot name if the slot is
// present; otherwise returns a value < 0. The name must be an internalized
// string.
int StackSlotIndex(String* name);
int StackSlotIndex(String* name) const;
// Lookup support for serialized scope info. Returns the local context slot
// index for a given slot name if the slot is present; otherwise
......@@ -147,33 +150,33 @@ class ScopeInfo : public FixedArray {
// Lookup support for serialized scope info. Returns the
// parameter index for a given parameter name if the parameter is present;
// otherwise returns a value < 0. The name must be an internalized string.
int ParameterIndex(String* name);
int ParameterIndex(String* name) const;
// Lookup support for serialized scope info. Returns the function context
// slot index if the function name is present and context-allocated (named
// function expressions, only), otherwise returns a value < 0. The name
// must be an internalized string.
int FunctionContextSlotIndex(String* name);
int FunctionContextSlotIndex(String* name) const;
// Lookup support for serialized scope info. Returns the receiver context
// slot index if scope has a "this" binding, and the binding is
// context-allocated. Otherwise returns a value < 0.
int ReceiverContextSlotIndex();
int ReceiverContextSlotIndex() const;
FunctionKind function_kind();
FunctionKind function_kind() const;
// Returns true if this ScopeInfo is linked to a outer ScopeInfo.
bool HasOuterScopeInfo();
bool HasOuterScopeInfo() const;
// Returns true if this ScopeInfo was created for a debug-evaluate scope.
bool IsDebugEvaluateScope();
bool IsDebugEvaluateScope() const;
// Can be used to mark a ScopeInfo that looks like a with-scope as actually
// being a debug-evaluate scope.
void SetIsDebugEvaluateScope();
// Return the outer ScopeInfo if present.
ScopeInfo* OuterScopeInfo();
ScopeInfo* OuterScopeInfo() const;
#ifdef DEBUG
bool Equals(ScopeInfo* other) const;
......@@ -203,7 +206,7 @@ class ScopeInfo : public FixedArray {
#define FIELD_ACCESSORS(name) \
inline void Set##name(int value); \
inline int name();
inline int name() const;
FOR_EACH_SCOPE_INFO_NUMERIC_FIELD(FIELD_ACCESSORS)
#undef FIELD_ACCESSORS
......@@ -255,17 +258,17 @@ class ScopeInfo : public FixedArray {
// For a module scope, this part contains the ModuleInfo, the number of
// MODULE-allocated variables, and the metadata of those variables. For
// non-module scopes it is empty.
int ParameterNamesIndex();
int StackLocalFirstSlotIndex();
int StackLocalNamesIndex();
int ContextLocalNamesIndex();
int ContextLocalInfosIndex();
int ReceiverInfoIndex();
int FunctionNameInfoIndex();
int OuterScopeInfoIndex();
int ModuleInfoIndex();
int ModuleVariableCountIndex();
int ModuleVariablesIndex();
int ParameterNamesIndex() const;
int StackLocalFirstSlotIndex() const;
int StackLocalNamesIndex() const;
int ContextLocalNamesIndex() const;
int ContextLocalInfosIndex() const;
int ReceiverInfoIndex() const;
int FunctionNameInfoIndex() const;
int OuterScopeInfoIndex() const;
int ModuleInfoIndex() const;
int ModuleVariableCountIndex() const;
int ModuleVariablesIndex() const;
int Lookup(Handle<String> name, int start, int end, VariableMode* mode,
VariableLocation* location, InitializationFlag* init_flag,
......
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