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

[compiler-dispatcher] Pass isolate to main thread step

Rather than storing the isolate in compiler dispatcher jobs, which gets
weird for jobs that are entirely off-thread, instead pass the isolate
in when stepping on the main thread.

This makes it clearer which steps must be executed on the main thread,
as they require the caller to explicitly give them access to the
isolate.

Bug: v8:6537
Change-Id: I02fff7c77fdcdbfb099a38235f94d8c1040699ac
Reviewed-on: https://chromium-review.googlesource.com/589437
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarRoss McIlroy <rmcilroy@chromium.org>
Cr-Commit-Position: refs/heads/master@{#46962}
parent 1c02987d
......@@ -36,13 +36,13 @@ class V8_EXPORT_PRIVATE CompilerDispatcherJob {
virtual bool CanStepNextOnAnyThread() = 0;
// Step the job forward by one state on the main thread.
virtual void StepNextOnMainThread() = 0;
virtual void StepNextOnMainThread(Isolate* isolate) = 0;
// Step the job forward by one state on a background thread.
virtual void StepNextOnBackgroundThread() = 0;
// Transition from any state to kInitial and free all resources.
virtual void ResetOnMainThread() = 0;
virtual void ResetOnMainThread(Isolate* isolate) = 0;
// Estimate how long the next step will take using the tracer.
virtual double EstimateRuntimeOfNextStepInMs() const = 0;
......
......@@ -27,7 +27,7 @@ bool DoNextStepOnMainThread(Isolate* isolate, CompilerDispatcherJob* job,
DCHECK(ThreadId::Current().Equals(isolate->thread_id()));
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"),
"V8.CompilerDispatcherForgroundStep");
job->StepNextOnMainThread();
job->StepNextOnMainThread(isolate);
DCHECK_EQ(job->IsFailed(), isolate->has_pending_exception());
if (job->IsFailed() && exception_handling == ExceptionHandling::kSwallow) {
......@@ -270,10 +270,11 @@ bool CompilerDispatcher::Enqueue(
}
std::unique_ptr<CompilerDispatcherJob> job(new UnoptimizedCompileJob(
tracer_.get(), max_stack_size_, source, start_position, end_position,
language_mode, function_literal_id, native, module, is_named_expression,
isolate_->heap()->HashSeed(), isolate_->allocator(), compiler_hints,
isolate_->ast_string_constants(), finish_callback));
isolate_->thread_id().ToInteger(), tracer_.get(), max_stack_size_, source,
start_position, end_position, language_mode, function_literal_id, native,
module, is_named_expression, isolate_->heap()->HashSeed(),
isolate_->allocator(), compiler_hints, isolate_->ast_string_constants(),
finish_callback));
JobId id = Enqueue(std::move(job));
if (job_id != nullptr) {
*job_id = id;
......@@ -388,7 +389,7 @@ void CompilerDispatcher::AbortAll(BlockingBehavior blocking) {
it.second->ShortPrint();
PrintF("\n");
}
it.second->ResetOnMainThread();
it.second->ResetOnMainThread(isolate_);
}
jobs_.clear();
shared_to_unoptimized_job_id_.Clear();
......@@ -709,7 +710,7 @@ CompilerDispatcher::JobMap::const_iterator CompilerDispatcher::InsertJob(
CompilerDispatcher::JobMap::const_iterator CompilerDispatcher::RemoveJob(
CompilerDispatcher::JobMap::const_iterator it) {
CompilerDispatcherJob* job = it->second.get();
job->ResetOnMainThread();
job->ResetOnMainThread(isolate_);
// Unmaps unoptimized jobs' SFIs to their job id.
if (job->type() == CompilerDispatcherJob::kUnoptimizedCompile) {
......
......@@ -56,12 +56,13 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob {
size_t max_stack_size);
// TODO(wiktorg) document it better once I know how it relates to whole stuff
// Creates a UnoptimizedCompileJob in ready to parse top-level function state.
UnoptimizedCompileJob(CompilerDispatcherTracer* tracer, size_t max_stack_size,
Handle<String> source, int start_position,
int end_position, LanguageMode language_mode,
int function_literal_id, bool native, bool module,
bool is_named_expression, uint32_t hash_seed,
AccountingAllocator* zone_allocator, int compiler_hints,
UnoptimizedCompileJob(int main_thread_id, CompilerDispatcherTracer* tracer,
size_t max_stack_size, Handle<String> source,
int start_position, int end_position,
LanguageMode language_mode, int function_literal_id,
bool native, bool module, bool is_named_expression,
uint32_t hash_seed, AccountingAllocator* zone_allocator,
int compiler_hints,
const AstStringConstants* ast_string_constants,
UnoptimizedCompileJobFinishCallback* finish_callback);
......@@ -90,13 +91,13 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob {
}
// Step the job forward by one state on the main thread.
void StepNextOnMainThread() override;
void StepNextOnMainThread(Isolate* isolate) override;
// Step the job forward by one state on a background thread.
void StepNextOnBackgroundThread() override;
// Transition from any state to kInitial and free all resources.
void ResetOnMainThread() override;
void ResetOnMainThread(Isolate* isolate) override;
// Estimate how long the next step will take using the tracer.
double EstimateRuntimeOfNextStepInMs() const override;
......@@ -115,7 +116,7 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob {
Status status() const { return status_; }
Status status_;
Isolate* isolate_;
int main_thread_id_;
CompilerDispatcherTracer* tracer_;
Handle<Context> context_; // Global handle.
Handle<SharedFunctionInfo> shared_; // Global handle.
......@@ -139,26 +140,26 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileJob : public CompilerDispatcherJob {
bool trace_compiler_dispatcher_jobs_;
// Transition from kInitial to kReadyToParse.
void PrepareToParseOnMainThread();
void PrepareToParseOnMainThread(Isolate* isolate);
// Transition from kReadyToParse to kParsed (or kDone if there is
// finish_callback).
void Parse();
// Transition from kParsed to kReadyToAnalyze (or kFailed).
void FinalizeParsingOnMainThread();
void FinalizeParsingOnMainThread(Isolate* isolate);
// Transition from kReadyToAnalyze to kAnalyzed (or kFailed).
void AnalyzeOnMainThread();
void AnalyzeOnMainThread(Isolate* isolate);
// Transition from kAnalyzed to kReadyToCompile (or kFailed).
void PrepareToCompileOnMainThread();
void PrepareToCompileOnMainThread(Isolate* isolate);
// Transition from kReadyToCompile to kCompiled.
void Compile();
// Transition from kCompiled to kDone (or kFailed).
void FinalizeCompilingOnMainThread();
void FinalizeCompilingOnMainThread(Isolate* isolate);
DISALLOW_COPY_AND_ASSIGN(UnoptimizedCompileJob);
};
......
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