Skip to content

Commit 39496a9

Browse files
verwaestCommit Bot
authored andcommitted
Replace Context::closure with Context::scope_info, allowing closure to die.
There are likely cleanups that can be done after this CL: - context-related functions in the interpreter and compiler take ScopeInfo as well as ScopeType and slot-count as input. The latter 2 should be directly derived from the former. We should be able to drop FunctionContextParameters. - ContextExtension is probably not needed anymore, since we now always have the correct scope_info directly in the SCOPE_INFO_INDEX slot. Bug: v8:7066 Cq-Include-Trybots: luci.chromium.try:linux_chromium_rel_ng;master.tryserver.blink:linux_trusty_blink_rel Change-Id: Ie1f6134c686a9f2183e54730d9cdd598a9e5ab67 Reviewed-on: https://chromium-review.googlesource.com/785151 Commit-Queue: Toon Verwaest <[email protected]> Reviewed-by: Hannes Payer <[email protected]> Reviewed-by: Adam Klein <[email protected]> Reviewed-by: Ross McIlroy <[email protected]> Reviewed-by: Michael Starzinger <[email protected]> Cr-Commit-Position: refs/heads/master@{#52952}
1 parent 7ed2e31 commit 39496a9

79 files changed

Lines changed: 789 additions & 876 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/api.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2533,8 +2533,10 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
25332533
options == CompileOptions::kNoCompileOptions);
25342534

25352535
i::Handle<i::Context> context = Utils::OpenHandle(*v8_context);
2536-
i::Handle<i::SharedFunctionInfo> outer_info(context->closure()->shared(),
2537-
isolate);
2536+
2537+
DCHECK(context->IsNativeContext());
2538+
i::Handle<i::SharedFunctionInfo> outer_info(
2539+
context->empty_function()->shared(), isolate);
25382540

