Commit 27708001 authored by Jakob Gruber's avatar Jakob Gruber Committed by V8 LUCI CQ

[compiler] Extract TF-specific parts of OptimizedCompilationJob

.. into new virtual subclass TurbofanCompilationJob. Update all TF code
to derive from this class. Specifically, the OptimizedCompilationInfo is
TF-specific and now lives in TurbofanCompilationJob.

The motivation behind this is that Maglev now also uses this
infrastructure.

Drive-by: Replace CompilationMode with ConcurrencyMode.

Bug: v8:7700
Change-Id: Iae6d1ffd1c810e2e45cad6c9b4e43d4c82ac54a7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3528493Reviewed-by: 's avatarTobias Tebbi <tebbi@chromium.org>
Auto-Submit: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79515}
parent e66a1116
...@@ -386,7 +386,6 @@ void RecordUnoptimizedFunctionCompilation( ...@@ -386,7 +386,6 @@ void RecordUnoptimizedFunctionCompilation(
CompilationJob::Status OptimizedCompilationJob::PrepareJob(Isolate* isolate) { CompilationJob::Status OptimizedCompilationJob::PrepareJob(Isolate* isolate) {
DCHECK_EQ(ThreadId::Current(), isolate->thread_id()); DCHECK_EQ(ThreadId::Current(), isolate->thread_id());
DisallowJavascriptExecution no_js(isolate); DisallowJavascriptExecution no_js(isolate);
CompilerTracer::TracePrepareJob(isolate, compilation_info(), compiler_name_);
// Delegate to the underlying implementation. // Delegate to the underlying implementation.
DCHECK_EQ(state(), State::kReadyToPrepare); DCHECK_EQ(state(), State::kReadyToPrepare);
...@@ -414,22 +413,22 @@ CompilationJob::Status OptimizedCompilationJob::FinalizeJob(Isolate* isolate) { ...@@ -414,22 +413,22 @@ CompilationJob::Status OptimizedCompilationJob::FinalizeJob(Isolate* isolate) {
return UpdateState(FinalizeJobImpl(isolate), State::kSucceeded); return UpdateState(FinalizeJobImpl(isolate), State::kSucceeded);
} }
CompilationJob::Status OptimizedCompilationJob::RetryOptimization( CompilationJob::Status TurbofanCompilationJob::RetryOptimization(
BailoutReason reason) { BailoutReason reason) {
DCHECK(compilation_info_->IsOptimizing()); DCHECK(compilation_info_->IsOptimizing());
compilation_info_->RetryOptimization(reason); compilation_info_->RetryOptimization(reason);
return UpdateState(FAILED, State::kFailed); return UpdateState(FAILED, State::kFailed);
} }
CompilationJob::Status OptimizedCompilationJob::AbortOptimization( CompilationJob::Status TurbofanCompilationJob::AbortOptimization(
BailoutReason reason) { BailoutReason reason) {
DCHECK(compilation_info_->IsOptimizing()); DCHECK(compilation_info_->IsOptimizing());
compilation_info_->AbortOptimization(reason); compilation_info_->AbortOptimization(reason);
return UpdateState(FAILED, State::kFailed); return UpdateState(FAILED, State::kFailed);
} }
void OptimizedCompilationJob::RecordCompilationStats(CompilationMode mode, void TurbofanCompilationJob::RecordCompilationStats(ConcurrencyMode mode,
Isolate* isolate) const { Isolate* isolate) const {
DCHECK(compilation_info()->IsOptimizing()); DCHECK(compilation_info()->IsOptimizing());
Handle<JSFunction> function = compilation_info()->closure(); Handle<JSFunction> function = compilation_info()->closure();
double ms_creategraph = time_taken_to_prepare_.InMillisecondsF(); double ms_creategraph = time_taken_to_prepare_.InMillisecondsF();
...@@ -477,12 +476,12 @@ void OptimizedCompilationJob::RecordCompilationStats(CompilationMode mode, ...@@ -477,12 +476,12 @@ void OptimizedCompilationJob::RecordCompilationStats(CompilationMode mode,
base::TimeDelta time_foreground = base::TimeDelta time_foreground =
time_taken_to_prepare_ + time_taken_to_finalize_; time_taken_to_prepare_ + time_taken_to_finalize_;
switch (mode) { switch (mode) {
case OptimizedCompilationJob::kConcurrent: case ConcurrencyMode::kConcurrent:
time_background += time_taken_to_execute_; time_background += time_taken_to_execute_;
counters->turbofan_optimize_concurrent_total_time()->AddSample( counters->turbofan_optimize_concurrent_total_time()->AddSample(
static_cast<int>(ElapsedTime().InMicroseconds())); static_cast<int>(ElapsedTime().InMicroseconds()));
break; break;
case OptimizedCompilationJob::kSynchronous: case ConcurrencyMode::kNotConcurrent:
counters->turbofan_optimize_non_concurrent_total_time()->AddSample( counters->turbofan_optimize_non_concurrent_total_time()->AddSample(
static_cast<int>(ElapsedTime().InMicroseconds())); static_cast<int>(ElapsedTime().InMicroseconds()));
time_foreground += time_taken_to_execute_; time_foreground += time_taken_to_execute_;
...@@ -498,7 +497,7 @@ void OptimizedCompilationJob::RecordCompilationStats(CompilationMode mode, ...@@ -498,7 +497,7 @@ void OptimizedCompilationJob::RecordCompilationStats(CompilationMode mode,
} }
} }
void OptimizedCompilationJob::RecordFunctionCompilation( void TurbofanCompilationJob::RecordFunctionCompilation(
CodeEventListener::LogEventsAndTags tag, Isolate* isolate) const { CodeEventListener::LogEventsAndTags tag, Isolate* isolate) const {
Handle<AbstractCode> abstract_code = Handle<AbstractCode> abstract_code =
Handle<AbstractCode>::cast(compilation_info()->code()); Handle<AbstractCode>::cast(compilation_info()->code());
...@@ -912,11 +911,13 @@ bool PrepareJobWithHandleScope(OptimizedCompilationJob* job, Isolate* isolate, ...@@ -912,11 +911,13 @@ bool PrepareJobWithHandleScope(OptimizedCompilationJob* job, Isolate* isolate,
OptimizedCompilationInfo* compilation_info) { OptimizedCompilationInfo* compilation_info) {
CompilationHandleScope compilation(isolate, compilation_info); CompilationHandleScope compilation(isolate, compilation_info);
CanonicalHandleScopeForTurbofan canonical(isolate, compilation_info); CanonicalHandleScopeForTurbofan canonical(isolate, compilation_info);
CompilerTracer::TracePrepareJob(isolate, compilation_info,
job->compiler_name());
compilation_info->ReopenHandlesInNewHandleScope(isolate); compilation_info->ReopenHandlesInNewHandleScope(isolate);
return job->PrepareJob(isolate) == CompilationJob::SUCCEEDED; return job->PrepareJob(isolate) == CompilationJob::SUCCEEDED;
} }
bool GetOptimizedCodeNow(OptimizedCompilationJob* job, Isolate* isolate, bool GetOptimizedCodeNow(TurbofanCompilationJob* job, Isolate* isolate,
OptimizedCompilationInfo* compilation_info) { OptimizedCompilationInfo* compilation_info) {
TimerEventScope<TimerEventRecompileSynchronous> timer(isolate); TimerEventScope<TimerEventRecompileSynchronous> timer(isolate);
RCS_SCOPE(isolate, RuntimeCallCounterId::kOptimizeNonConcurrent); RCS_SCOPE(isolate, RuntimeCallCounterId::kOptimizeNonConcurrent);
...@@ -945,14 +946,14 @@ bool GetOptimizedCodeNow(OptimizedCompilationJob* job, Isolate* isolate, ...@@ -945,14 +946,14 @@ bool GetOptimizedCodeNow(OptimizedCompilationJob* job, Isolate* isolate,
} }
// Success! // Success!
job->RecordCompilationStats(OptimizedCompilationJob::kSynchronous, isolate); job->RecordCompilationStats(ConcurrencyMode::kNotConcurrent, isolate);
DCHECK(!isolate->has_pending_exception()); DCHECK(!isolate->has_pending_exception());
InsertCodeIntoOptimizedCodeCache(compilation_info); InsertCodeIntoOptimizedCodeCache(compilation_info);
job->RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, isolate); job->RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, isolate);
return true; return true;
} }
bool GetOptimizedCodeLater(std::unique_ptr<OptimizedCompilationJob> job, bool GetOptimizedCodeLater(std::unique_ptr<TurbofanCompilationJob> job,
Isolate* isolate, Isolate* isolate,
OptimizedCompilationInfo* compilation_info, OptimizedCompilationInfo* compilation_info,
CodeKind code_kind, Handle<JSFunction> function) { CodeKind code_kind, Handle<JSFunction> function) {
...@@ -1056,7 +1057,7 @@ MaybeHandle<CodeT> CompileTurbofan( ...@@ -1056,7 +1057,7 @@ MaybeHandle<CodeT> CompileTurbofan(
// BUG(5946): This DCHECK is necessary to make certain that we won't // BUG(5946): This DCHECK is necessary to make certain that we won't
// tolerate the lack of a script without bytecode. // tolerate the lack of a script without bytecode.
DCHECK_IMPLIES(!has_script, shared->HasBytecodeArray()); DCHECK_IMPLIES(!has_script, shared->HasBytecodeArray());
std::unique_ptr<OptimizedCompilationJob> job( std::unique_ptr<TurbofanCompilationJob> job(
compiler::Pipeline::NewCompilationJob(isolate, function, kCodeKind, compiler::Pipeline::NewCompilationJob(isolate, function, kCodeKind,
has_script, osr_offset, osr_frame)); has_script, osr_offset, osr_frame));
OptimizedCompilationInfo* compilation_info = job->compilation_info(); OptimizedCompilationInfo* compilation_info = job->compilation_info();
...@@ -3317,8 +3318,8 @@ MaybeHandle<CodeT> Compiler::GetOptimizedCodeForOSR( ...@@ -3317,8 +3318,8 @@ MaybeHandle<CodeT> Compiler::GetOptimizedCodeForOSR(
} }
// static // static
bool Compiler::FinalizeOptimizedCompilationJob(OptimizedCompilationJob* job, bool Compiler::FinalizeTurbofanCompilationJob(TurbofanCompilationJob* job,
Isolate* isolate) { Isolate* isolate) {
VMState<COMPILER> state(isolate); VMState<COMPILER> state(isolate);
// Take ownership of the job. Deleting the job also tears down the zone. // Take ownership of the job. Deleting the job also tears down the zone.
std::unique_ptr<OptimizedCompilationJob> job_scope(job); std::unique_ptr<OptimizedCompilationJob> job_scope(job);
...@@ -3348,8 +3349,7 @@ bool Compiler::FinalizeOptimizedCompilationJob(OptimizedCompilationJob* job, ...@@ -3348,8 +3349,7 @@ bool Compiler::FinalizeOptimizedCompilationJob(OptimizedCompilationJob* job,
if (shared->optimization_disabled()) { if (shared->optimization_disabled()) {
job->RetryOptimization(BailoutReason::kOptimizationDisabled); job->RetryOptimization(BailoutReason::kOptimizationDisabled);
} else if (job->FinalizeJob(isolate) == CompilationJob::SUCCEEDED) { } else if (job->FinalizeJob(isolate) == CompilationJob::SUCCEEDED) {
job->RecordCompilationStats(OptimizedCompilationJob::kConcurrent, job->RecordCompilationStats(ConcurrencyMode::kConcurrent, isolate);
isolate);
job->RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, job->RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG,
isolate); isolate);
if (V8_LIKELY(use_result)) { if (V8_LIKELY(use_result)) {
......
...@@ -40,6 +40,7 @@ class ParseInfo; ...@@ -40,6 +40,7 @@ class ParseInfo;
class Parser; class Parser;
class RuntimeCallStats; class RuntimeCallStats;
class TimedHistogram; class TimedHistogram;
class TurbofanCompilationJob;
class UnoptimizedCompilationInfo; class UnoptimizedCompilationInfo;
class UnoptimizedCompilationJob; class UnoptimizedCompilationJob;
class WorkerThreadRuntimeCallStats; class WorkerThreadRuntimeCallStats;
...@@ -111,9 +112,9 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic { ...@@ -111,9 +112,9 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
Isolate* isolate, Isolate* isolate,
ClearExceptionFlag flag); ClearExceptionFlag flag);
// Finalize and install optimized code from previously run job. // Finalize and install Turbofan code from a previously run job.
static bool FinalizeOptimizedCompilationJob(OptimizedCompilationJob* job, static bool FinalizeTurbofanCompilationJob(TurbofanCompilationJob* job,
Isolate* isolate); Isolate* isolate);
// Give the compiler a chance to perform low-latency initialization tasks of // Give the compiler a chance to perform low-latency initialization tasks of
// the given {function} on its instantiation. Note that only the runtime will // the given {function} on its instantiation. Note that only the runtime will
...@@ -364,24 +365,48 @@ class UnoptimizedCompilationJob : public CompilationJob { ...@@ -364,24 +365,48 @@ class UnoptimizedCompilationJob : public CompilationJob {
// Each of the three phases can either fail or succeed. // Each of the three phases can either fail or succeed.
class OptimizedCompilationJob : public CompilationJob { class OptimizedCompilationJob : public CompilationJob {
public: public:
OptimizedCompilationJob(OptimizedCompilationInfo* compilation_info, OptimizedCompilationJob(const char* compiler_name, State initial_state)
const char* compiler_name, : CompilationJob(initial_state), compiler_name_(compiler_name) {}
State initial_state = State::kReadyToPrepare)
: CompilationJob(initial_state),
compilation_info_(compilation_info),
compiler_name_(compiler_name) {}
// Prepare the compile job. Must be called on the main thread. // Prepare the compile job. Must be called on the main thread.
V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Status PrepareJob(Isolate* isolate); V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Status PrepareJob(Isolate* isolate);
// Executes the compile job. Can be called on a background thread if // Executes the compile job. Can be called on a background thread.
// can_execute_on_background_thread() returns true.
V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Status V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Status
ExecuteJob(RuntimeCallStats* stats, LocalIsolate* local_isolate = nullptr); ExecuteJob(RuntimeCallStats* stats, LocalIsolate* local_isolate = nullptr);
// Finalizes the compile job. Must be called on the main thread. // Finalizes the compile job. Must be called on the main thread.
V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Status FinalizeJob(Isolate* isolate); V8_EXPORT_PRIVATE V8_WARN_UNUSED_RESULT Status FinalizeJob(Isolate* isolate);
const char* compiler_name() const { return compiler_name_; }
protected:
// Overridden by the actual implementation.
virtual Status PrepareJobImpl(Isolate* isolate) = 0;
virtual Status ExecuteJobImpl(RuntimeCallStats* stats,
LocalIsolate* local_heap) = 0;
virtual Status FinalizeJobImpl(Isolate* isolate) = 0;
base::TimeDelta time_taken_to_prepare_;
base::TimeDelta time_taken_to_execute_;
base::TimeDelta time_taken_to_finalize_;
private:
const char* const compiler_name_;
};
// Thin wrapper to split off Turbofan-specific parts.
class TurbofanCompilationJob : public OptimizedCompilationJob {
public:
TurbofanCompilationJob(OptimizedCompilationInfo* compilation_info,
State initial_state)
: OptimizedCompilationJob("Turbofan", initial_state),
compilation_info_(compilation_info) {}
OptimizedCompilationInfo* compilation_info() const {
return compilation_info_;
}
// Report a transient failure, try again next time. Should only be called on // Report a transient failure, try again next time. Should only be called on
// optimization compilation jobs. // optimization compilation jobs.
Status RetryOptimization(BailoutReason reason); Status RetryOptimization(BailoutReason reason);
...@@ -390,28 +415,12 @@ class OptimizedCompilationJob : public CompilationJob { ...@@ -390,28 +415,12 @@ class OptimizedCompilationJob : public CompilationJob {
// Should only be called on optimization compilation jobs. // Should only be called on optimization compilation jobs.
Status AbortOptimization(BailoutReason reason); Status AbortOptimization(BailoutReason reason);
enum CompilationMode { kConcurrent, kSynchronous }; void RecordCompilationStats(ConcurrencyMode mode, Isolate* isolate) const;
void RecordCompilationStats(CompilationMode mode, Isolate* isolate) const;
void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag, void RecordFunctionCompilation(CodeEventListener::LogEventsAndTags tag,
Isolate* isolate) const; Isolate* isolate) const;
OptimizedCompilationInfo* compilation_info() const {
return compilation_info_;
}
protected:
// Overridden by the actual implementation.
virtual Status PrepareJobImpl(Isolate* isolate) = 0;
virtual Status ExecuteJobImpl(RuntimeCallStats* stats,
LocalIsolate* local_heap) = 0;
virtual Status FinalizeJobImpl(Isolate* isolate) = 0;
private: private:
OptimizedCompilationInfo* compilation_info_; OptimizedCompilationInfo* const compilation_info_;
base::TimeDelta time_taken_to_prepare_;
base::TimeDelta time_taken_to_execute_;
base::TimeDelta time_taken_to_finalize_;
const char* compiler_name_;
}; };
class FinalizeUnoptimizedCompilationData { class FinalizeUnoptimizedCompilationData {
......
...@@ -24,7 +24,7 @@ namespace internal { ...@@ -24,7 +24,7 @@ namespace internal {
namespace { namespace {
void DisposeCompilationJob(OptimizedCompilationJob* job, void DisposeCompilationJob(TurbofanCompilationJob* job,
bool restore_function_code) { bool restore_function_code) {
if (restore_function_code) { if (restore_function_code) {
Handle<JSFunction> function = job->compilation_info()->closure(); Handle<JSFunction> function = job->compilation_info()->closure();
...@@ -96,18 +96,18 @@ OptimizingCompileDispatcher::~OptimizingCompileDispatcher() { ...@@ -96,18 +96,18 @@ OptimizingCompileDispatcher::~OptimizingCompileDispatcher() {
DeleteArray(input_queue_); DeleteArray(input_queue_);
} }
OptimizedCompilationJob* OptimizingCompileDispatcher::NextInput( TurbofanCompilationJob* OptimizingCompileDispatcher::NextInput(
LocalIsolate* local_isolate) { LocalIsolate* local_isolate) {
base::MutexGuard access_input_queue_(&input_queue_mutex_); base::MutexGuard access_input_queue_(&input_queue_mutex_);
if (input_queue_length_ == 0) return nullptr; if (input_queue_length_ == 0) return nullptr;
OptimizedCompilationJob* job = input_queue_[InputQueueIndex(0)]; TurbofanCompilationJob* job = input_queue_[InputQueueIndex(0)];
DCHECK_NOT_NULL(job); DCHECK_NOT_NULL(job);
input_queue_shift_ = InputQueueIndex(1); input_queue_shift_ = InputQueueIndex(1);
input_queue_length_--; input_queue_length_--;
return job; return job;
} }
void OptimizingCompileDispatcher::CompileNext(OptimizedCompilationJob* job, void OptimizingCompileDispatcher::CompileNext(TurbofanCompilationJob* job,
LocalIsolate* local_isolate) { LocalIsolate* local_isolate) {
if (!job) return; if (!job) return;
...@@ -129,7 +129,7 @@ void OptimizingCompileDispatcher::CompileNext(OptimizedCompilationJob* job, ...@@ -129,7 +129,7 @@ void OptimizingCompileDispatcher::CompileNext(OptimizedCompilationJob* job,
void OptimizingCompileDispatcher::FlushOutputQueue(bool restore_function_code) { void OptimizingCompileDispatcher::FlushOutputQueue(bool restore_function_code) {
for (;;) { for (;;) {
OptimizedCompilationJob* job = nullptr; TurbofanCompilationJob* job = nullptr;
{ {
base::MutexGuard access_output_queue_(&output_queue_mutex_); base::MutexGuard access_output_queue_(&output_queue_mutex_);
if (output_queue_.empty()) return; if (output_queue_.empty()) return;
...@@ -144,7 +144,7 @@ void OptimizingCompileDispatcher::FlushOutputQueue(bool restore_function_code) { ...@@ -144,7 +144,7 @@ void OptimizingCompileDispatcher::FlushOutputQueue(bool restore_function_code) {
void OptimizingCompileDispatcher::FlushInputQueue() { void OptimizingCompileDispatcher::FlushInputQueue() {
base::MutexGuard access_input_queue_(&input_queue_mutex_); base::MutexGuard access_input_queue_(&input_queue_mutex_);
while (input_queue_length_ > 0) { while (input_queue_length_ > 0) {
OptimizedCompilationJob* job = input_queue_[InputQueueIndex(0)]; TurbofanCompilationJob* job = input_queue_[InputQueueIndex(0)];
DCHECK_NOT_NULL(job); DCHECK_NOT_NULL(job);
input_queue_shift_ = InputQueueIndex(1); input_queue_shift_ = InputQueueIndex(1);
input_queue_length_--; input_queue_length_--;
...@@ -196,7 +196,7 @@ void OptimizingCompileDispatcher::InstallOptimizedFunctions() { ...@@ -196,7 +196,7 @@ void OptimizingCompileDispatcher::InstallOptimizedFunctions() {
HandleScope handle_scope(isolate_); HandleScope handle_scope(isolate_);
for (;;) { for (;;) {
OptimizedCompilationJob* job = nullptr; TurbofanCompilationJob* job = nullptr;
{ {
base::MutexGuard access_output_queue_(&output_queue_mutex_); base::MutexGuard access_output_queue_(&output_queue_mutex_);
if (output_queue_.empty()) return; if (output_queue_.empty()) return;
...@@ -213,7 +213,7 @@ void OptimizingCompileDispatcher::InstallOptimizedFunctions() { ...@@ -213,7 +213,7 @@ void OptimizingCompileDispatcher::InstallOptimizedFunctions() {
} }
DisposeCompilationJob(job, false); DisposeCompilationJob(job, false);
} else { } else {
Compiler::FinalizeOptimizedCompilationJob(job, isolate_); Compiler::FinalizeTurbofanCompilationJob(job, isolate_);
} }
} }
} }
...@@ -227,7 +227,7 @@ bool OptimizingCompileDispatcher::HasJobs() { ...@@ -227,7 +227,7 @@ bool OptimizingCompileDispatcher::HasJobs() {
} }
void OptimizingCompileDispatcher::QueueForOptimization( void OptimizingCompileDispatcher::QueueForOptimization(
OptimizedCompilationJob* job) { TurbofanCompilationJob* job) {
DCHECK(IsQueueAvailable()); DCHECK(IsQueueAvailable());
{ {
// Add job to the back of the input queue. // Add job to the back of the input queue.
......
...@@ -19,7 +19,7 @@ namespace v8 { ...@@ -19,7 +19,7 @@ namespace v8 {
namespace internal { namespace internal {
class LocalHeap; class LocalHeap;
class OptimizedCompilationJob; class TurbofanCompilationJob;
class RuntimeCallStats; class RuntimeCallStats;
class SharedFunctionInfo; class SharedFunctionInfo;
...@@ -32,7 +32,7 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher { ...@@ -32,7 +32,7 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher {
input_queue_shift_(0), input_queue_shift_(0),
ref_count_(0), ref_count_(0),
recompilation_delay_(FLAG_concurrent_recompilation_delay) { recompilation_delay_(FLAG_concurrent_recompilation_delay) {
input_queue_ = NewArray<OptimizedCompilationJob*>(input_queue_capacity_); input_queue_ = NewArray<TurbofanCompilationJob*>(input_queue_capacity_);
} }
~OptimizingCompileDispatcher(); ~OptimizingCompileDispatcher();
...@@ -40,7 +40,7 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher { ...@@ -40,7 +40,7 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher {
void Stop(); void Stop();
void Flush(BlockingBehavior blocking_behavior); void Flush(BlockingBehavior blocking_behavior);
// Takes ownership of |job|. // Takes ownership of |job|.
void QueueForOptimization(OptimizedCompilationJob* job); void QueueForOptimization(TurbofanCompilationJob* job);
void AwaitCompileTasks(); void AwaitCompileTasks();
void InstallOptimizedFunctions(); void InstallOptimizedFunctions();
...@@ -72,8 +72,8 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher { ...@@ -72,8 +72,8 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher {
bool restore_function_code); bool restore_function_code);
void FlushInputQueue(); void FlushInputQueue();
void FlushOutputQueue(bool restore_function_code); void FlushOutputQueue(bool restore_function_code);
void CompileNext(OptimizedCompilationJob* job, LocalIsolate* local_isolate); void CompileNext(TurbofanCompilationJob* job, LocalIsolate* local_isolate);
OptimizedCompilationJob* NextInput(LocalIsolate* local_isolate); TurbofanCompilationJob* NextInput(LocalIsolate* local_isolate);
inline int InputQueueIndex(int i) { inline int InputQueueIndex(int i) {
int result = (i + input_queue_shift_) % input_queue_capacity_; int result = (i + input_queue_shift_) % input_queue_capacity_;
...@@ -85,14 +85,14 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher { ...@@ -85,14 +85,14 @@ class V8_EXPORT_PRIVATE OptimizingCompileDispatcher {
Isolate* isolate_; Isolate* isolate_;
// Circular queue of incoming recompilation tasks (including OSR). // Circular queue of incoming recompilation tasks (including OSR).
OptimizedCompilationJob** input_queue_; TurbofanCompilationJob** input_queue_;
int input_queue_capacity_; int input_queue_capacity_;
int input_queue_length_; int input_queue_length_;
int input_queue_shift_; int input_queue_shift_;
base::Mutex input_queue_mutex_; base::Mutex input_queue_mutex_;
// Queue of recompilation tasks ready to be installed (excluding OSR). // Queue of recompilation tasks ready to be installed (excluding OSR).
std::queue<OptimizedCompilationJob*> output_queue_; std::queue<TurbofanCompilationJob*> output_queue_;
// Used for job based recompilation which has multiple producers on // Used for job based recompilation which has multiple producers on
// different threads. // different threads.
base::Mutex output_queue_mutex_; base::Mutex output_queue_mutex_;
......
...@@ -1066,7 +1066,7 @@ PipelineStatistics* CreatePipelineStatistics( ...@@ -1066,7 +1066,7 @@ PipelineStatistics* CreatePipelineStatistics(
} // namespace } // namespace
class PipelineCompilationJob final : public OptimizedCompilationJob { class PipelineCompilationJob final : public TurbofanCompilationJob {
public: public:
PipelineCompilationJob(Isolate* isolate, PipelineCompilationJob(Isolate* isolate,
Handle<SharedFunctionInfo> shared_info, Handle<SharedFunctionInfo> shared_info,
...@@ -1104,7 +1104,8 @@ PipelineCompilationJob::PipelineCompilationJob( ...@@ -1104,7 +1104,8 @@ PipelineCompilationJob::PipelineCompilationJob(
// Note that the OptimizedCompilationInfo is not initialized at the time // Note that the OptimizedCompilationInfo is not initialized at the time
// we pass it to the CompilationJob constructor, but it is not // we pass it to the CompilationJob constructor, but it is not
// dereferenced there. // dereferenced there.
: OptimizedCompilationJob(&compilation_info_, "TurboFan"), : TurbofanCompilationJob(&compilation_info_,
CompilationJob::State::kReadyToPrepare),
zone_(isolate->allocator(), kPipelineCompilationJobZoneName), zone_(isolate->allocator(), kPipelineCompilationJobZoneName),
zone_stats_(isolate->allocator()), zone_stats_(isolate->allocator()),
compilation_info_(&zone_, isolate, shared_info, function, code_kind, compilation_info_(&zone_, isolate, shared_info, function, code_kind,
...@@ -2481,7 +2482,7 @@ struct VerifyGraphPhase { ...@@ -2481,7 +2482,7 @@ struct VerifyGraphPhase {
#undef DECL_PIPELINE_PHASE_CONSTANTS_HELPER #undef DECL_PIPELINE_PHASE_CONSTANTS_HELPER
#if V8_ENABLE_WEBASSEMBLY #if V8_ENABLE_WEBASSEMBLY
class WasmHeapStubCompilationJob final : public OptimizedCompilationJob { class WasmHeapStubCompilationJob final : public TurbofanCompilationJob {
public: public:
WasmHeapStubCompilationJob(Isolate* isolate, CallDescriptor* call_descriptor, WasmHeapStubCompilationJob(Isolate* isolate, CallDescriptor* call_descriptor,
std::unique_ptr<Zone> zone, Graph* graph, std::unique_ptr<Zone> zone, Graph* graph,
...@@ -2491,8 +2492,7 @@ class WasmHeapStubCompilationJob final : public OptimizedCompilationJob { ...@@ -2491,8 +2492,7 @@ class WasmHeapStubCompilationJob final : public OptimizedCompilationJob {
// Note that the OptimizedCompilationInfo is not initialized at the time // Note that the OptimizedCompilationInfo is not initialized at the time
// we pass it to the CompilationJob constructor, but it is not // we pass it to the CompilationJob constructor, but it is not
// dereferenced there. // dereferenced there.
: OptimizedCompilationJob(&info_, "TurboFan", : TurbofanCompilationJob(&info_, CompilationJob::State::kReadyToExecute),
CompilationJob::State::kReadyToExecute),
debug_name_(std::move(debug_name)), debug_name_(std::move(debug_name)),
info_(base::CStrVector(debug_name_.get()), graph->zone(), kind), info_(base::CStrVector(debug_name_.get()), graph->zone(), kind),
call_descriptor_(call_descriptor), call_descriptor_(call_descriptor),
...@@ -2526,14 +2526,11 @@ class WasmHeapStubCompilationJob final : public OptimizedCompilationJob { ...@@ -2526,14 +2526,11 @@ class WasmHeapStubCompilationJob final : public OptimizedCompilationJob {
}; };
// static // static
std::unique_ptr<OptimizedCompilationJob> std::unique_ptr<TurbofanCompilationJob> Pipeline::NewWasmHeapStubCompilationJob(
Pipeline::NewWasmHeapStubCompilationJob(Isolate* isolate, Isolate* isolate, CallDescriptor* call_descriptor,
CallDescriptor* call_descriptor, std::unique_ptr<Zone> zone, Graph* graph, CodeKind kind,
std::unique_ptr<Zone> zone, std::unique_ptr<char[]> debug_name, const AssemblerOptions& options,
Graph* graph, CodeKind kind, SourcePositionTable* source_positions) {
std::unique_ptr<char[]> debug_name,
const AssemblerOptions& options,
SourcePositionTable* source_positions) {
return std::make_unique<WasmHeapStubCompilationJob>( return std::make_unique<WasmHeapStubCompilationJob>(
isolate, call_descriptor, std::move(zone), graph, kind, isolate, call_descriptor, std::move(zone), graph, kind,
std::move(debug_name), options, source_positions); std::move(debug_name), options, source_positions);
...@@ -3319,7 +3316,7 @@ MaybeHandle<Code> Pipeline::GenerateCodeForTesting( ...@@ -3319,7 +3316,7 @@ MaybeHandle<Code> Pipeline::GenerateCodeForTesting(
} }
// static // static
std::unique_ptr<OptimizedCompilationJob> Pipeline::NewCompilationJob( std::unique_ptr<TurbofanCompilationJob> Pipeline::NewCompilationJob(
Isolate* isolate, Handle<JSFunction> function, CodeKind code_kind, Isolate* isolate, Handle<JSFunction> function, CodeKind code_kind,
bool has_script, BytecodeOffset osr_offset, JavaScriptFrame* osr_frame) { bool has_script, BytecodeOffset osr_offset, JavaScriptFrame* osr_frame) {
Handle<SharedFunctionInfo> shared(function->shared(), isolate); Handle<SharedFunctionInfo> shared(function->shared(), isolate);
......
...@@ -18,7 +18,7 @@ namespace internal { ...@@ -18,7 +18,7 @@ namespace internal {
struct AssemblerOptions; struct AssemblerOptions;
class OptimizedCompilationInfo; class OptimizedCompilationInfo;
class OptimizedCompilationJob; class TurbofanCompilationJob;
class ProfileDataFromFile; class ProfileDataFromFile;
class RegisterConfiguration; class RegisterConfiguration;
...@@ -48,7 +48,7 @@ struct WasmLoopInfo; ...@@ -48,7 +48,7 @@ struct WasmLoopInfo;
class Pipeline : public AllStatic { class Pipeline : public AllStatic {
public: public:
// Returns a new compilation job for the given JavaScript function. // Returns a new compilation job for the given JavaScript function.
static V8_EXPORT_PRIVATE std::unique_ptr<OptimizedCompilationJob> static V8_EXPORT_PRIVATE std::unique_ptr<TurbofanCompilationJob>
NewCompilationJob(Isolate* isolate, Handle<JSFunction> function, NewCompilationJob(Isolate* isolate, Handle<JSFunction> function,
CodeKind code_kind, bool has_script, CodeKind code_kind, bool has_script,
BytecodeOffset osr_offset = BytecodeOffset::None(), BytecodeOffset osr_offset = BytecodeOffset::None(),
...@@ -70,7 +70,7 @@ class Pipeline : public AllStatic { ...@@ -70,7 +70,7 @@ class Pipeline : public AllStatic {
SourcePositionTable* source_positions = nullptr); SourcePositionTable* source_positions = nullptr);
// Returns a new compilation job for a wasm heap stub. // Returns a new compilation job for a wasm heap stub.
static std::unique_ptr<OptimizedCompilationJob> NewWasmHeapStubCompilationJob( static std::unique_ptr<TurbofanCompilationJob> NewWasmHeapStubCompilationJob(
Isolate* isolate, CallDescriptor* call_descriptor, Isolate* isolate, CallDescriptor* call_descriptor,
std::unique_ptr<Zone> zone, Graph* graph, CodeKind kind, std::unique_ptr<Zone> zone, Graph* graph, CodeKind kind,
std::unique_ptr<char[]> debug_name, const AssemblerOptions& options, std::unique_ptr<char[]> debug_name, const AssemblerOptions& options,
......
...@@ -7661,7 +7661,7 @@ void BuildInlinedJSToWasmWrapper( ...@@ -7661,7 +7661,7 @@ void BuildInlinedJSToWasmWrapper(
builder.BuildJSToWasmWrapper(false, js_wasm_call_data, frame_state); builder.BuildJSToWasmWrapper(false, js_wasm_call_data, frame_state);
} }
std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob( std::unique_ptr<TurbofanCompilationJob> NewJSToWasmCompilationJob(
Isolate* isolate, const wasm::FunctionSig* sig, Isolate* isolate, const wasm::FunctionSig* sig,
const wasm::WasmModule* module, bool is_import, const wasm::WasmModule* module, bool is_import,
const wasm::WasmFeatures& enabled_features) { const wasm::WasmFeatures& enabled_features) {
...@@ -8256,7 +8256,7 @@ MaybeHandle<Code> CompileWasmToJSWrapper(Isolate* isolate, ...@@ -8256,7 +8256,7 @@ MaybeHandle<Code> CompileWasmToJSWrapper(Isolate* isolate,
GetWasmCallDescriptor(zone.get(), sig, WasmCallKind::kWasmImportWrapper); GetWasmCallDescriptor(zone.get(), sig, WasmCallKind::kWasmImportWrapper);
// Run the compilation job synchronously. // Run the compilation job synchronously.
std::unique_ptr<OptimizedCompilationJob> job( std::unique_ptr<TurbofanCompilationJob> job(
Pipeline::NewWasmHeapStubCompilationJob( Pipeline::NewWasmHeapStubCompilationJob(
isolate, incoming, std::move(zone), graph, isolate, incoming, std::move(zone), graph,
CodeKind::WASM_TO_JS_FUNCTION, std::move(name_buffer), CodeKind::WASM_TO_JS_FUNCTION, std::move(name_buffer),
...@@ -8305,7 +8305,7 @@ MaybeHandle<Code> CompileJSToJSWrapper(Isolate* isolate, ...@@ -8305,7 +8305,7 @@ MaybeHandle<Code> CompileJSToJSWrapper(Isolate* isolate,
base::VectorOf(name_buffer.get(), kMaxNameLen) + kNamePrefixLen, sig); base::VectorOf(name_buffer.get(), kMaxNameLen) + kNamePrefixLen, sig);
// Run the compilation job synchronously. // Run the compilation job synchronously.
std::unique_ptr<OptimizedCompilationJob> job( std::unique_ptr<TurbofanCompilationJob> job(
Pipeline::NewWasmHeapStubCompilationJob( Pipeline::NewWasmHeapStubCompilationJob(
isolate, incoming, std::move(zone), graph, isolate, incoming, std::move(zone), graph,
CodeKind::JS_TO_JS_FUNCTION, std::move(name_buffer), CodeKind::JS_TO_JS_FUNCTION, std::move(name_buffer),
...@@ -8362,7 +8362,7 @@ Handle<CodeT> CompileCWasmEntry(Isolate* isolate, const wasm::FunctionSig* sig, ...@@ -8362,7 +8362,7 @@ Handle<CodeT> CompileCWasmEntry(Isolate* isolate, const wasm::FunctionSig* sig,
base::VectorOf(name_buffer.get(), kMaxNameLen) + kNamePrefixLen, sig); base::VectorOf(name_buffer.get(), kMaxNameLen) + kNamePrefixLen, sig);
// Run the compilation job synchronously. // Run the compilation job synchronously.
std::unique_ptr<OptimizedCompilationJob> job( std::unique_ptr<TurbofanCompilationJob> job(
Pipeline::NewWasmHeapStubCompilationJob( Pipeline::NewWasmHeapStubCompilationJob(
isolate, incoming, std::move(zone), graph, CodeKind::C_WASM_ENTRY, isolate, incoming, std::move(zone), graph, CodeKind::C_WASM_ENTRY,
std::move(name_buffer), AssemblerOptions::Default(isolate))); std::move(name_buffer), AssemblerOptions::Default(isolate)));
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
struct AssemblerOptions; struct AssemblerOptions;
class OptimizedCompilationJob; class TurbofanCompilationJob;
namespace compiler { namespace compiler {
// Forward declarations for some compiler data structures. // Forward declarations for some compiler data structures.
...@@ -138,8 +138,8 @@ wasm::WasmCode* CompileWasmJSFastCallWrapper(wasm::NativeModule*, ...@@ -138,8 +138,8 @@ wasm::WasmCode* CompileWasmJSFastCallWrapper(wasm::NativeModule*,
const wasm::FunctionSig*, const wasm::FunctionSig*,
Handle<JSFunction> target); Handle<JSFunction> target);
// Returns an OptimizedCompilationJob object for a JS to Wasm wrapper. // Returns an TurbofanCompilationJob object for a JS to Wasm wrapper.
std::unique_ptr<OptimizedCompilationJob> NewJSToWasmCompilationJob( std::unique_ptr<TurbofanCompilationJob> NewJSToWasmCompilationJob(
Isolate* isolate, const wasm::FunctionSig* sig, Isolate* isolate, const wasm::FunctionSig* sig,
const wasm::WasmModule* module, bool is_import, const wasm::WasmModule* module, bool is_import,
const wasm::WasmFeatures& enabled_features); const wasm::WasmFeatures& enabled_features);
......
...@@ -85,10 +85,8 @@ std::unique_ptr<MaglevCompilationJob> MaglevCompilationJob::New( ...@@ -85,10 +85,8 @@ std::unique_ptr<MaglevCompilationJob> MaglevCompilationJob::New(
MaglevCompilationJob::MaglevCompilationJob( MaglevCompilationJob::MaglevCompilationJob(
std::unique_ptr<MaglevCompilationInfo>&& info) std::unique_ptr<MaglevCompilationInfo>&& info)
: OptimizedCompilationJob(nullptr, kMaglevCompilerName), : OptimizedCompilationJob(kMaglevCompilerName, State::kReadyToPrepare),
info_(std::move(info)) { info_(std::move(info)) {
// TODO(jgruber, v8:7700): Remove the OptimizedCompilationInfo (which should
// be renamed to TurbofanCompilationInfo) from OptimizedCompilationJob.
DCHECK(FLAG_maglev); DCHECK(FLAG_maglev);
} }
......
...@@ -24,7 +24,7 @@ namespace v8 { ...@@ -24,7 +24,7 @@ namespace v8 {
namespace internal { namespace internal {
class Counters; class Counters;
class OptimizedCompilationJob; class TurbofanCompilationJob;
namespace wasm { namespace wasm {
...@@ -138,7 +138,7 @@ class V8_EXPORT_PRIVATE JSToWasmWrapperCompilationUnit final { ...@@ -138,7 +138,7 @@ class V8_EXPORT_PRIVATE JSToWasmWrapperCompilationUnit final {
bool is_import_; bool is_import_;
const FunctionSig* sig_; const FunctionSig* sig_;
bool use_generic_wrapper_; bool use_generic_wrapper_;
std::unique_ptr<OptimizedCompilationJob> job_; std::unique_ptr<TurbofanCompilationJob> job_;
}; };
} // namespace wasm } // namespace wasm
......
...@@ -26,11 +26,10 @@ using OptimizingCompileDispatcherTest = TestWithNativeContext; ...@@ -26,11 +26,10 @@ using OptimizingCompileDispatcherTest = TestWithNativeContext;
namespace { namespace {
class BlockingCompilationJob : public OptimizedCompilationJob { class BlockingCompilationJob : public TurbofanCompilationJob {
public: public:
BlockingCompilationJob(Isolate* isolate, Handle<JSFunction> function) BlockingCompilationJob(Isolate* isolate, Handle<JSFunction> function)
: OptimizedCompilationJob(&info_, "BlockingCompilationJob", : TurbofanCompilationJob(&info_, State::kReadyToExecute),
State::kReadyToExecute),
shared_(function->shared(), isolate), shared_(function->shared(), isolate),
zone_(isolate->allocator(), ZONE_NAME), zone_(isolate->allocator(), ZONE_NAME),
info_(&zone_, isolate, shared_, function, CodeKind::TURBOFAN), info_(&zone_, isolate, shared_, function, CodeKind::TURBOFAN),
......
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