Commit c3504034 authored by Camillo Bruni's avatar Camillo Bruni Committed by Commit Bot

[parser] Only use write barriers conditionally in ScopeInfo::Create

Change-Id: Ia082e676e2cabab07c99b424f80b91e9459f1d3d
Reviewed-on: https://chromium-review.googlesource.com/c/1430070Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Camillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59112}
parent 1bc801a1
...@@ -477,15 +477,10 @@ void ObjectLiteral::BuildBoilerplateDescription(Isolate* isolate) { ...@@ -477,15 +477,10 @@ void ObjectLiteral::BuildBoilerplateDescription(Isolate* isolate) {
has_seen_proto = true; has_seen_proto = true;
continue; continue;
} }
if (property->is_computed_name()) { if (property->is_computed_name()) continue;
continue;
}
Literal* key = property->key()->AsLiteral(); Literal* key = property->key()->AsLiteral();
if (!key->IsPropertyName()) index_keys++;
if (!key->IsPropertyName()) {
index_keys++;
}
} }
Handle<ObjectBoilerplateDescription> boilerplate_description = Handle<ObjectBoilerplateDescription> boilerplate_description =
......
...@@ -148,172 +148,176 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope, ...@@ -148,172 +148,176 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
? 2 + kModuleVariableEntryLength * module_vars_count ? 2 + kModuleVariableEntryLength * module_vars_count
: 0); : 0);
Factory* factory = isolate->factory(); Handle<ScopeInfo> scope_info_handle =
Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length); isolate->factory()->NewScopeInfo(length);
bool has_simple_parameters = false;
bool is_asm_module = false;
bool calls_sloppy_eval = false;
if (scope->is_function_scope()) {
DeclarationScope* function_scope = scope->AsDeclarationScope();
has_simple_parameters = function_scope->has_simple_parameters();
is_asm_module = function_scope->is_asm_module();
}
FunctionKind function_kind = kNormalFunction;
if (scope->is_declaration_scope()) {
function_kind = scope->AsDeclarationScope()->function_kind();
calls_sloppy_eval = scope->AsDeclarationScope()->calls_sloppy_eval();
}
// Encode the flags.
int flags =
ScopeTypeField::encode(scope->scope_type()) |
CallsSloppyEvalField::encode(calls_sloppy_eval) |
LanguageModeField::encode(scope->language_mode()) |
DeclarationScopeField::encode(scope->is_declaration_scope()) |
ReceiverVariableField::encode(receiver_info) |
HasNewTargetField::encode(has_new_target) |
FunctionVariableField::encode(function_name_info) |
HasInferredFunctionNameField::encode(has_inferred_function_name) |
IsAsmModuleField::encode(is_asm_module) |
HasSimpleParametersField::encode(has_simple_parameters) |
FunctionKindField::encode(function_kind) |
HasOuterScopeInfoField::encode(has_outer_scope_info) |
IsDebugEvaluateScopeField::encode(scope->is_debug_evaluate_scope()) |
ForceContextAllocationField::encode(scope->ForceContextForLanguageMode());
scope_info->SetFlags(flags);
scope_info->SetParameterCount(parameter_count);
scope_info->SetContextLocalCount(context_local_count);
int index = kVariablePartIndex; int index = kVariablePartIndex;
{
DisallowHeapAllocation no_gc;
ScopeInfo scope_info = *scope_info_handle;
WriteBarrierMode mode = scope_info->GetWriteBarrierMode(no_gc);
bool has_simple_parameters = false;
bool is_asm_module = false;
bool calls_sloppy_eval = false;
if (scope->is_function_scope()) {
DeclarationScope* function_scope = scope->AsDeclarationScope();
has_simple_parameters = function_scope->has_simple_parameters();
is_asm_module = function_scope->is_asm_module();
}
FunctionKind function_kind = kNormalFunction;
if (scope->is_declaration_scope()) {
function_kind = scope->AsDeclarationScope()->function_kind();
calls_sloppy_eval = scope->AsDeclarationScope()->calls_sloppy_eval();
}
// Add context locals' names and info, module variables' names and info. // Encode the flags.
// Context locals are added using their index. int flags =
int context_local_base = index; ScopeTypeField::encode(scope->scope_type()) |
int context_local_info_base = context_local_base + context_local_count; CallsSloppyEvalField::encode(calls_sloppy_eval) |
int module_var_entry = scope_info->ModuleVariablesIndex(); LanguageModeField::encode(scope->language_mode()) |
DeclarationScopeField::encode(scope->is_declaration_scope()) |
for (Variable* var : *scope->locals()) { ReceiverVariableField::encode(receiver_info) |
switch (var->location()) { HasNewTargetField::encode(has_new_target) |
case VariableLocation::CONTEXT: { FunctionVariableField::encode(function_name_info) |
// Due to duplicate parameters, context locals aren't guaranteed to come HasInferredFunctionNameField::encode(has_inferred_function_name) |
// in order. IsAsmModuleField::encode(is_asm_module) |
int local_index = var->index() - Context::MIN_CONTEXT_SLOTS; HasSimpleParametersField::encode(has_simple_parameters) |
DCHECK_LE(0, local_index); FunctionKindField::encode(function_kind) |
DCHECK_LT(local_index, context_local_count); HasOuterScopeInfoField::encode(has_outer_scope_info) |
uint32_t info = IsDebugEvaluateScopeField::encode(scope->is_debug_evaluate_scope()) |
VariableModeField::encode(var->mode()) | ForceContextAllocationField::encode(
InitFlagField::encode(var->initialization_flag()) | scope->ForceContextForLanguageMode());
MaybeAssignedFlagField::encode(var->maybe_assigned()) | scope_info->SetFlags(flags);
ParameterNumberField::encode(ParameterNumberField::kMax);
scope_info->set(context_local_base + local_index, *var->name()); scope_info->SetParameterCount(parameter_count);
scope_info->set(context_local_info_base + local_index, scope_info->SetContextLocalCount(context_local_count);
Smi::FromInt(info));
break; // Add context locals' names and info, module variables' names and info.
} // Context locals are added using their index.
case VariableLocation::MODULE: { int context_local_base = index;
scope_info->set(module_var_entry + kModuleVariableNameOffset, int context_local_info_base = context_local_base + context_local_count;
*var->name()); int module_var_entry = scope_info->ModuleVariablesIndex();
scope_info->set(module_var_entry + kModuleVariableIndexOffset,
Smi::FromInt(var->index())); for (Variable* var : *scope->locals()) {
uint32_t properties = switch (var->location()) {
VariableModeField::encode(var->mode()) | case VariableLocation::CONTEXT: {
InitFlagField::encode(var->initialization_flag()) | // Due to duplicate parameters, context locals aren't guaranteed to
MaybeAssignedFlagField::encode(var->maybe_assigned()) | // come in order.
ParameterNumberField::encode(ParameterNumberField::kMax); int local_index = var->index() - Context::MIN_CONTEXT_SLOTS;
scope_info->set(module_var_entry + kModuleVariablePropertiesOffset, DCHECK_LE(0, local_index);
Smi::FromInt(properties)); DCHECK_LT(local_index, context_local_count);
module_var_entry += kModuleVariableEntryLength; uint32_t info =
break; VariableModeField::encode(var->mode()) |
InitFlagField::encode(var->initialization_flag()) |
MaybeAssignedFlagField::encode(var->maybe_assigned()) |
ParameterNumberField::encode(ParameterNumberField::kMax);
scope_info->set(context_local_base + local_index, *var->name(), mode);
scope_info->set(context_local_info_base + local_index,
Smi::FromInt(info), mode);
break;
}
case VariableLocation::MODULE: {
scope_info->set(module_var_entry + kModuleVariableNameOffset,
*var->name(), mode);
scope_info->set(module_var_entry + kModuleVariableIndexOffset,
Smi::FromInt(var->index()), mode);
uint32_t properties =
VariableModeField::encode(var->mode()) |
InitFlagField::encode(var->initialization_flag()) |
MaybeAssignedFlagField::encode(var->maybe_assigned()) |
ParameterNumberField::encode(ParameterNumberField::kMax);
scope_info->set(module_var_entry + kModuleVariablePropertiesOffset,
Smi::FromInt(properties), mode);
module_var_entry += kModuleVariableEntryLength;
break;
}
default:
break;
} }
default:
break;
} }
}
if (scope->is_declaration_scope()) { if (scope->is_declaration_scope()) {
// Mark contexts slots with the parameter number they represent. We walk the // Mark contexts slots with the parameter number they represent. We walk
// list of parameters. That can include duplicate entries if a parameter // the list of parameters. That can include duplicate entries if a
// name is repeated. By walking upwards, we'll automatically mark the // parameter name is repeated. By walking upwards, we'll automatically
// context slot with the highest parameter number that uses this variable. // mark the context slot with the highest parameter number that uses this
// That will be the parameter number that is represented by the context // variable. That will be the parameter number that is represented by the
// slot. All lower parameters will only be available on the stack through // context slot. All lower parameters will only be available on the stack
// the arguments object. // through the arguments object.
for (int i = 0; i < parameter_count; i++) { for (int i = 0; i < parameter_count; i++) {
Variable* parameter = scope->AsDeclarationScope()->parameter(i); Variable* parameter = scope->AsDeclarationScope()->parameter(i);
if (parameter->location() != VariableLocation::CONTEXT) continue; if (parameter->location() != VariableLocation::CONTEXT) continue;
int index = parameter->index() - Context::MIN_CONTEXT_SLOTS; int index = parameter->index() - Context::MIN_CONTEXT_SLOTS;
int info_index = context_local_info_base + index; int info_index = context_local_info_base + index;
int info = Smi::ToInt(scope_info->get(info_index)); int info = Smi::ToInt(scope_info->get(info_index));
info = ParameterNumberField::update(info, i); info = ParameterNumberField::update(info, i);
scope_info->set(info_index, Smi::FromInt(info)); scope_info->set(info_index, Smi::FromInt(info), mode);
}
} }
}
index += 2 * context_local_count; index += 2 * context_local_count;
// If the receiver is allocated, add its index. // If the receiver is allocated, add its index.
DCHECK_EQ(index, scope_info->ReceiverInfoIndex()); DCHECK_EQ(index, scope_info->ReceiverInfoIndex());
if (has_receiver) { if (has_receiver) {
int var_index = scope->AsDeclarationScope()->receiver()->index(); int var_index = scope->AsDeclarationScope()->receiver()->index();
scope_info->set(index++, Smi::FromInt(var_index)); scope_info->set(index++, Smi::FromInt(var_index), mode);
// ?? DCHECK(receiver_info != CONTEXT || var_index == // ?? DCHECK(receiver_info != CONTEXT || var_index ==
// scope_info->ContextLength() - 1); // scope_info->ContextLength() - 1);
} }
// If present, add the function variable name and its index. // If present, add the function variable name and its index.
DCHECK_EQ(index, scope_info->FunctionNameInfoIndex()); DCHECK_EQ(index, scope_info->FunctionNameInfoIndex());
if (has_function_name) { if (has_function_name) {
DisallowHeapAllocation no_gc; Variable* var = scope->AsDeclarationScope()->function_var();
Variable* var = scope->AsDeclarationScope()->function_var(); int var_index = -1;
int var_index = -1; Object name = Smi::kZero;
Object name = Smi::kZero; if (var != nullptr) {
if (var != nullptr) { var_index = var->index();
var_index = var->index(); name = *var->name();
name = *var->name(); }
scope_info->set(index++, name, mode);
scope_info->set(index++, Smi::FromInt(var_index), mode);
DCHECK(function_name_info != CONTEXT ||
var_index == scope_info->ContextLength() - 1);
} }
scope_info->set(index++, name);
scope_info->set(index++, Smi::FromInt(var_index));
DCHECK(function_name_info != CONTEXT ||
var_index == scope_info->ContextLength() - 1);
}
DCHECK_EQ(index, scope_info->InferredFunctionNameIndex()); DCHECK_EQ(index, scope_info->InferredFunctionNameIndex());
if (has_inferred_function_name) { if (has_inferred_function_name) {
// The inferred function name is taken from the SFI. // The inferred function name is taken from the SFI.
index++; index++;
} }
DCHECK_EQ(index, scope_info->PositionInfoIndex()); DCHECK_EQ(index, scope_info->PositionInfoIndex());
if (has_position_info) { if (has_position_info) {
scope_info->set(index++, Smi::FromInt(scope->start_position())); scope_info->set(index++, Smi::FromInt(scope->start_position()), mode);
scope_info->set(index++, Smi::FromInt(scope->end_position())); scope_info->set(index++, Smi::FromInt(scope->end_position()), mode);
} }
// If present, add the outer scope info. // If present, add the outer scope info.
DCHECK(index == scope_info->OuterScopeInfoIndex()); DCHECK(index == scope_info->OuterScopeInfoIndex());
if (has_outer_scope_info) { if (has_outer_scope_info) {
scope_info->set(index++, *outer_scope.ToHandleChecked()); scope_info->set(index++, *outer_scope.ToHandleChecked(), mode);
}
} }
// Module-specific information (only for module scopes). // Module-specific information (only for module scopes).
if (scope->is_module_scope()) { if (scope->is_module_scope()) {
Handle<ModuleInfo> module_info = Handle<ModuleInfo> module_info =
ModuleInfo::New(isolate, zone, scope->AsModuleScope()->module()); ModuleInfo::New(isolate, zone, scope->AsModuleScope()->module());
DCHECK_EQ(index, scope_info->ModuleInfoIndex()); DCHECK_EQ(index, scope_info_handle->ModuleInfoIndex());
scope_info->set(index++, *module_info); scope_info_handle->set(index++, *module_info);
DCHECK_EQ(index, scope_info->ModuleVariableCountIndex()); DCHECK_EQ(index, scope_info_handle->ModuleVariableCountIndex());
scope_info->set(index++, Smi::FromInt(module_vars_count)); scope_info_handle->set(index++, Smi::FromInt(module_vars_count));
DCHECK_EQ(index, scope_info->ModuleVariablesIndex()); DCHECK_EQ(index, scope_info_handle->ModuleVariablesIndex());
// The variable entries themselves have already been written above. // The variable entries themselves have already been written above.
index += kModuleVariableEntryLength * module_vars_count; index += kModuleVariableEntryLength * module_vars_count;
} }
DCHECK_EQ(index, scope_info->length()); DCHECK_EQ(index, scope_info_handle->length());
DCHECK_EQ(scope->num_parameters(), scope_info->ParameterCount()); DCHECK_EQ(scope->num_parameters(), scope_info_handle->ParameterCount());
DCHECK_EQ(scope->num_heap_slots(), scope_info->ContextLength()); DCHECK_EQ(scope->num_heap_slots(), scope_info_handle->ContextLength());
return scope_info; return scope_info_handle;
} }
// static // static
......
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