Commit b4712802 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[parser] Set script id on ParseInfo creation

Rather than having an optional script id during ParseInfo creation (which
is either selected lazily on script creation, or eagerly if based on an
existing Script), always eagerly get either the desired script id (either
from the Script or Isolate::GetNextScriptId()).

This has the side-effect that we will currently no longer need to get the
script id on background threads, but I'm not reverting the thread-safety
of Isolate::GetNextScriptId in case it's needed again in the future.

Bug: v8:10314
Change-Id: I8f2dd962d3652b1a84a5d704a099e57a1679aba5
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2096616
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66649}
parent e68b5941
......@@ -20,7 +20,7 @@
namespace v8 {
namespace internal {
ParseInfo::ParseInfo(AccountingAllocator* zone_allocator)
ParseInfo::ParseInfo(AccountingAllocator* zone_allocator, int script_id)
: zone_(std::make_unique<Zone>(zone_allocator, ZONE_NAME)),
flags_(0),
extension_(nullptr),
......@@ -29,7 +29,7 @@ ParseInfo::ParseInfo(AccountingAllocator* zone_allocator)
hash_seed_(0),
function_kind_(FunctionKind::kNormalFunction),
function_syntax_kind_(FunctionSyntaxKind::kDeclaration),
script_id_(-1),
script_id_(script_id),
start_position_(0),
end_position_(0),
parameters_end_pos_(kNoSourcePosition),
......@@ -43,8 +43,9 @@ ParseInfo::ParseInfo(AccountingAllocator* zone_allocator)
source_range_map_(nullptr),
literal_(nullptr) {}
ParseInfo::ParseInfo(Isolate* isolate, AccountingAllocator* zone_allocator)
: ParseInfo(zone_allocator) {
ParseInfo::ParseInfo(Isolate* isolate, AccountingAllocator* zone_allocator,
int script_id)
: ParseInfo(zone_allocator, script_id) {
set_hash_seed(HashSeed(isolate));
set_stack_limit(isolate->stack_guard()->real_climit());
set_runtime_call_stats(isolate->counters()->runtime_call_stats());
......@@ -70,9 +71,8 @@ ParseInfo::ParseInfo(Isolate* isolate, AccountingAllocator* zone_allocator)
}
ParseInfo::ParseInfo(Isolate* isolate)
: ParseInfo(isolate, isolate->allocator()) {
script_id_ = isolate->GetNextScriptId();
LOG(isolate, ScriptEvent(Logger::ScriptEventType::kReserveId, script_id_));
: ParseInfo(isolate, isolate->allocator(), isolate->GetNextScriptId()) {
LOG(isolate, ScriptEvent(Logger::ScriptEventType::kReserveId, script_id()));
}
template <typename T>
......@@ -90,7 +90,8 @@ void ParseInfo::SetFunctionInfo(T function) {
}
ParseInfo::ParseInfo(Isolate* isolate, SharedFunctionInfo shared)
: ParseInfo(isolate, isolate->allocator()) {
: ParseInfo(isolate, isolate->allocator(),
Script::cast(shared.script()).id()) {
// Do not support re-parsing top-level function of a wrapped script.
// TODO(yangguo): consider whether we need a top-level function in a
// wrapped script at all.
......@@ -128,7 +129,7 @@ ParseInfo::ParseInfo(Isolate* isolate, SharedFunctionInfo shared)
}
ParseInfo::ParseInfo(Isolate* isolate, Script script)
: ParseInfo(isolate, isolate->allocator()) {
: ParseInfo(isolate, isolate->allocator(), script.id()) {
SetFlagsForToplevelCompileFromScript(isolate, script,
isolate->is_collecting_type_profile());
}
......@@ -137,12 +138,12 @@ ParseInfo::ParseInfo(Isolate* isolate, Script script)
std::unique_ptr<ParseInfo> ParseInfo::FromParent(
const ParseInfo* outer_parse_info, AccountingAllocator* zone_allocator,
const FunctionLiteral* literal, const AstRawString* function_name) {
std::unique_ptr<ParseInfo> result =
std::make_unique<ParseInfo>(zone_allocator);
// Can't use make_unique because the constructor is private.
std::unique_ptr<ParseInfo> result(
new ParseInfo(zone_allocator, outer_parse_info->script_id_));
// Replicate shared state of the outer_parse_info.
result->flags_ = outer_parse_info->flags_;
result->script_id_ = outer_parse_info->script_id_;
result->set_logger(outer_parse_info->logger());
result->set_ast_string_constants(outer_parse_info->ast_string_constants());
result->set_hash_seed(outer_parse_info->hash_seed());
......@@ -178,12 +179,9 @@ Handle<Script> ParseInfo::CreateScript(LocalIsolate* isolate,
ScriptOriginOptions origin_options,
NativesFlag natives) {
// Create a script object describing the script to be compiled.
Handle<Script> script;
if (script_id_ == -1) {
script = isolate->factory()->NewScript(source);
} else {
script = isolate->factory()->NewScriptWithId(source, script_id_);
}
DCHECK_GE(script_id_, 0);
Handle<Script> script =
isolate->factory()->NewScriptWithId(source, script_id_);
if (isolate->NeedsSourcePositionsForProfiling()) {
Script::InitLineEnds(isolate, script);
}
......@@ -289,8 +287,7 @@ void ParseInfo::CheckFlagsForToplevelCompileFromScript(
}
void ParseInfo::SetFlagsForFunctionFromScript(Script script) {
DCHECK(script_id_ == -1 || script_id_ == script.id());
script_id_ = script.id();
DCHECK_EQ(script_id_, script.id());
set_eval(script.compilation_type() == Script::COMPILATION_TYPE_EVAL);
set_module(script.origin_options().IsModule());
......
......@@ -41,9 +41,7 @@ class Zone;
// A container for the inputs, configuration options, and outputs of parsing.
class V8_EXPORT_PRIVATE ParseInfo {
public:
explicit ParseInfo(AccountingAllocator* zone_allocator);
explicit ParseInfo(Isolate*);
ParseInfo(Isolate*, AccountingAllocator* zone_allocator);
ParseInfo(Isolate* isolate, Script script);
ParseInfo(Isolate* isolate, SharedFunctionInfo shared);
......@@ -297,6 +295,9 @@ class V8_EXPORT_PRIVATE ParseInfo {
}
private:
ParseInfo(AccountingAllocator* zone_allocator, int script_id);
ParseInfo(Isolate*, AccountingAllocator* zone_allocator, int script_id);
void SetFlagsForFunctionFromScript(Script script);
template <typename LocalIsolate>
......
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