Skip to content

Commit 467eb14

Browse files
verwaestCommit Bot
authored andcommitted
Drop stack-locals from ScopeInfo
For now we keep params since NewSloppyArguments uses it to figure out how to structure the arguments object. We should be able to only keep params in case we have a special case though. E.g., leaf functions with no duplicate parameters don't need special treatment. Or we simply encode the parameter index for each context slot. (I'm not sure duplicates need special treatment.) Change-Id: Icfbb844e5331aeb93c50bc07edd58246c8aeb1d7 Reviewed-on: https://chromium-review.googlesource.com/1104420 Commit-Queue: Toon Verwaest <[email protected]> Reviewed-by: Camillo Bruni <[email protected]> Cr-Commit-Position: refs/heads/master@{#53802}
1 parent 6be6ec0 commit 467eb14

8 files changed

Lines changed: 20 additions & 212 deletions

File tree

src/ast/scopes.cc

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,6 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
439439
ModuleScope(isolate, handle(scope_info, isolate), ast_value_factory);
440440
} else {
441441
DCHECK_EQ(scope_info->scope_type(), CATCH_SCOPE);
442-
DCHECK_EQ(scope_info->LocalCount(), 1);
443442
DCHECK_EQ(scope_info->ContextLocalCount(), 1);
444443
DCHECK_EQ(scope_info->ContextLocalMode(0), VariableMode::kVar);
445444
DCHECK_EQ(scope_info->ContextLocalInitFlag(0), kCreatedInitialized);
@@ -958,10 +957,6 @@ Variable* Scope::LookupInScopeInfo(const AstRawString* name) {
958957
// The Scope is backed up by ScopeInfo. This means it cannot operate in a
959958
// heap-independent mode, and all strings must be internalized immediately. So
960959
// it's ok to get the Handle<String> here.
961-
// If we have a serialized scope info, we might find the variable there.
962-
// There should be no local slot with the given name.
963-
DCHECK_LT(scope_info_->StackSlotIndex(*name_handle), 0);
964-
965960
bool found = false;
966961

967962
VariableLocation location;

src/frames.cc

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2028,26 +2028,9 @@ void JavaScriptFrame::Print(StringStream* accumulator,
20282028
accumulator->Add(" {\n");
20292029

20302030
// Compute the number of locals and expression stack elements.
2031-
int stack_locals_count = scope_info->StackLocalCount();
20322031
int heap_locals_count = scope_info->ContextLocalCount();
20332032
int expressions_count = ComputeExpressionsCount();
20342033

2035-
// Print stack-allocated local variables.
2036-
if (stack_locals_count > 0) {
2037-
accumulator->Add(" // stack-allocated locals\n");
2038-
}
2039-
for (int i = 0; i < stack_locals_count; i++) {
2040-
accumulator->Add(" var ");
2041-
accumulator->PrintName(scope_info->StackLocalName(i));
2042-
accumulator->Add(" = ");
2043-
if (i < expressions_count) {
2044-
accumulator->Add("%o", GetExpression(i));
2045-
} else {
2046-
accumulator->Add("// no expression found - inconsistent frame?");
2047-
}
2048-
accumulator->Add("\n");
2049-
}
2050-
20512034
// Try to get hold of the context of this frame.
20522035
Context* context = nullptr;
20532036
if (this->context() != nullptr && this->context()->IsContext()) {
@@ -2081,11 +2064,10 @@ void JavaScriptFrame::Print(StringStream* accumulator,
20812064
}
20822065

20832066
// Print the expression stack.
2084-
int expressions_start = stack_locals_count;
2085-
if (expressions_start < expressions_count) {
2067+
if (0 < expressions_count) {
20862068
accumulator->Add(" // expression stack (top to bottom)\n");
20872069
}
2088-
for (int i = expressions_count - 1; i >= expressions_start; i--) {
2070+
for (int i = expressions_count - 1; i >= 0; i--) {
20892071
accumulator->Add(" [%02d] : %o\n", i, GetExpression(i));
20902072
}
20912073

src/gdb-jit.cc

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,11 +1171,9 @@ class DebugInfoSection : public DebugSection {
11711171
fb_block_size.set(static_cast<uint32_t>(w->position() - fb_block_start));
11721172

11731173
int params = scope->ParameterCount();
1174-
int slots = scope->StackLocalCount();
11751174
int context_slots = scope->ContextLocalCount();
11761175
// The real slot ID is internal_slots + context_slot_id.
11771176
int internal_slots = Context::MIN_CONTEXT_SLOTS;
1178-
int locals = scope->StackLocalCount();
11791177
int current_abbreviation = 4;
11801178

11811179
for (int param = 0; param < params; ++param) {
@@ -1195,13 +1193,6 @@ class DebugInfoSection : public DebugSection {
11951193
EmbeddedVector<char, 256> buffer;
11961194
StringBuilder builder(buffer.start(), buffer.length());
11971195

1198-
for (int slot = 0; slot < slots; ++slot) {
1199-
w->WriteULEB128(current_abbreviation++);
1200-
builder.Reset();
1201-
builder.AddFormatted("slot%d", slot);
1202-
w->WriteString(builder.Finalize());
1203-
}
1204-
12051196
// See contexts.h for more information.
12061197
DCHECK_EQ(Context::MIN_CONTEXT_SLOTS, 4);
12071198
DCHECK_EQ(Context::SCOPE_INFO_INDEX, 0);
@@ -1226,20 +1217,6 @@ class DebugInfoSection : public DebugSection {
12261217
w->WriteString(builder.Finalize());
12271218
}
12281219

1229-
for (int local = 0; local < locals; ++local) {
1230-
w->WriteULEB128(current_abbreviation++);
1231-
w->WriteString(
1232-
scope->StackLocalName(local)->ToCString(DISALLOW_NULLS).get());
1233-
w->Write<uint32_t>(ty_offset);
1234-
Writer::Slot<uint32_t> block_size = w->CreateSlotHere<uint32_t>();
1235-
uintptr_t block_start = w->position();
1236-
w->Write<uint8_t>(DW_OP_fbreg);
1237-
w->WriteSLEB128(
1238-
JavaScriptFrameConstants::kLocal0Offset -
1239-
kPointerSize * local);
1240-
block_size.set(static_cast<uint32_t>(w->position() - block_start));
1241-
}
1242-
12431220
{
12441221
w->WriteULEB128(current_abbreviation++);
12451222
w->WriteString("__function");
@@ -1370,13 +1347,11 @@ class DebugAbbrevSection : public DebugSection {
13701347
if (extra_info) {
13711348
ScopeInfo* scope = desc_->scope_info();
13721349
int params = scope->ParameterCount();
1373-
int slots = scope->StackLocalCount();
13741350
int context_slots = scope->ContextLocalCount();
13751351
// The real slot ID is internal_slots + context_slot_id.
13761352
int internal_slots = Context::MIN_CONTEXT_SLOTS;
1377-
int locals = scope->StackLocalCount();
1378-
// Total children is params + slots + context_slots + internal_slots +
1379-
// locals + 2 (__function and __context).
1353+
// Total children is params + context_slots + internal_slots + 2
1354+
// (__function and __context).
13801355

13811356
// The extra duplication below seems to be necessary to keep
13821357
// gdb from getting upset on OSX.
@@ -1408,10 +1383,6 @@ class DebugAbbrevSection : public DebugSection {
14081383
WriteVariableAbbreviation(w, current_abbreviation++, true, true);
14091384
}
14101385

1411-
for (int slot = 0; slot < slots; ++slot) {
1412-
WriteVariableAbbreviation(w, current_abbreviation++, false, false);
1413-
}
1414-
14151386
for (int internal_slot = 0;
14161387
internal_slot < internal_slots;
14171388
++internal_slot) {
@@ -1424,10 +1395,6 @@ class DebugAbbrevSection : public DebugSection {
14241395
WriteVariableAbbreviation(w, current_abbreviation++, false, false);
14251396
}
14261397

1427-
for (int local = 0; local < locals; ++local) {
1428-
WriteVariableAbbreviation(w, current_abbreviation++, true, false);
1429-
}
1430-
14311398
// The function.
14321399
WriteVariableAbbreviation(w, current_abbreviation++, true, false);
14331400

src/objects-printer.cc

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,6 @@ void ScopeInfo::ScopeInfoPrint(std::ostream& os) { // NOLINT
19931993
int flags = Flags();
19941994

19951995
os << "\n - parameters: " << ParameterCount();
1996-
os << "\n - stack locals: " << StackLocalCount();
19971996
os << "\n - context locals : " << ContextLocalCount();
19981997

19991998
os << "\n - scope type: " << scope_type();
@@ -2030,8 +2029,6 @@ void ScopeInfo::ScopeInfoPrint(std::ostream& os) { // NOLINT
20302029
if (length() > 0) {
20312030
PrintScopeInfoList(this, os, "parameters", 0, ParameterNamesIndex(),
20322031
ParameterCount());
2033-
PrintScopeInfoList(this, os, "stack slots", 0, StackLocalNamesIndex(),
2034-
StackLocalCount());
20352032
PrintScopeInfoList(this, os, "context slots", Context::MIN_CONTEXT_SLOTS,
20362033
ContextLocalNamesIndex(), ContextLocalCount());
20372034
// TODO(neis): Print module stuff if present.

src/objects/scope-info.cc

Lines changed: 7 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -63,20 +63,14 @@ bool ScopeInfo::Equals(ScopeInfo* other) const {
6363
Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
6464
MaybeHandle<ScopeInfo> outer_scope) {
6565
// Collect variables.
66-
int stack_local_count = 0;
6766
int context_local_count = 0;
6867
int module_vars_count = 0;
6968
// Stack allocated block scope variables are allocated in the parent
7069
// declaration scope, but are recorded in the block scope's scope info. First
7170
// slot index indicates at which offset a particular scope starts in the
7271
// parent declaration scope.
73-
int first_slot_index = 0;
7472
for (Variable* var : *scope->locals()) {
7573
switch (var->location()) {
76-
case VariableLocation::LOCAL:
77-
if (stack_local_count == 0) first_slot_index = var->index();
78-
stack_local_count++;
79-
break;
8074
case VariableLocation::CONTEXT:
8175
context_local_count++;
8276
break;
@@ -146,8 +140,7 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
146140
const int parameter_count = scope->num_parameters();
147141
const bool has_outer_scope_info = !outer_scope.is_null();
148142
const int length = kVariablePartIndex + parameter_count +
149-
(1 + stack_local_count) + 2 * context_local_count +
150-
(has_receiver ? 1 : 0) +
143+
2 * context_local_count + (has_receiver ? 1 : 0) +
151144
(has_function_name ? kFunctionNameEntries : 0) +
152145
(has_inferred_function_name ? 1 : 0) +
153146
(has_position_info ? kPositionInfoEntries : 0) +
@@ -191,7 +184,6 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
191184
scope_info->SetFlags(flags);
192185

193186
scope_info->SetParameterCount(parameter_count);
194-
scope_info->SetStackLocalCount(stack_local_count);
195187
scope_info->SetContextLocalCount(context_local_count);
196188

197189
int index = kVariablePartIndex;
@@ -204,28 +196,14 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
204196
}
205197
}
206198

207-
// Add stack locals' names, context locals' names and info, module variables'
208-
// names and info. We are assuming that the stack locals' slots are allocated
209-
// in increasing order, so we can simply add them to the ScopeInfo object.
199+
// Add context locals' names and info, module variables' names and info.
210200
// Context locals are added using their index.
211-
DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex());
212-
scope_info->set(index++, Smi::FromInt(first_slot_index));
213-
DCHECK_EQ(index, scope_info->StackLocalNamesIndex());
214-
215-
int stack_local_base = index;
216-
int context_local_base = stack_local_base + stack_local_count;
201+
int context_local_base = index;
217202
int context_local_info_base = context_local_base + context_local_count;
218203
int module_var_entry = scope_info->ModuleVariablesIndex();
219204

220205
for (Variable* var : *scope->locals()) {
221206
switch (var->location()) {
222-
case VariableLocation::LOCAL: {
223-
int local_index = var->index() - first_slot_index;
224-
DCHECK_LE(0, local_index);
225-
DCHECK_LT(local_index, stack_local_count);
226-
scope_info->set(stack_local_base + local_index, *var->name());
227-
break;
228-
}
229207
case VariableLocation::CONTEXT: {
230208
// Due to duplicate parameters, context locals aren't guaranteed to come
231209
// in order.
@@ -259,7 +237,7 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
259237
}
260238
}
261239

262-
index += stack_local_count + 2 * context_local_count;
240+
index += 2 * context_local_count;
263241

264242
// If the receiver is allocated, add its index.
265243
DCHECK_EQ(index, scope_info->ReceiverInfoIndex());
@@ -328,7 +306,7 @@ Handle<ScopeInfo> ScopeInfo::Create(Isolate* isolate, Zone* zone, Scope* scope,
328306
Handle<ScopeInfo> ScopeInfo::CreateForWithScope(
329307
Isolate* isolate, MaybeHandle<ScopeInfo> outer_scope) {
330308
const bool has_outer_scope_info = !outer_scope.is_null();
331-
const int length = kVariablePartIndex + 1 + (has_outer_scope_info ? 1 : 0);
309+
const int length = kVariablePartIndex + (has_outer_scope_info ? 1 : 0);
332310

333311
Factory* factory = isolate->factory();
334312
Handle<ScopeInfo> scope_info = factory->NewScopeInfo(length);
@@ -347,14 +325,10 @@ Handle<ScopeInfo> ScopeInfo::CreateForWithScope(
347325
scope_info->SetFlags(flags);
348326

349327
scope_info->SetParameterCount(0);
350-
scope_info->SetStackLocalCount(0);
351328
scope_info->SetContextLocalCount(0);
352329

353330
int index = kVariablePartIndex;
354331
DCHECK_EQ(index, scope_info->ParameterNamesIndex());
355-
DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex());
356-
scope_info->set(index++, Smi::kZero);
357-
DCHECK_EQ(index, scope_info->StackLocalNamesIndex());
358332
DCHECK_EQ(index, scope_info->ReceiverInfoIndex());
359333
DCHECK_EQ(index, scope_info->FunctionNameInfoIndex());
360334
DCHECK_EQ(index, scope_info->InferredFunctionNameIndex());
@@ -386,15 +360,13 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
386360
DCHECK(type == SCRIPT_SCOPE || type == FUNCTION_SCOPE);
387361

388362
const int parameter_count = 0;
389-
const int stack_local_count = 0;
390363
const bool is_empty_function = type == FUNCTION_SCOPE;
391364
const int context_local_count = is_empty_function ? 0 : 1;
392365
const bool has_receiver = !is_empty_function;
393366
const bool has_inferred_function_name = is_empty_function;
394367
const bool has_position_info = true;
395368
const int length = kVariablePartIndex + parameter_count +
396-
(1 + stack_local_count) + 2 * context_local_count +
397-
(has_receiver ? 1 : 0) +
369+
2 * context_local_count + (has_receiver ? 1 : 0) +
398370
(is_empty_function ? kFunctionNameEntries : 0) +
399371
(has_inferred_function_name ? 1 : 0) +
400372
(has_position_info ? kPositionInfoEntries : 0);
@@ -417,14 +389,9 @@ Handle<ScopeInfo> ScopeInfo::CreateForBootstrapping(Isolate* isolate,
417389
IsDebugEvaluateScopeField::encode(false);
418390
scope_info->SetFlags(flags);
419391
scope_info->SetParameterCount(parameter_count);
420-
scope_info->SetStackLocalCount(stack_local_count);
421392
scope_info->SetContextLocalCount(context_local_count);
422393

423394
int index = kVariablePartIndex;
424-
const int first_slot_index = 0;
425-
DCHECK_EQ(index, scope_info->StackLocalFirstSlotIndex());
426-
scope_info->set(index++, Smi::FromInt(first_slot_index));
427-
DCHECK_EQ(index, scope_info->StackLocalNamesIndex());
428395

429396
// Here we add info for context-allocated "this".
430397
DCHECK_EQ(index, scope_info->ContextLocalNamesIndex());
@@ -497,19 +464,6 @@ bool ScopeInfo::is_declaration_scope() const {
497464
return DeclarationScopeField::decode(Flags());
498465
}
499466

500-
int ScopeInfo::LocalCount() const {
501-
return StackLocalCount() + ContextLocalCount();
502-
}
503-
504-
int ScopeInfo::StackSlotCount() const {
505-
if (length() > 0) {
506-
bool function_name_stack_slot =
507-
FunctionVariableField::decode(Flags()) == STACK;
508-
return StackLocalCount() + (function_name_stack_slot ? 1 : 0);
509-
}
510-
return 0;
511-
}
512-
513467
int ScopeInfo::ContextLength() const {
514468
if (length() > 0) {
515469
int context_locals = ContextLocalCount();
@@ -659,29 +613,6 @@ String* ScopeInfo::ParameterName(int var) const {
659613
return String::cast(get(info_index));
660614
}
661615

662-
String* ScopeInfo::LocalName(int var) const {
663-
DCHECK_LE(0, var);
664-
DCHECK_LT(var, LocalCount());
665-
DCHECK(StackLocalNamesIndex() + StackLocalCount() ==
666-
ContextLocalNamesIndex());
667-
int info_index = StackLocalNamesIndex() + var;
668-
return String::cast(get(info_index));
669-
}
670-
671-
String* ScopeInfo::StackLocalName(int var) const {
672-
DCHECK_LE(0, var);
673-
DCHECK_LT(var, StackLocalCount());
674-
int info_index = StackLocalNamesIndex() + var;
675-
return String::cast(get(info_index));
676-
}
677-
678-
int ScopeInfo::StackLocalIndex(int var) const {
679-
DCHECK_LE(0, var);
680-
DCHECK_LT(var, StackLocalCount());
681-
int first_slot_index = Smi::ToInt(get(StackLocalFirstSlotIndex()));
682-
return first_slot_index + var;
683-
}
684-
685616
String* ScopeInfo::ContextLocalName(int var) const {
686617
DCHECK_LE(0, var);
687618
DCHECK_LT(var, ContextLocalCount());
@@ -723,20 +654,6 @@ bool ScopeInfo::VariableIsSynthetic(String* name) {
723654
name->Equals(name->GetHeap()->this_string());
724655
}
725656

726-
int ScopeInfo::StackSlotIndex(String* name) const {
727-
DCHECK(name->IsInternalizedString());
728-
if (length() == 0) return -1;
729-
int first_slot_index = Smi::ToInt(get(StackLocalFirstSlotIndex()));
730-
int start = StackLocalNamesIndex();
731-
int end = start + StackLocalCount();
732-
for (int i = start; i < end; ++i) {
733-
if (name == get(i)) {
734-
return i - start + first_slot_index;
735-
}
736-
}
737-
return -1;
738-
}
739-
740657
int ScopeInfo::ModuleIndex(Handle<String> name, VariableMode* mode,
741658
InitializationFlag* init_flag,
742659
MaybeAssignedFlag* maybe_assigned_flag) {
@@ -850,16 +767,8 @@ int ScopeInfo::ParameterNamesIndex() const {
850767
return kVariablePartIndex;
851768
}
852769

853-
int ScopeInfo::StackLocalFirstSlotIndex() const {
854-
return ParameterNamesIndex() + ParameterCount();
855-
}
856-
857-
int ScopeInfo::StackLocalNamesIndex() const {
858-
return StackLocalFirstSlotIndex() + 1;
859-
}
860-
861770
int ScopeInfo::ContextLocalNamesIndex() const {
862-
return StackLocalNamesIndex() + StackLocalCount();
771+
return ParameterNamesIndex() + ParameterCount();
863772
}
864773

865774
int ScopeInfo::ContextLocalInfosIndex() const {

0 commit comments

Comments
 (0)