Skip to content

Commit 2fe1552

Browse files
szuendCommit Bot
authored andcommitted
Reparse closure instead of script for most uses of ScopeIterator
The ScopeIterator only requires accurate information for the whole script during local debug-evaluate, when the accurate scope information is used to build stack local blacklists. Otherwise it is enough to only reparse the closure. This should recover some performance during stepping, especially with large stacks and scripts. Drive-by: Remove unused COLLECT_NON_LOCALS enum option. Bug: chromium:1028093, v8:9938 Change-Id: I6b3a34e9015e564d683e76b88388daabc426e1cb Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1948715 Commit-Queue: Simon Zünd <[email protected]> Reviewed-by: Yang Guo <[email protected]> Cr-Commit-Position: refs/heads/master@{#65318}
1 parent 70803a8 commit 2fe1552

File tree

5 files changed

+27
-12
lines changed

5 files changed

+27
-12
lines changed

src/debug/debug-evaluate.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ DebugEvaluate::ContextBuilder::ContextBuilder(Isolate* isolate,
171171
: isolate_(isolate),
172172
frame_inspector_(frame, inlined_jsframe_index, isolate),
173173
scope_iterator_(isolate, &frame_inspector_,
174-
ScopeIterator::COLLECT_NON_LOCALS) {
174+
ScopeIterator::ReparseStrategy::kScript) {
175175
Handle<Context> outer_context(frame_inspector_.GetFunction()->context(),
176176
isolate);
177177
evaluation_context_ = outer_context;

src/debug/debug-scope-iterator.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ namespace internal {
5050

5151
DebugScopeIterator::DebugScopeIterator(Isolate* isolate,
5252
FrameInspector* frame_inspector)
53-
: iterator_(isolate, frame_inspector) {
53+
: iterator_(
54+
isolate, frame_inspector,
55+
::v8::internal::ScopeIterator::ReparseStrategy::kFunctionLiteral) {
5456
if (!Done() && ShouldIgnore()) Advance();
5557
}
5658

src/debug/debug-scopes.cc

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace v8 {
2323
namespace internal {
2424

2525
ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector,
26-
ScopeIterator::Option option)
26+
ReparseStrategy strategy)
2727
: isolate_(isolate),
2828
frame_inspector_(frame_inspector),
2929
function_(frame_inspector_->GetFunction()),
@@ -37,7 +37,7 @@ ScopeIterator::ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector,
3737
// We should not instantiate a ScopeIterator for wasm frames.
3838
DCHECK_NE(Script::TYPE_WASM, frame_inspector->GetScript()->type());
3939

40-
TryParseAndRetrieveScopes(option);
40+
TryParseAndRetrieveScopes(strategy);
4141
}
4242

4343
ScopeIterator::~ScopeIterator() { delete info_; }
@@ -72,7 +72,7 @@ ScopeIterator::ScopeIterator(Isolate* isolate,
7272
context_(generator->context(), isolate),
7373
script_(Script::cast(function_->shared().script()), isolate) {
7474
CHECK(function_->shared().IsSubjectToDebugging());
75-
TryParseAndRetrieveScopes(DEFAULT);
75+
TryParseAndRetrieveScopes(ReparseStrategy::kFunctionLiteral);
7676
}
7777

7878
void ScopeIterator::Restart() {
@@ -195,7 +195,7 @@ class ScopeChainRetriever {
195195

196196
} // namespace
197197

198-
void ScopeIterator::TryParseAndRetrieveScopes(ScopeIterator::Option option) {
198+
void ScopeIterator::TryParseAndRetrieveScopes(ReparseStrategy strategy) {
199199
// Catch the case when the debugger stops in an internal function.
200200
Handle<SharedFunctionInfo> shared_info(function_->shared(), isolate_);
201201
Handle<ScopeInfo> scope_info(shared_info->scope_info(), isolate_);
@@ -233,9 +233,17 @@ void ScopeIterator::TryParseAndRetrieveScopes(ScopeIterator::Option option) {
233233
}
234234

235235
// Reparse the code and analyze the scopes.
236+
// Depending on the choosen strategy, the whole script or just
237+
// the closure is re-parsed for function scopes.
236238
Handle<Script> script(Script::cast(shared_info->script()), isolate_);
237-
info_ = new ParseInfo(isolate_, script);
238-
info_->set_eager();
239+
if (scope_info->scope_type() == FUNCTION_SCOPE &&
240+
strategy == ReparseStrategy::kFunctionLiteral) {
241+
info_ = new ParseInfo(isolate_, shared_info);
242+
} else {
243+
info_ = new ParseInfo(isolate_, script);
244+
info_->set_eager();
245+
}
246+
239247
if (scope_info->scope_type() == EVAL_SCOPE || script->is_wrapped()) {
240248
info_->set_eval();
241249
if (!context_->IsNativeContext()) {

src/debug/debug-scopes.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,13 @@ class ScopeIterator {
4141
static const int kScopeDetailsFunctionIndex = 5;
4242
static const int kScopeDetailsSize = 6;
4343

44-
enum Option { DEFAULT, COLLECT_NON_LOCALS };
44+
enum class ReparseStrategy {
45+
kScript,
46+
kFunctionLiteral,
47+
};
4548

4649
ScopeIterator(Isolate* isolate, FrameInspector* frame_inspector,
47-
Option options = DEFAULT);
50+
ReparseStrategy strategy);
4851

4952
ScopeIterator(Isolate* isolate, Handle<JSFunction> function);
5053
ScopeIterator(Isolate* isolate, Handle<JSGeneratorObject> generator);
@@ -129,7 +132,7 @@ class ScopeIterator {
129132

130133
int GetSourcePosition();
131134

132-
void TryParseAndRetrieveScopes(ScopeIterator::Option option);
135+
void TryParseAndRetrieveScopes(ReparseStrategy strategy);
133136

134137
void UnwrapEvaluationContext();
135138

src/debug/debug-stack-trace-iterator.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,9 @@ v8::MaybeLocal<v8::Value> DebugStackTraceIterator::GetReceiver() const {
8787
// Arrow function defined in top level function without references to
8888
// variables may have NativeContext as context.
8989
if (!context->IsFunctionContext()) return v8::MaybeLocal<v8::Value>();
90-
ScopeIterator scope_iterator(isolate_, frame_inspector_.get());
90+
ScopeIterator scope_iterator(
91+
isolate_, frame_inspector_.get(),
92+
ScopeIterator::ReparseStrategy::kFunctionLiteral);
9193
// We lookup this variable in function context only when it is used in arrow
9294
// function otherwise V8 can optimize it out.
9395
if (!scope_iterator.ClosureScopeHasThisReference()) {

0 commit comments

Comments
 (0)