36 bytecode_(handles->NewHandle(sfi->GetBytecodeArray(isolate))) {
37 DCHECK(sfi->is_compiled());
46 RCS_SCOPE(local_isolate, RuntimeCallCounterId::kCompileBackgroundBaseline);
50 compiler.GenerateCode();
52 local_isolate->heap()->NewPersistentMaybeHandle(compiler.Build());
74 ss <<
"[Concurrent Sparkplug Off Thread] Function ";
82 isolate, LogEventListener::CodeTag::kFunction,
102 handles_ = isolate->NewPersistentHandles();
103 tasks_.reserve(batch_size);
104 for (
int i = 0;
i < batch_size;
i++) {
115 if (shared->is_sparkplug_compiling())
continue;
120 PrintF(scope.
file(),
"[Concurrent Sparkplug] compiling %zu functions\n",
128 for (
auto& task :
tasks_) {
129 task.Compile(local_isolate);
138 for (
auto& task :
tasks_) {
139 task.Install(isolate);
144 std::vector<BaselineCompilerTask>
tasks_;
154 LockedQueue<std::unique_ptr<BaselineBatchCompilerJob>>* incoming_queue,
155 LockedQueue<std::unique_ptr<BaselineBatchCompilerJob>>* outcoming_queue)
168 std::unique_ptr<BaselineBatchCompilerJob> job;
171 job->Compile(&local_isolate);
178 size_t max_threads =
v8_flags.concurrent_sparkplug_max_threads;
180 if (max_threads > 0) {
181 return std::min(max_threads, num_tasks);
193 if (
v8_flags.concurrent_sparkplug) {
194 TaskPriority priority =
195 v8_flags.concurrent_sparkplug_high_priority_threads
196 ? TaskPriority::kUserBlocking
197 : TaskPriority::kUserVisible;
198 job_handle_ = V8::GetCurrentPlatform()->PostJob(
199 priority, std::make_unique<JobDispatcher>(isolate_, &incoming_queue_,
222 std::unique_ptr<BaselineBatchCompilerJob> job;
239 estimated_instruction_size_(0),
241 if (
v8_flags.concurrent_sparkplug) {
242 concurrent_compiler_ =
243 std::make_unique<ConcurrentBaselineCompiler>(isolate_);
255 return v8_flags.concurrent_sparkplug &&
264 function->shared()->is_compiled_scope(
isolate_));
318 function->shared()->is_compiled_scope(
isolate_));
341 if (shared->HasBaselineCode())
return false;
343 if (shared->is_sparkplug_compiling())
return false;
350 shared->GetBytecodeArray(
isolate_));
353 if (
v8_flags.trace_baseline_batch_compilation) {
355 PrintF(trace_scope.
file(),
"[Baseline batch compilation] Enqueued SFI %s",
356 shared->DebugNameCStr().get());
358 " with estimated size %d (current budget: %d/%d)\n", estimated_size,
360 v8_flags.baseline_batch_compilation_threshold.value());
363 v8_flags.baseline_batch_compilation_threshold) {
364 if (
v8_flags.trace_baseline_batch_compilation) {
367 "[Baseline batch compilation] Compiling current batch of %d "
384 if (!shared->is_compiled())
return false;
virtual bool ShouldYield()=0
double InMillisecondsF() const
static bool CompileSharedWithBaseline(Isolate *isolate, Handle< SharedFunctionInfo > shared, ClearExceptionFlag flag, IsCompiledScope *is_compiled_scope)
static bool CompileBaseline(Isolate *isolate, DirectHandle< JSFunction > function, ClearExceptionFlag flag, IsCompiledScope *is_compiled_scope)
static void LogFunctionCompilation(Isolate *isolate, LogEventListener::CodeTag code_type, DirectHandle< Script > script, DirectHandle< SharedFunctionInfo > shared, DirectHandle< FeedbackVector > vector, DirectHandle< AbstractCode > abstract_code, CodeKind kind, double time_taken_ms)
Handle< WeakFixedArray > NewWeakFixedArray(int length, AllocationType allocation=AllocationType::kYoung)
DirectHandle< WeakFixedArray > CopyWeakFixedArrayAndGrow(DirectHandle< WeakFixedArray > array, int grow_by)
static void Destroy(Address *location)
IndirectHandle< Object > Create(Tagged< Object > value)
GlobalHandles * global_handles() const
bool flush_denormals() const
bool EfficiencyModeEnabledForTiering()
StackGuard * stack_guard()
CodeTracer * GetCodeTracer()
v8::internal::Factory * factory()
std::unique_ptr< PersistentHandles > DetachPersistentHandles()
void AttachPersistentHandles(std::unique_ptr< PersistentHandles > persistent_handles)
bool GetHeapObjectIfWeak(Tagged< HeapObject > *result) const
void Compile(LocalIsolate *local_isolate)
std::unique_ptr< PersistentHandles > handles_
BaselineBatchCompilerJob(Isolate *isolate, DirectHandle< WeakFixedArray > task_queue, int batch_size)
std::vector< BaselineCompilerTask > tasks_
void Install(Isolate *isolate)
void Enqueue(DirectHandle< SharedFunctionInfo > shared)
int estimated_instruction_size_
bool ShouldCompileBatch(Tagged< SharedFunctionInfo > shared)
BaselineBatchCompiler(Isolate *isolate)
static const int kInitialQueueSize
void CompileBatch(DirectHandle< JSFunction > function)
void EnsureQueueCapacity()
bool MaybeCompileFunction(Tagged< MaybeObject > maybe_sfi)
void CompileBatchConcurrent(Tagged< SharedFunctionInfo > shared)
void EnqueueFunction(DirectHandle< JSFunction > function)
Handle< WeakFixedArray > compilation_queue_
std::unique_ptr< ConcurrentBaselineCompiler > concurrent_compiler_
void EnqueueSFI(Tagged< SharedFunctionInfo > shared)
BaselineCompilerTask(const BaselineCompilerTask &) V8_NOEXCEPT=delete
BaselineCompilerTask(BaselineCompilerTask &&) V8_NOEXCEPT=default
void Compile(LocalIsolate *local_isolate)
base::TimeDelta time_taken_
IndirectHandle< SharedFunctionInfo > shared_function_info_
void Install(Isolate *isolate)
MaybeIndirectHandle< Code > maybe_code_
IndirectHandle< BytecodeArray > bytecode_
BaselineCompilerTask(Isolate *isolate, PersistentHandles *handles, Tagged< SharedFunctionInfo > sfi)
static int EstimateInstructionSize(Tagged< BytecodeArray > bytecode)
LockedQueue< std::unique_ptr< BaselineBatchCompilerJob > > * incoming_queue_
void Run(JobDelegate *delegate) override
LockedQueue< std::unique_ptr< BaselineBatchCompilerJob > > * outgoing_queue_
size_t GetMaxConcurrency(size_t worker_count) const override
JobDispatcher(Isolate *isolate, LockedQueue< std::unique_ptr< BaselineBatchCompilerJob > > *incoming_queue, LockedQueue< std::unique_ptr< BaselineBatchCompilerJob > > *outcoming_queue)
ConcurrentBaselineCompiler(Isolate *isolate)
LockedQueue< std::unique_ptr< BaselineBatchCompilerJob > > outgoing_queue_
std::unique_ptr< JobHandle > job_handle_
LockedQueue< std::unique_ptr< BaselineBatchCompilerJob > > incoming_queue_
~ConcurrentBaselineCompiler()
void CompileBatch(Handle< WeakFixedArray > task_queue, int batch_size)
SharedFunctionInfoRef shared
static bool CanCompileWithConcurrentBaseline(Tagged< SharedFunctionInfo > shared, Isolate *isolate)
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
void PrintF(const char *format,...)
V8_INLINE DirectHandle< T > direct_handle(Tagged< T > object, Isolate *isolate)
void Print(Tagged< Object > obj)
void ShortPrint(Tagged< Object > obj, FILE *out)
Tagged< MaybeWeak< T > > MakeWeak(Tagged< T > value)
Tagged< ClearedWeakValue > ClearedValue(PtrComprCageBase cage_base)
V8_EXPORT_PRIVATE FlagValues v8_flags
bool CanCompileWithBaseline(Isolate *isolate, Tagged< SharedFunctionInfo > shared)
Tagged< To > Cast(Tagged< From > value, const v8::SourceLocation &loc=INIT_SOURCE_LOCATION_IN_DEBUG)
static constexpr ReleaseStoreTag kReleaseStore
#define DCHECK_NOT_NULL(val)
#define DCHECK(condition)