Commit 585ad977 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Parsing] Avoid updating parsing stats in CollectSourcePositions.

We have already parsed a function when we call CollectSourcePositions, so we
shouldn't update the parsing statistics again otherwise we will double-count.
Also, CollectSourcePositions needs to be made native-context independent, and
Blink's CountUsage counter requires a context to have been entered when it is
called and so isn't context independent.

BUG=chromium:992063

Change-Id: Idda50b98a8308f022cb90e1a18afb43982e95298
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1746472
Auto-Submit: Ross McIlroy <rmcilroy@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63151}
parent 71acda22
......@@ -1215,8 +1215,10 @@ bool Compiler::CollectSourcePositions(Isolate* isolate,
parse_info.set_collect_source_positions();
if (FLAG_allow_natives_syntax) parse_info.set_allow_natives_syntax();
// Parse and update ParseInfo with the results.
if (!parsing::ParseAny(&parse_info, shared_info, isolate)) {
// Parse and update ParseInfo with the results. Don't update parsing
// statistics since we've already parsed the code before.
if (!parsing::ParseAny(&parse_info, shared_info, isolate,
parsing::UpdateStatisticsMode::kNo)) {
// Parsing failed probably as a result of stack exhaustion.
bytecode->SetSourcePositionsFailedToCollect();
return FailWithPendingException(
......
......@@ -165,9 +165,11 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
friend class i::VariableDeclarationParsingScope<ParserTypes<Parser>>;
friend class i::ParameterDeclarationParsingScope<ParserTypes<Parser>>;
friend class i::ArrowHeadParsingScope<ParserTypes<Parser>>;
friend bool v8::internal::parsing::ParseProgram(ParseInfo*, Isolate*);
friend bool v8::internal::parsing::ParseProgram(
ParseInfo*, Isolate*, parsing::UpdateStatisticsMode stats_mode);
friend bool v8::internal::parsing::ParseFunction(
ParseInfo*, Handle<SharedFunctionInfo> shared_info, Isolate*);
ParseInfo*, Handle<SharedFunctionInfo> shared_info, Isolate*,
parsing::UpdateStatisticsMode stats_mode);
bool AllowsLazyParsingWithoutUnresolvedVariables() const {
return scope()->AllowsLazyParsingWithoutUnresolvedVariables(
......
......@@ -18,7 +18,8 @@ namespace v8 {
namespace internal {
namespace parsing {
bool ParseProgram(ParseInfo* info, Isolate* isolate) {
bool ParseProgram(ParseInfo* info, Isolate* isolate,
UpdateStatisticsMode stats_mode) {
DCHECK(info->is_toplevel());
DCHECK_NULL(info->literal());
......@@ -48,12 +49,14 @@ bool ParseProgram(ParseInfo* info, Isolate* isolate) {
info->set_allow_eval_cache(parser.allow_eval_cache());
}
}
parser.UpdateStatistics(isolate, info->script());
if (stats_mode == UpdateStatisticsMode::kYes) {
parser.UpdateStatistics(isolate, info->script());
}
return (result != nullptr);
}
bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
Isolate* isolate) {
Isolate* isolate, UpdateStatisticsMode stats_mode) {
DCHECK(!info->is_toplevel());
DCHECK(!shared_info.is_null());
DCHECK_NULL(info->literal());
......@@ -85,15 +88,18 @@ bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
info->set_allow_eval_cache(parser.allow_eval_cache());
}
}
parser.UpdateStatistics(isolate, info->script());
if (stats_mode == UpdateStatisticsMode::kYes) {
parser.UpdateStatistics(isolate, info->script());
}
return (result != nullptr);
}
bool ParseAny(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
Isolate* isolate) {
Isolate* isolate, UpdateStatisticsMode stats_mode) {
DCHECK(!shared_info.is_null());
return info->is_toplevel() ? ParseProgram(info, isolate)
: ParseFunction(info, shared_info, isolate);
return info->is_toplevel()
? ParseProgram(info, isolate, stats_mode)
: ParseFunction(info, shared_info, isolate, stats_mode);
}
} // namespace parsing
......
......@@ -15,23 +15,27 @@ class SharedFunctionInfo;
namespace parsing {
enum class UpdateStatisticsMode { kYes, kNo };
// Parses the top-level source code represented by the parse info and sets its
// function literal. Returns false (and deallocates any allocated AST
// nodes) if parsing failed.
V8_EXPORT_PRIVATE bool ParseProgram(ParseInfo* info, Isolate* isolate);
V8_EXPORT_PRIVATE bool ParseProgram(
ParseInfo* info, Isolate* isolate,
UpdateStatisticsMode stats_mode = UpdateStatisticsMode::kYes);
// Like ParseProgram but for an individual function which already has a
// allocated shared function info.
V8_EXPORT_PRIVATE bool ParseFunction(ParseInfo* info,
Handle<SharedFunctionInfo> shared_info,
Isolate* isolate);
V8_EXPORT_PRIVATE bool ParseFunction(
ParseInfo* info, Handle<SharedFunctionInfo> shared_info, Isolate* isolate,
UpdateStatisticsMode stats_mode = UpdateStatisticsMode::kYes);
// If you don't know whether info->is_toplevel() is true or not, use this method
// to dispatch to either of the above functions. Prefer to use the above methods
// whenever possible.
V8_EXPORT_PRIVATE bool ParseAny(ParseInfo* info,
Handle<SharedFunctionInfo> shared_info,
Isolate* isolate);
V8_EXPORT_PRIVATE bool ParseAny(
ParseInfo* info, Handle<SharedFunctionInfo> shared_info, Isolate* isolate,
UpdateStatisticsMode stats_mode = UpdateStatisticsMode::kYes);
} // namespace parsing
} // namespace internal
......
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