25392541
i::Handle<i::JSFunction> fun;
25402542
i::Handle<i::FixedArray> arguments_list =
@@ -2550,9 +2552,8 @@ MaybeLocal<Function> ScriptCompiler::CompileFunctionInContext(
25502552
i::Handle<i::JSReceiver> extension =
25512553
Utils::OpenHandle(*context_extensions[i]);
25522554
if (!extension->IsJSObject()) return Local<Function>();
2553-
i::Handle<i::JSFunction> closure(context->closure(), isolate);
25542555
context = isolate->factory()->NewWithContext(
2555-
closure, context,
2556+
context,
25562557
i::ScopeInfo::CreateForWithScope(
25572558
isolate, context->IsNativeContext()
25582559
? i::Handle<i::ScopeInfo>::null()

src/arm/interface-descriptors-arm.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void RecordWriteDescriptor::InitializePlatformSpecific(
3434
data->InitializePlatformSpecific(kParameterCount, default_stub_registers);
3535
}
3636

37-
const Register FastNewFunctionContextDescriptor::FunctionRegister() {
37+
const Register FastNewFunctionContextDescriptor::ScopeInfoRegister() {
3838
return r1;
3939
}
4040
const Register FastNewFunctionContextDescriptor::SlotsRegister() { return r0; }

src/arm64/interface-descriptors-arm64.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void RecordWriteDescriptor::InitializePlatformSpecific(
3434
data->InitializePlatformSpecific(kParameterCount, default_stub_registers);
3535
}
3636

37-
const Register FastNewFunctionContextDescriptor::FunctionRegister() {
37+
const Register FastNewFunctionContextDescriptor::ScopeInfoRegister() {
3838
return x1;
3939
}
4040
const Register FastNewFunctionContextDescriptor::SlotsRegister() { return x0; }

src/bootstrapper.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1172,8 +1172,8 @@ void Genesis::InstallGlobalThisBinding() {
11721172
Handle<ScriptContextTable> script_contexts(
11731173
native_context()->script_context_table());
11741174
Handle<ScopeInfo> scope_info = ScopeInfo::CreateGlobalThisBinding(isolate());
1175-
Handle<JSFunction> closure(native_context()->closure());
1176-
Handle<Context> context = factory()->NewScriptContext(closure, scope_info);
1175+
Handle<Context> context =
1176+
factory()->NewScriptContext(native_context(), scope_info);
11771177

11781178
// Go ahead and hook it up while we're at it.
11791179
int slot = scope_info->ReceiverContextSlotIndex();
@@ -1406,8 +1406,8 @@ void Genesis::InitializeGlobal(Handle<JSGlobalObject> global_object,
14061406
Handle<JSFunction> empty_function,
14071407
GlobalContextType context_type) {
14081408
// --- N a t i v e C o n t e x t ---
1409-
// Use the empty function as closure (no scope info).
1410-
native_context()->set_closure(*empty_function);
1409+
// Use the empty scope info.
1410+
native_context()->set_scope_info(empty_function->shared()->scope_info());
14111411
native_context()->set_previous(nullptr);
14121412
// Set extension and global object.
14131413
native_context()->set_extension(*global_object);

src/builtins/builtins-constructor-gen.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ Node* ConstructorBuiltinsAssembler::EmitFastNewObject(Node* context,
233233
}
234234

235235
Node* ConstructorBuiltinsAssembler::EmitFastNewFunctionContext(
236-
Node* function, Node* slots, Node* context, ScopeType scope_type) {
236+
Node* scope_info, Node* slots, Node* context, ScopeType scope_type) {
237237
slots = ChangeUint32ToWord(slots);
238238

239239
// TODO(ishell): Use CSA::OptimalParameterMode() here.
@@ -261,8 +261,8 @@ Node* ConstructorBuiltinsAssembler::EmitFastNewFunctionContext(
261261
SmiTag(length));
262262

263263
// Set up the fixed slots.
264-
StoreFixedArrayElement(function_context, Context::CLOSURE_INDEX, function,
265-
SKIP_WRITE_BARRIER);
264+
StoreFixedArrayElement(function_context, Context::SCOPE_INFO_INDEX,
265+
scope_info, SKIP_WRITE_BARRIER);
266266
StoreFixedArrayElement(function_context, Context::PREVIOUS_INDEX, context,
267267
SKIP_WRITE_BARRIER);
268268
StoreFixedArrayElement(function_context, Context::EXTENSION_INDEX,
@@ -287,18 +287,18 @@ Node* ConstructorBuiltinsAssembler::EmitFastNewFunctionContext(
287287
}
288288

289289
TF_BUILTIN(FastNewFunctionContextEval, ConstructorBuiltinsAssembler) {
290-
Node* function = Parameter(FastNewFunctionContextDescriptor::kFunction);
290+
Node* scope_info = Parameter(FastNewFunctionContextDescriptor::kScopeInfo);
291291
Node* slots = Parameter(FastNewFunctionContextDescriptor::kSlots);
292292
Node* context = Parameter(FastNewFunctionContextDescriptor::kContext);
293-
Return(EmitFastNewFunctionContext(function, slots, context,
293+
Return(EmitFastNewFunctionContext(scope_info, slots, context,
294294
ScopeType::EVAL_SCOPE));
295295
}
296296

297297
TF_BUILTIN(FastNewFunctionContextFunction, ConstructorBuiltinsAssembler) {
298-
Node* function = Parameter(FastNewFunctionContextDescriptor::kFunction);
298+
Node* scope_info = Parameter(FastNewFunctionContextDescriptor::kScopeInfo);
299299
Node* slots = Parameter(FastNewFunctionContextDescriptor::kSlots);
300300
Node* context = Parameter(FastNewFunctionContextDescriptor::kContext);
301-
Return(EmitFastNewFunctionContext(function, slots, context,
301+
Return(EmitFastNewFunctionContext(scope_info, slots, context,
302302
ScopeType::FUNCTION_SCOPE));
303303
}
304304

src/code-stub-assembler.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11630,9 +11630,10 @@ void CodeStubAssembler::InitializeFunctionContext(Node* native_context,
1163011630
StoreObjectFieldNoWriteBarrier(context, FixedArray::kLengthOffset,
1163111631
SmiConstant(slots));
1163211632

11633-
Node* const empty_fn =
11634-
LoadContextElement(native_context, Context::CLOSURE_INDEX);
11635-
StoreContextElementNoWriteBarrier(context, Context::CLOSURE_INDEX, empty_fn);
11633+
Node* const empty_scope_info =
11634+
LoadContextElement(native_context, Context::SCOPE_INFO_INDEX);
11635+
StoreContextElementNoWriteBarrier(context, Context::SCOPE_INFO_INDEX,
11636+
empty_scope_info);
1163611637
StoreContextElementNoWriteBarrier(context, Context::PREVIOUS_INDEX,
1163711638
UndefinedConstant());
1163811639
StoreContextElementNoWriteBarrier(context, Context::EXTENSION_INDEX,

src/compilation-cache.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ bool CompilationCacheScript::HasOrigin(Handle<SharedFunctionInfo> function_info,
126126
MaybeHandle<SharedFunctionInfo> CompilationCacheScript::Lookup(
127127
Handle<String> source, MaybeHandle<Object> name, int line_offset,
128128
int column_offset, ScriptOriginOptions resource_options,
129-
Handle<Context> context, LanguageMode language_mode) {
129+
Handle<Context> native_context, LanguageMode language_mode) {
130130
MaybeHandle<SharedFunctionInfo> result;
131131

132132
// Probe the script generation tables. Make sure not to leak handles
@@ -136,7 +136,7 @@ MaybeHandle<SharedFunctionInfo> CompilationCacheScript::Lookup(
136136
DCHECK_EQ(generations(), 1);
137137
Handle<CompilationCacheTable> table = GetTable(generation);
138138
MaybeHandle<SharedFunctionInfo> probe =
139-
table->LookupScript(source, context, language_mode);
139+
table->LookupScript(source, native_context, language_mode);
140140
Handle<SharedFunctionInfo> function_info;
141141
if (probe.ToHandle(&function_info)) {
142142
// Break when we've found a suitable shared function info that
@@ -166,12 +166,13 @@ MaybeHandle<SharedFunctionInfo> CompilationCacheScript::Lookup(
166166
return result;
167167
}
168168

169-
void CompilationCacheScript::Put(Handle<String> source, Handle<Context> context,
169+
void CompilationCacheScript::Put(Handle<String> source,
170+
Handle<Context> native_context,
170171
LanguageMode language_mode,
171172
Handle<SharedFunctionInfo> function_info) {
172173
HandleScope scope(isolate());
173174
Handle<CompilationCacheTable> table = GetFirstTable();
174-
SetFirstTable(CompilationCacheTable::PutScript(table, source, context,
175+
SetFirstTable(CompilationCacheTable::PutScript(table, source, native_context,
175176
language_mode, function_info));
176177
}
177178

@@ -258,11 +259,11 @@ void CompilationCache::Remove(Handle<SharedFunctionInfo> function_info) {
258259
MaybeHandle<SharedFunctionInfo> CompilationCache::LookupScript(
259260
Handle<String> source, MaybeHandle<Object> name, int line_offset,
260261
int column_offset, ScriptOriginOptions resource_options,
261-
Handle<Context> context, LanguageMode language_mode) {
262+
Handle<Context> native_context, LanguageMode language_mode) {
262263
if (!IsEnabled()) return MaybeHandle<SharedFunctionInfo>();
263264

264265
return script_.Lookup(source, name, line_offset, column_offset,
265-
resource_options, context, language_mode);
266+
resource_options, native_context, language_mode);
266267
}
267268

268269
InfoCellPair CompilationCache::LookupEval(Handle<String> source,
@@ -293,12 +294,13 @@ MaybeHandle<FixedArray> CompilationCache::LookupRegExp(Handle<String> source,
293294
return reg_exp_.Lookup(source, flags);
294295
}
295296

296-
void CompilationCache::PutScript(Handle<String> source, Handle<Context> context,
297+
void CompilationCache::PutScript(Handle<String> source,
298+
Handle<Context> native_context,
297299
LanguageMode language_mode,
298300
Handle<SharedFunctionInfo> function_info) {
299301
if (!IsEnabled()) return;
300302

301-
script_.Put(source, context, language_mode, function_info);
303+
script_.Put(source, native_context, language_mode, function_info);
302304
}
303305

304306
void CompilationCache::PutEval(Handle<String> source,

src/compilation-cache.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ class CompilationCacheScript : public CompilationSubCache {
8383
MaybeHandle<Object> name,
8484
int line_offset, int column_offset,
8585
ScriptOriginOptions resource_options,
86-
Handle<Context> context,
86+
Handle<Context> native_context,
8787
LanguageMode language_mode);
8888

8989
void Put(Handle<String> source, Handle<Context> context,
@@ -158,7 +158,7 @@ class CompilationCache {
158158
MaybeHandle<SharedFunctionInfo> LookupScript(
159159
Handle<String> source, MaybeHandle<Object> name, int line_offset,
160160
int column_offset, ScriptOriginOptions resource_options,
161-
Handle<Context> context, LanguageMode language_mode);
161+
Handle<Context> native_context, LanguageMode language_mode);
162162

163163
// Finds the shared function info for a source string for eval in a
164164
// given context. Returns an empty handle if the cache doesn't
@@ -175,7 +175,7 @@ class CompilationCache {
175175

176176
// Associate the (source, kind) pair to the shared function
177177
// info. This may overwrite an existing mapping.
178-
void PutScript(Handle<String> source, Handle<Context> context,
178+
void PutScript(Handle<String> source, Handle<Context> native_context,
179179
LanguageMode language_mode,
180180
Handle<SharedFunctionInfo> function_info);
181181

src/compiler.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1397,7 +1397,8 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromString(
13971397
// Compile source string in the native context.
13981398
int eval_scope_position = 0;
13991399
int eval_position = kNoSourcePosition;
1400-
Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared());
1400+
Handle<SharedFunctionInfo> outer_info(
1401+
native_context->empty_function()->shared());
14011402
return Compiler::GetFunctionFromEval(
14021403
source, outer_info, native_context, LanguageMode::kSloppy, restriction,
14031404
parameters_end_pos, eval_scope_position, eval_position);

src/compiler/bytecode-graph-builder.cc

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1483,22 +1483,27 @@ void BytecodeGraphBuilder::VisitCreateBlockContext() {
14831483
bytecode_iterator().GetConstantForIndexOperand(0));
14841484

14851485
const Operator* op = javascript()->CreateBlockContext(scope_info);
1486-
Node* context = NewNode(op, environment()->LookupAccumulator());
1486+
Node* context = NewNode(op);
14871487
environment()->BindAccumulator(context);
14881488
}
14891489

14901490
void BytecodeGraphBuilder::VisitCreateFunctionContext() {
1491-
uint32_t slots = bytecode_iterator().GetUnsignedImmediateOperand(0);
1491+
Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::cast(
1492+
bytecode_iterator().GetConstantForIndexOperand(0));
1493+
uint32_t slots = bytecode_iterator().GetUnsignedImmediateOperand(1);
14921494
const Operator* op =
1493-
javascript()->CreateFunctionContext(slots, FUNCTION_SCOPE);
1494-
Node* context = NewNode(op, GetFunctionClosure());
1495+
javascript()->CreateFunctionContext(scope_info, slots, FUNCTION_SCOPE);
1496+
Node* context = NewNode(op);
14951497
environment()->BindAccumulator(context);
14961498
}
14971499

14981500
void BytecodeGraphBuilder::VisitCreateEvalContext() {
1499-
uint32_t slots = bytecode_iterator().GetUnsignedImmediateOperand(0);
1500-
const Operator* op = javascript()->CreateFunctionContext(slots, EVAL_SCOPE);
1501-
Node* context = NewNode(op, GetFunctionClosure());
1501+
Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::cast(
1502+
bytecode_iterator().GetConstantForIndexOperand(0));
1503+
uint32_t slots = bytecode_iterator().GetUnsignedImmediateOperand(1);
1504+
const Operator* op =
1505+
javascript()->CreateFunctionContext(scope_info, slots, EVAL_SCOPE);
1506+
Node* context = NewNode(op);
15021507
environment()->BindAccumulator(context);
15031508
}
15041509

@@ -1509,10 +1514,9 @@ void BytecodeGraphBuilder::VisitCreateCatchContext() {
15091514
Handle<String>::cast(bytecode_iterator().GetConstantForIndexOperand(1));
15101515
Handle<ScopeInfo> scope_info = Handle<ScopeInfo>::cast(
15111516
bytecode_iterator().GetConstantForIndexOperand(2));
1512-
Node* closure = environment()->LookupAccumulator();
15131517

15141518
const Operator* op = javascript()->CreateCatchContext(name, scope_info);
1515-
Node* context = NewNode(op, exception, closure);
1519+
Node* context = NewNode(op, exception);
15161520
environment()->BindAccumulator(context);
15171521
}
15181522

@@ -1523,7 +1527,7 @@ void BytecodeGraphBuilder::VisitCreateWithContext() {
15231527
bytecode_iterator().GetConstantForIndexOperand(1));
15241528

15251529
const Operator* op = javascript()->CreateWithContext(scope_info);
1526-
Node* context = NewNode(op, object, environment()->LookupAccumulator());
1530+
Node* context = NewNode(op, object);
15271531
environment()->BindAccumulator(context);
15281532
}
15291533

0 commit comments

Comments
 (0)