Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | Friends | List of all members
dart::BackgroundCompiler Class Reference

#include <compiler.h>

Public Member Functions

 BackgroundCompiler (IsolateGroup *isolate_group)
 
virtual ~BackgroundCompiler ()
 
bool EnqueueCompilation (const Function &function)
 
void VisitPointers (ObjectPointerVisitor *visitor)
 
BackgroundCompilationQueuefunction_queue () const
 
bool is_running () const
 
void Run ()
 

Static Public Member Functions

static void Stop (IsolateGroup *isolate_group)
 

Friends

class NoBackgroundCompilerScope
 

Detailed Description

Definition at line 120 of file compiler.h.

Constructor & Destructor Documentation

◆ BackgroundCompiler()

dart::BackgroundCompiler::BackgroundCompiler ( IsolateGroup isolate_group)
explicit

Definition at line 1112 of file compiler.cc.

1113 : isolate_group_(isolate_group),
1114 monitor_(),
1115 function_queue_(new BackgroundCompilationQueue()),
1116 running_(false),
1117 done_(true),
1118 disabled_depth_(0) {}

◆ ~BackgroundCompiler()

dart::BackgroundCompiler::~BackgroundCompiler ( )
virtual

Definition at line 1121 of file compiler.cc.

1121 {
1122 delete function_queue_;
1123}

Member Function Documentation

◆ EnqueueCompilation()

bool dart::BackgroundCompiler::EnqueueCompilation ( const Function function)

Definition at line 1179 of file compiler.cc.

1179 {
1180 Thread* thread = Thread::Current();
1181 ASSERT(thread->IsDartMutatorThread());
1182 ASSERT(thread->CanAcquireSafepointLocks());
1183
1184 SafepointMonitorLocker ml(&monitor_);
1185 if (disabled_depth_ > 0) return false;
1186 if (!running_ && done_) {
1187 running_ = true;
1188 done_ = false;
1189 // If we ever wanted to run the BG compiler on the
1190 // `IsolateGroup::mutator_pool()` we would need to ensure the BG compiler
1191 // stops when it's idle - otherwise the [MutatorThreadPool]-based idle
1192 // notification would not work anymore.
1193 if (!Dart::thread_pool()->Run<BackgroundCompilerTask>(this)) {
1194 running_ = false;
1195 done_ = true;
1196 return false;
1197 }
1198 }
1199
1200 ASSERT(running_);
1201 if (function_queue()->ContainsObj(function)) {
1202 return true;
1203 }
1204 QueueElement* elem = new QueueElement(function);
1205 function_queue()->Add(elem);
1206 ml.NotifyAll();
1207 return true;
1208}
void Add(QueueElement *value)
Definition: compiler.cc:1037
BackgroundCompilationQueue * function_queue() const
Definition: compiler.h:136
static ThreadPool * thread_pool()
Definition: dart.h:73
static Thread * Current()
Definition: thread.h:362
#define ASSERT(E)
Dart_NativeFunction function
Definition: fuchsia.cc:51

◆ function_queue()

BackgroundCompilationQueue * dart::BackgroundCompiler::function_queue ( ) const
inline

Definition at line 136 of file compiler.h.

136{ return function_queue_; }

◆ is_running()

bool dart::BackgroundCompiler::is_running ( ) const
inline

Definition at line 137 of file compiler.h.

137{ return running_; }

◆ Run()

void dart::BackgroundCompiler::Run ( )

Definition at line 1125 of file compiler.cc.

1125 {
1127 isolate_group_, Thread::kCompilerTask, /*bypass_safepoint=*/false);
1128 ASSERT(result);
1129 {
1130 Thread* thread = Thread::Current();
1131 StackZone stack_zone(thread);
1132 Zone* zone = stack_zone.GetZone();
1133 HANDLESCOPE(thread);
1134 Function& function = Function::Handle(zone);
1135 QueueElement* element = nullptr;
1136 {
1137 SafepointMonitorLocker ml(&monitor_);
1138 if (running_ && !function_queue()->IsEmpty()) {
1139 element = function_queue()->Remove();
1140 function ^= element->function();
1141 }
1142 }
1143 if (element != nullptr) {
1144 delete element;
1147
1148 // If an optimizable method is not optimized, put it back on
1149 // the background queue (unless it was passed to foreground).
1150 if ((!function.HasOptimizedCode() && function.IsOptimizable()) ||
1151 FLAG_stress_test_background_compilation) {
1153 SafepointMonitorLocker ml(&monitor_);
1154 if (running_) {
1155 QueueElement* repeat_qelem = new QueueElement(function);
1156 function_queue()->Add(repeat_qelem);
1157 }
1158 }
1159 }
1160 }
1161 }
1162 Thread::ExitIsolateGroupAsHelper(/*bypass_safepoint=*/false);
1163 {
1164 MonitorLocker ml(&monitor_);
1165 if (running_ && !function_queue()->IsEmpty() &&
1166 Dart::thread_pool()->Run<BackgroundCompilerTask>(this)) {
1167 // Successfully scheduled a new task.
1168 } else {
1169 // Background compiler done. This notification must happen after the
1170 // thread leaves to group to avoid a shutdown race with the thread
1171 // registry.
1172 running_ = false;
1173 done_ = true;
1174 ml.NotifyAll();
1175 }
1176 }
1177}
static bool CanOptimizeFunction(Thread *thread, const Function &function)
Definition: compiler.cc:229
static constexpr intptr_t kNoOSRDeoptId
Definition: compiler.h:73
static ObjectPtr CompileOptimizedFunction(Thread *thread, const Function &function, intptr_t osr_id=kNoOSRDeoptId)
Definition: compiler.cc:886
static Object & Handle()
Definition: object.h:407
@ kCompilerTask
Definition: thread.h:348
static void ExitIsolateGroupAsHelper(bool bypass_safepoint)
Definition: thread.cc:499
static bool EnterIsolateGroupAsHelper(IsolateGroup *isolate_group, TaskKind kind, bool bypass_safepoint)
Definition: thread.cc:481
GAsyncResult * result
#define HANDLESCOPE(thread)
Definition: handles.h:321
bool EMSCRIPTEN_KEEPALIVE IsEmpty(const SkPath &path)

◆ Stop()

static void dart::BackgroundCompiler::Stop ( IsolateGroup isolate_group)
inlinestatic

Definition at line 125 of file compiler.h.

125 {
126 isolate_group->background_compiler()->Stop();
127 }

◆ VisitPointers()

void dart::BackgroundCompiler::VisitPointers ( ObjectPointerVisitor visitor)

Definition at line 1210 of file compiler.cc.

1210 {
1211 function_queue_->VisitObjectPointers(visitor);
1212}
void VisitObjectPointers(ObjectPointerVisitor *visitor)
Definition: compiler.cc:1026

Friends And Related Function Documentation

◆ NoBackgroundCompilerScope

friend class NoBackgroundCompilerScope
friend

Definition at line 142 of file compiler.h.


The documentation for this class was generated from the following files: