Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 1113 of file compiler.cc.

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

◆ ~BackgroundCompiler()

dart::BackgroundCompiler::~BackgroundCompiler ( )
virtual

Definition at line 1122 of file compiler.cc.

1122 {
1123 delete function_queue_;
1124}

Member Function Documentation

◆ EnqueueCompilation()

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

Definition at line 1180 of file compiler.cc.

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

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

◆ 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 1211 of file compiler.cc.

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

Friends And Related Symbol 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: