Commit 3bec8e23 authored by Leszek Swirski's avatar Leszek Swirski Committed by V8 LUCI CQ

[compiler-dispatcher] Focus API around SFIs, not literals

Remove FunctionLiterals and ParseInfo from the LazyCompileDispatcher
API, passing instead the SharedFunctionInfo, a character stream, and
optionally some preparse data.

In the future, this should allow us to pass arbitrary uncompiled
SharedFunctionInfos into the LazyCompileDispatcher.

Change-Id: Iff90408f3b259c7f5df0e74687d052e75959fa48
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3262131Reviewed-by: 's avatarVictor Gomes <victorgomes@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77723}
parent f67dd50a
......@@ -1404,32 +1404,27 @@ BackgroundCompileTask::BackgroundCompileTask(ScriptStreamingData* streamed_data,
}
BackgroundCompileTask::BackgroundCompileTask(
Isolate* isolate, const ParseInfo* outer_parse_info,
Handle<SharedFunctionInfo> shared_info,
const FunctionLiteral* function_literal,
Isolate* isolate, Handle<SharedFunctionInfo> shared_info,
std::unique_ptr<Utf16CharacterStream> character_stream,
ProducedPreparseData* preparse_data,
WorkerThreadRuntimeCallStats* worker_thread_runtime_stats,
TimedHistogram* timer, int max_stack_size)
: isolate_for_local_isolate_(isolate),
flags_(UnoptimizedCompileFlags::ForToplevelFunction(
outer_parse_info->flags(), function_literal)),
compile_state_(*outer_parse_info->state()),
flags_(
UnoptimizedCompileFlags::ForFunctionCompile(isolate, *shared_info)),
compile_state_(isolate),
info_(std::make_unique<ParseInfo>(isolate, flags_, &compile_state_)),
stack_size_(max_stack_size),
worker_thread_runtime_call_stats_(worker_thread_runtime_stats),
timer_(timer),
input_shared_info_(shared_info),
start_position_(function_literal->start_position()),
end_position_(function_literal->end_position()),
function_literal_id_(function_literal->function_literal_id()),
start_position_(shared_info->StartPosition()),
end_position_(shared_info->EndPosition()),
function_literal_id_(shared_info->function_literal_id()),
language_mode_(info_->language_mode()) {
DCHECK_EQ(outer_parse_info->parameters_end_pos(), kNoSourcePosition);
DCHECK_NULL(outer_parse_info->extension());
DCHECK(!function_literal->is_toplevel());
DCHECK(!shared_info->is_toplevel());
// Clone the character stream so both can be accessed independently.
std::unique_ptr<Utf16CharacterStream> character_stream =
outer_parse_info->character_stream()->Clone();
character_stream->Seek(start_position_);
info_->set_character_stream(std::move(character_stream));
......@@ -1439,9 +1434,8 @@ BackgroundCompileTask::BackgroundCompileTask(
input_shared_info_ = persistent_handles_->NewHandle(shared_info);
// Get preparsed scope data from the function literal.
if (function_literal->produced_preparse_data()) {
ZonePreparseData* serialized_data =
function_literal->produced_preparse_data()->Serialize(info_->zone());
if (preparse_data) {
ZonePreparseData* serialized_data = preparse_data->Serialize(info_->zone());
info_->set_consumed_preparse_data(
ConsumedPreparseData::For(info_->zone(), serialized_data));
}
......
......@@ -505,12 +505,12 @@ class V8_EXPORT_PRIVATE BackgroundCompileTask {
~BackgroundCompileTask();
// Creates a new task that when run will parse and compile the top-level
// |function_literal| and can be finalized with FinalizeFunction
// |shared_info| and can be finalized with FinalizeFunction in
// Compiler::FinalizeBackgroundCompileTask.
BackgroundCompileTask(
Isolate* isolate, const ParseInfo* outer_parse_info,
Handle<SharedFunctionInfo> shared_info,
const FunctionLiteral* function_literal,
Isolate* isolate, Handle<SharedFunctionInfo> shared_info,
std::unique_ptr<Utf16CharacterStream> character_stream,
ProducedPreparseData* preparse_data,
WorkerThreadRuntimeCallStats* worker_thread_runtime_stats,
TimedHistogram* timer, int max_stack_size);
......
......@@ -77,16 +77,17 @@ LazyCompileDispatcher::~LazyCompileDispatcher() {
CHECK(!job_handle_->IsValid());
}
void LazyCompileDispatcher::Enqueue(const ParseInfo* outer_parse_info,
Handle<SharedFunctionInfo> shared_info,
const FunctionLiteral* function_literal) {
void LazyCompileDispatcher::Enqueue(
Handle<SharedFunctionInfo> shared_info,
std::unique_ptr<Utf16CharacterStream> character_stream,
ProducedPreparseData* preparse_data) {
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
"V8.LazyCompilerDispatcherEnqueue");
RCS_SCOPE(isolate_, RuntimeCallCounterId::kCompileEnqueueOnDispatcher);
std::unique_ptr<Job> job =
std::make_unique<Job>(std::make_unique<BackgroundCompileTask>(
isolate_, outer_parse_info, shared_info, function_literal,
isolate_, shared_info, std::move(character_stream), preparse_data,
worker_thread_runtime_call_stats_, background_compile_timer_,
static_cast<int>(max_stack_size_)));
......@@ -95,10 +96,7 @@ void LazyCompileDispatcher::Enqueue(const ParseInfo* outer_parse_info,
{
base::MutexGuard lock(&mutex_);
if (trace_compiler_dispatcher_) {
PrintF(
"LazyCompileDispatcher: enqueued job for function literal id %d "
"and ",
function_literal->function_literal_id());
PrintF("LazyCompileDispatcher: enqueued job for ");
shared_info->ShortPrint();
PrintF("\n");
}
......
......@@ -37,8 +37,10 @@ class UnoptimizedCompileJob;
class FunctionLiteral;
class Isolate;
class ParseInfo;
class ProducedPreparseData;
class SharedFunctionInfo;
class TimedHistogram;
class Utf16CharacterStream;
class WorkerThreadRuntimeCallStats;
class Zone;
......@@ -81,9 +83,9 @@ class V8_EXPORT_PRIVATE LazyCompileDispatcher {
LazyCompileDispatcher& operator=(const LazyCompileDispatcher&) = delete;
~LazyCompileDispatcher();
void Enqueue(const ParseInfo* outer_parse_info,
Handle<SharedFunctionInfo> shared_info,
const FunctionLiteral* function_literal);
void Enqueue(Handle<SharedFunctionInfo> shared_info,
std::unique_ptr<Utf16CharacterStream> character_stream,
ProducedPreparseData* preparse_data);
// Returns true if there is a pending job registered for the given function.
bool IsEnqueued(Handle<SharedFunctionInfo> function) const;
......
......@@ -2174,6 +2174,7 @@ DEFINE_NEG_IMPLICATION(predictable, memory_reducer)
DEFINE_IMPLICATION(predictable, single_threaded_gc)
DEFINE_NEG_IMPLICATION(predictable, concurrent_recompilation)
DEFINE_NEG_IMPLICATION(predictable, lazy_compile_dispatcher)
DEFINE_NEG_IMPLICATION(predictable, parallel_compile_tasks)
DEFINE_NEG_IMPLICATION(predictable, stress_concurrent_inlining)
DEFINE_BOOL(predictable_gc_schedule, false,
......@@ -2192,6 +2193,7 @@ DEFINE_BOOL(single_threaded, false, "disable the use of background tasks")
DEFINE_IMPLICATION(single_threaded, single_threaded_gc)
DEFINE_NEG_IMPLICATION(single_threaded, concurrent_recompilation)
DEFINE_NEG_IMPLICATION(single_threaded, lazy_compile_dispatcher)
DEFINE_NEG_IMPLICATION(single_threaded, parallel_compile_tasks)
DEFINE_NEG_IMPLICATION(single_threaded, stress_concurrent_inlining)
//
......
......@@ -2701,7 +2701,9 @@ FunctionLiteral* Parser::ParseFunctionLiteral(
Handle<SharedFunctionInfo> shared_info =
local_isolate_->factory()->NewSharedFunctionInfoForLiteral(
function_literal, script_, false);
info()->dispatcher()->Enqueue(info(), shared_info, function_literal);
info()->dispatcher()->Enqueue(shared_info,
info()->character_stream()->Clone(),
function_literal->produced_preparse_data());
}
if (should_infer_name) {
......
......@@ -77,32 +77,8 @@ class LazyCompileDispatcherTest : public TestWithNativeContext {
UnoptimizedCompileState state(isolate);
std::unique_ptr<ParseInfo> outer_parse_info =
test::OuterParseInfoForShared(isolate, shared, &state);
AstValueFactory* ast_value_factory =
outer_parse_info->GetOrCreateAstValueFactory();
AstNodeFactory ast_node_factory(ast_value_factory,
outer_parse_info->zone());
const AstRawString* function_name =
ast_value_factory->GetOneByteString("f");
DeclarationScope* script_scope =
outer_parse_info->zone()->New<DeclarationScope>(
outer_parse_info->zone(), ast_value_factory);
DeclarationScope* function_scope =
outer_parse_info->zone()->New<DeclarationScope>(
outer_parse_info->zone(), script_scope, FUNCTION_SCOPE);
function_scope->set_start_position(shared->StartPosition());
function_scope->set_end_position(shared->EndPosition());
std::vector<void*> pointer_buffer;
ScopedPtrList<Statement> statements(&pointer_buffer);
const FunctionLiteral* function_literal =
ast_node_factory.NewFunctionLiteral(
function_name, function_scope, statements, -1, -1, -1,
FunctionLiteral::kNoDuplicateParameters,
FunctionSyntaxKind::kAnonymousExpression,
FunctionLiteral::kShouldEagerCompile, shared->StartPosition(), true,
shared->function_literal_id(), nullptr);
dispatcher->Enqueue(outer_parse_info.get(), shared, function_literal);
dispatcher->Enqueue(shared, outer_parse_info->character_stream()->Clone(),
nullptr);
}
};
......
......@@ -80,7 +80,8 @@ class BackgroundCompileTaskTest : public TestWithNativeContext {
shared->function_literal_id(), nullptr);
return new BackgroundCompileTask(
isolate, outer_parse_info.get(), shared, function_literal,
isolate, shared, outer_parse_info->character_stream()->Clone(),
function_literal->produced_preparse_data(),
isolate->counters()->worker_thread_runtime_call_stats(),
isolate->counters()->compile_function_on_background(), FLAG_stack_size);
}
......
......@@ -111,6 +111,7 @@ INCOMPATIBLE_FLAGS_PER_BUILD_VARIABLE = {
# implications defined in flag-definitions.h.
INCOMPATIBLE_FLAGS_PER_EXTRA_FLAG = {
"--concurrent-recompilation": ["--predictable", "--assert-types"],
"--parallel-compile-tasks": ["--predictable"],
"--gc-interval=*": ["--gc-interval=*"],
"--optimize-for-size": ["--max-semi-space-size=*"],
"--stress_concurrent_allocation":
......
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