Flutter Engine
The Flutter Engine
Static Public Member Functions | Static Public Attributes | Protected Types | Static Protected Member Functions | Static Protected Attributes | Friends | List of all members
dart::KernelIsolate Class Reference

#include <kernel_isolate.h>

Inheritance diagram for dart::KernelIsolate:
dart::AllStatic

Static Public Member Functions

static void InitializeState ()
 
static bool Start ()
 
static void Shutdown ()
 
static bool Exists ()
 
static bool IsRunning ()
 
static Dart_Port WaitForKernelPort ()
 
static Dart_Port KernelPort ()
 
static Dart_KernelCompilationResult CompileToKernel (const char *script_uri, const uint8_t *platform_kernel, intptr_t platform_kernel_size, int source_files_count=0, Dart_SourceFile source_files[]=nullptr, bool incremental_compile=true, bool for_snapshot=false, bool embed_sources=true, const char *package_config=nullptr, const char *multiroot_filepaths=nullptr, const char *multiroot_scheme=nullptr, Dart_KernelCompilationVerbosityLevel verbosity=Dart_KernelCompilationVerbosityLevel_All)
 
static Dart_KernelCompilationResult AcceptCompilation ()
 
static Dart_KernelCompilationResult RejectCompilation ()
 
static Dart_KernelCompilationResult UpdateInMemorySources (int source_files_count, Dart_SourceFile source_files[])
 
static Dart_KernelCompilationResult CompileExpressionToKernel (const uint8_t *platform_kernel, intptr_t platform_kernel_size, const char *expression, const Array &definitions, const Array &definition_types, const Array &type_definitions, const Array &type_bounds, const Array &type_defaults, const char *library_url, const char *klass, const char *method, TokenPosition token_pos, char const *script_uri, bool is_static)
 
static Dart_KernelCompilationResult ListDependencies ()
 
static void NotifyAboutIsolateGroupShutdown (const IsolateGroup *isolate_group)
 
static void AddExperimentalFlag (const char *value)
 
static bool GetExperimentalFlag (ExperimentalFeature feature)
 

Static Public Attributes

static const char * kName = DART_KERNEL_ISOLATE_NAME
 
static constexpr int kCompileTag = 0
 
static constexpr int kUpdateSourcesTag = 1
 
static constexpr int kAcceptTag = 2
 
static constexpr int kTrainTag = 3
 
static constexpr int kCompileExpressionTag = 4
 
static constexpr int kListDependenciesTag = 5
 
static constexpr int kNotifyIsolateShutdown = 6
 
static constexpr int kRejectTag = 7
 

Protected Types

enum  State {
  kNotStarted , kStopped , kStarting , kStarted ,
  kStopping
}
 

Static Protected Member Functions

static void InitCallback (Isolate *I)
 
static void SetKernelIsolate (Isolate *isolate)
 
static void SetLoadPort (Dart_Port port)
 
static void FinishedExiting ()
 
static void FinishedInitializing ()
 
static void InitializingFailed ()
 
static Dart_IsolateGroupCreateCallback create_group_callback ()
 

Static Protected Attributes

static Dart_IsolateGroupCreateCallback create_group_callback_ = nullptr
 
static Monitormonitor_ = new Monitor()
 
static State state_ = KernelIsolate::kNotStarted
 
static Isolateisolate_ = nullptr
 
static Dart_Port kernel_port_ = ILLEGAL_PORT
 
static MallocGrowableArray< char * > * experimental_flags_
 

Friends

class Dart
 
class Isolate
 
class RunKernelTask
 

Detailed Description

Definition at line 22 of file kernel_isolate.h.

Member Enumeration Documentation

◆ State

Enumerator
kNotStarted 
kStopped 
kStarting 
kStarted 
kStopping 

Definition at line 115 of file kernel_isolate.h.

Member Function Documentation

◆ AcceptCompilation()

Dart_KernelCompilationResult dart::KernelIsolate::AcceptCompilation ( )
static

Definition at line 1139 of file kernel_isolate.cc.

1139 {
1140 // This must be the main script to be loaded. Wait for Kernel isolate
1141 // to finish initialization.
1142 Dart_Port kernel_port = WaitForKernelPort();
1143 if (kernel_port == ILLEGAL_PORT) {
1146 result.error = Utils::StrDup("Error while initializing Kernel isolate");
1147 return result;
1148 }
1149
1150 KernelCompilationRequest request;
1151 return request.SendAndWaitForResponse(
1152 kAcceptTag, kernel_port, nullptr, nullptr, 0, 0, nullptr, true, false,
1153 false, nullptr, nullptr, nullptr, experimental_flags_,
1155}
static Dart_Port WaitForKernelPort()
static constexpr int kAcceptTag
static MallocGrowableArray< char * > * experimental_flags_
static char * StrDup(const char *s)
@ Dart_KernelCompilationStatus_MsgFailed
Definition: dart_api.h:3788
#define ILLEGAL_PORT
Definition: dart_api.h:1535
int64_t Dart_Port
Definition: dart_api.h:1525
@ Dart_KernelCompilationVerbosityLevel_Error
Definition: dart_api.h:3799
GAsyncResult * result

◆ AddExperimentalFlag()

void dart::KernelIsolate::AddExperimentalFlag ( const char *  value)
static

Definition at line 371 of file kernel_isolate.cc.

371 {
372 char* save_ptr; // Needed for strtok_r.
373 char* temp = Utils::StrDup(value);
374 char* token = strtok_r(temp, ",", &save_ptr);
375 while (token != nullptr) {
377 token = strtok_r(nullptr, ",", &save_ptr);
378 }
379 free(temp);
380}
void Add(const T &value)
uint8_t value

◆ CompileExpressionToKernel()

Dart_KernelCompilationResult dart::KernelIsolate::CompileExpressionToKernel ( const uint8_t *  platform_kernel,
intptr_t  platform_kernel_size,
const char *  expression,
const Array definitions,
const Array definition_types,
const Array type_definitions,
const Array type_bounds,
const Array type_defaults,
const char *  library_url,
const char *  klass,
const char *  method,
TokenPosition  token_pos,
char const *  script_uri,
bool  is_static 
)
static

Definition at line 1175 of file kernel_isolate.cc.

1189 {
1190 Dart_Port kernel_port = WaitForKernelPort();
1191 if (kernel_port == ILLEGAL_PORT) {
1194 result.error = Utils::StrDup("Error while initializing Kernel isolate");
1195 return result;
1196 }
1197
1198 intptr_t token_pos_int = -1;
1199 if (token_pos.IsReal()) {
1200 token_pos_int = token_pos.Pos();
1201 }
1202
1203 TransitionVMToNative transition(Thread::Current());
1204 KernelCompilationRequest request;
1205 ASSERT(is_static || (klass != nullptr));
1206 return request.SendAndWaitForResponse(
1207 kernel_port, platform_kernel, platform_kernel_size, expression,
1208 definitions, definition_types, type_definitions, type_bounds,
1209 type_defaults, library_url, klass, method, token_pos_int, script_uri,
1210 is_static, experimental_flags_);
1211}
static Thread * Current()
Definition: thread.h:362
#define ASSERT(E)

◆ CompileToKernel()

Dart_KernelCompilationResult dart::KernelIsolate::CompileToKernel ( const char *  script_uri,
const uint8_t *  platform_kernel,
intptr_t  platform_kernel_size,
int  source_files_count = 0,
Dart_SourceFile  source_files[] = nullptr,
bool  incremental_compile = true,
bool  for_snapshot = false,
bool  embed_sources = true,
const char *  package_config = nullptr,
const char *  multiroot_filepaths = nullptr,
const char *  multiroot_scheme = nullptr,
Dart_KernelCompilationVerbosityLevel  verbosity = Dart_KernelCompilationVerbosityLevel_All 
)
static

Definition at line 1084 of file kernel_isolate.cc.

1096 {
1097 // Start the kernel Isolate if it is not already running.
1098 if (!Start()) {
1101 result.error = Utils::StrDup("Error while starting Kernel isolate task");
1102 return result;
1103 }
1104
1105 // This must be the main script to be loaded. Wait for Kernel isolate
1106 // to finish initialization.
1107 Dart_Port kernel_port = WaitForKernelPort();
1108 if (kernel_port == ILLEGAL_PORT) {
1111 result.error = Utils::StrDup("Error while initializing Kernel isolate");
1112 return result;
1113 }
1114
1115 KernelCompilationRequest request;
1116 return request.SendAndWaitForResponse(
1117 kCompileTag, kernel_port, script_uri, platform_kernel,
1118 platform_kernel_size, source_file_count, source_files,
1119 incremental_compile, for_snapshot, embed_sources, package_config,
1120 multiroot_filepaths, multiroot_scheme, experimental_flags_, verbosity);
1121}
static constexpr int kCompileTag
@ Dart_KernelCompilationStatus_Unknown
Definition: dart_api.h:3784

◆ create_group_callback()

static Dart_IsolateGroupCreateCallback dart::KernelIsolate::create_group_callback ( )
inlinestaticprotected

Definition at line 109 of file kernel_isolate.h.

109 {
111 }
static Dart_IsolateGroupCreateCallback create_group_callback_

◆ Exists()

bool dart::KernelIsolate::Exists ( )
static

Definition at line 282 of file kernel_isolate.cc.

282 {
283 MonitorLocker ml(monitor_);
284 return isolate_ != nullptr;
285}
static Monitor * monitor_
static Isolate * isolate_

◆ FinishedExiting()

void dart::KernelIsolate::FinishedExiting ( )
staticprotected

Definition at line 300 of file kernel_isolate.cc.

300 {
301 MonitorLocker ml(monitor_);
304 ml.NotifyAll();
305}

◆ FinishedInitializing()

void dart::KernelIsolate::FinishedInitializing ( )
staticprotected

Definition at line 307 of file kernel_isolate.cc.

307 {
308 MonitorLocker ml(monitor_);
311 ml.NotifyAll();
312}

◆ GetExperimentalFlag()

bool dart::KernelIsolate::GetExperimentalFlag ( ExperimentalFeature  feature)
static

Definition at line 382 of file kernel_isolate.cc.

382 {
383 const char* value = GetExperimentalFeatureName(feature);
384 for (const char* str : *experimental_flags_) {
385 if (strcmp(str, value) == 0) {
386 return true;
387 } else if (strstr(str, "no-") == str && strcmp(str + 3, value) == 0) {
388 return false;
389 }
390 }
391 return GetExperimentalFeatureDefault(feature);
392}
bool GetExperimentalFeatureDefault(ExperimentalFeature feature)
const char * GetExperimentalFeatureName(ExperimentalFeature feature)

◆ InitCallback()

void dart::KernelIsolate::InitCallback ( Isolate I)
staticprotected

Definition at line 261 of file kernel_isolate.cc.

261 {
262 Thread* T = Thread::Current();
263 ASSERT(I == T->isolate());
264 ASSERT(I != nullptr);
265 if (!I->is_kernel_isolate()) {
266 // Not kernel isolate.
267 return;
268 }
269 ASSERT(!Exists());
270 if (FLAG_trace_kernel) {
271 OS::PrintErr(DART_KERNEL_ISOLATE_NAME ": InitCallback for %s.\n",
272 I->name());
273 }
275}
static bool Exists()
static void SetKernelIsolate(Isolate *isolate)
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
#define DART_KERNEL_ISOLATE_NAME
Definition: dart_api.h:3880
#define T
Definition: precompiler.cc:65
Definition: SkMD5.cpp:134

◆ InitializeState()

void dart::KernelIsolate::InitializeState ( )
static

Definition at line 202 of file kernel_isolate.cc.

202 {
203 // Grab the isolate create callback here to avoid race conditions with tests
204 // that change this after Dart_Initialize returns.
205 if (FLAG_trace_kernel) {
206 OS::PrintErr(DART_KERNEL_ISOLATE_NAME ": InitializeState\n");
207 }
209 if (create_group_callback_ == nullptr) {
211 return;
212 }
213}
static Dart_IsolateGroupCreateCallback CreateGroupCallback()
Definition: isolate.h:1203
static void InitializingFailed()

◆ InitializingFailed()

void dart::KernelIsolate::InitializingFailed ( )
staticprotected

Definition at line 314 of file kernel_isolate.cc.

314 {
315 MonitorLocker ml(monitor_);
318 ml.NotifyAll();
319}

◆ IsRunning()

bool dart::KernelIsolate::IsRunning ( )
static

Definition at line 277 of file kernel_isolate.cc.

277 {
278 MonitorLocker ml(monitor_);
279 return (kernel_port_ != ILLEGAL_PORT) && (isolate_ != nullptr);
280}
static Dart_Port kernel_port_

◆ KernelPort()

static Dart_Port dart::KernelIsolate::KernelPort ( )
inlinestatic

Definition at line 55 of file kernel_isolate.h.

55{ return kernel_port_; }

◆ ListDependencies()

Dart_KernelCompilationResult dart::KernelIsolate::ListDependencies ( )
static

Definition at line 1123 of file kernel_isolate.cc.

1123 {
1124 Dart_Port kernel_port = WaitForKernelPort();
1125 if (kernel_port == ILLEGAL_PORT) {
1128 result.error = Utils::StrDup("Error while initializing Kernel isolate");
1129 return result;
1130 }
1131
1132 KernelCompilationRequest request;
1133 return request.SendAndWaitForResponse(
1134 kListDependenciesTag, kernel_port, nullptr, nullptr, 0, 0, nullptr, false,
1135 false, false, nullptr, nullptr, nullptr, experimental_flags_,
1137}
static constexpr int kListDependenciesTag

◆ NotifyAboutIsolateGroupShutdown()

void dart::KernelIsolate::NotifyAboutIsolateGroupShutdown ( const IsolateGroup isolate_group)
static

Definition at line 1233 of file kernel_isolate.cc.

1234 {
1235 if (!KernelIsolate::IsRunning()) {
1236 return;
1237 }
1238 Dart_Port kernel_port = WaitForKernelPort();
1239 if (kernel_port == ILLEGAL_PORT) {
1240 return;
1241 }
1242
1243 Dart_CObject tag;
1246
1247 Dart_CObject isolate_id;
1248 isolate_id.type = Dart_CObject_kInt64;
1249 isolate_id.value.as_int64 = static_cast<int64_t>(isolate_group->id());
1250
1253 Dart_CObject* message_arr[] = {&tag, &isolate_id};
1254 message.value.as_array.values = message_arr;
1255 message.value.as_array.length = ARRAY_SIZE(message_arr);
1256 // Send the message.
1257 Dart_PostCObject(kernel_port, &message);
1258}
static bool IsRunning()
static constexpr int kNotifyIsolateShutdown
@ Dart_CObject_kInt64
@ Dart_CObject_kArray
@ Dart_CObject_kInt32
Win32Message message
DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject *message)
union _Dart_CObject::@86 value
Dart_CObject_Type type
#define ARRAY_SIZE(array)
Definition: globals.h:72

◆ RejectCompilation()

Dart_KernelCompilationResult dart::KernelIsolate::RejectCompilation ( )
static

Definition at line 1157 of file kernel_isolate.cc.

1157 {
1158 // This must be the main script to be loaded. Wait for Kernel isolate
1159 // to finish initialization.
1160 Dart_Port kernel_port = WaitForKernelPort();
1161 if (kernel_port == ILLEGAL_PORT) {
1164 result.error = Utils::StrDup("Error while initializing Kernel isolate");
1165 return result;
1166 }
1167
1168 KernelCompilationRequest request;
1169 return request.SendAndWaitForResponse(
1170 kRejectTag, kernel_port, nullptr, nullptr, 0, 0, nullptr, true, false,
1171 false, nullptr, nullptr, nullptr, experimental_flags_,
1173}
static constexpr int kRejectTag

◆ SetKernelIsolate()

void dart::KernelIsolate::SetKernelIsolate ( Isolate isolate)
staticprotected

Definition at line 287 of file kernel_isolate.cc.

287 {
288 MonitorLocker ml(monitor_);
289 ASSERT(isolate == nullptr || isolate->is_kernel_isolate());
290 isolate_ = isolate;
291 ml.NotifyAll();
292}

◆ SetLoadPort()

void dart::KernelIsolate::SetLoadPort ( Dart_Port  port)
staticprotected

Definition at line 294 of file kernel_isolate.cc.

294 {
295 MonitorLocker ml(monitor_);
297 ml.NotifyAll();
298}
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service port
Definition: switches.h:87

◆ Shutdown()

void dart::KernelIsolate::Shutdown ( )
static

Definition at line 244 of file kernel_isolate.cc.

244 {
245 MonitorLocker ml(monitor_);
246 while (state_ == kStarting) {
247 ml.Wait();
248 }
249 if (state_ == kStopped || state_ == kNotStarted) {
250 return;
251 }
254 ml.NotifyAll();
256 while (state_ != kStopped) {
257 ml.Wait();
258 }
259}
@ kInternalKillMsg
Definition: isolate.h:973
static void KillIfExists(Isolate *isolate, LibMsgId msg_id)
Definition: isolate.cc:3706

◆ Start()

bool dart::KernelIsolate::Start ( )
static

Definition at line 215 of file kernel_isolate.cc.

215 {
216 if (create_group_callback_ == nullptr) {
217 if (FLAG_trace_kernel) {
219 ": Attempted to start kernel isolate without setting "
220 "Dart_InitializeParams property 'start_kernel_isolate' "
221 "to true\n");
222 }
223 return false;
224 }
225 bool start_task = false;
226 {
227 MonitorLocker ml(monitor_);
228 if (state_ == kNotStarted) {
229 if (FLAG_trace_kernel) {
231 }
232 start_task = true;
234 ml.NotifyAll();
235 }
236 }
237 bool task_started = true;
238 if (start_task) {
239 task_started = Dart::thread_pool()->Run<RunKernelTask>();
240 }
241 return task_started;
242}
static ThreadPool * thread_pool()
Definition: dart.h:73
friend class RunKernelTask
bool Run(Args &&... args)
Definition: thread_pool.h:45

◆ UpdateInMemorySources()

Dart_KernelCompilationResult dart::KernelIsolate::UpdateInMemorySources ( int  source_files_count,
Dart_SourceFile  source_files[] 
)
static

Definition at line 1213 of file kernel_isolate.cc.

1215 {
1216 // This must be the main script to be loaded. Wait for Kernel isolate
1217 // to finish initialization.
1218 Dart_Port kernel_port = WaitForKernelPort();
1219 if (kernel_port == ILLEGAL_PORT) {
1222 result.error = Utils::StrDup("Error while initializing Kernel isolate");
1223 return result;
1224 }
1225
1226 KernelCompilationRequest request;
1227 return request.SendAndWaitForResponse(
1228 kUpdateSourcesTag, kernel_port, nullptr, nullptr, 0, source_files_count,
1229 source_files, true, false, false, nullptr, nullptr, nullptr,
1231}
static constexpr int kUpdateSourcesTag

◆ WaitForKernelPort()

Dart_Port dart::KernelIsolate::WaitForKernelPort ( )
static

Definition at line 321 of file kernel_isolate.cc.

321 {
322 VMTagScope tagScope(Thread::Current(), VMTag::kLoadWaitTagId);
323 MonitorLocker ml(monitor_);
324 while (state_ == kStarting && (kernel_port_ == ILLEGAL_PORT)) {
325 ml.Wait();
326 }
327 return kernel_port_;
328}

Friends And Related Function Documentation

◆ Dart

friend class Dart
friend

Definition at line 141 of file kernel_isolate.h.

◆ Isolate

friend class Isolate
friend

Definition at line 142 of file kernel_isolate.h.

◆ RunKernelTask

friend class RunKernelTask
friend

Definition at line 143 of file kernel_isolate.h.

Member Data Documentation

◆ create_group_callback_

Dart_IsolateGroupCreateCallback dart::KernelIsolate::create_group_callback_ = nullptr
staticprotected

Definition at line 113 of file kernel_isolate.h.

◆ experimental_flags_

MallocGrowableArray< char * > * dart::KernelIsolate::experimental_flags_
staticprotected
Initial value:
=
new MallocGrowableArray<char*>()

Definition at line 126 of file kernel_isolate.h.

◆ isolate_

Isolate * dart::KernelIsolate::isolate_ = nullptr
staticprotected

Definition at line 123 of file kernel_isolate.h.

◆ kAcceptTag

constexpr int dart::KernelIsolate::kAcceptTag = 2
staticconstexpr

Definition at line 41 of file kernel_isolate.h.

◆ kCompileExpressionTag

constexpr int dart::KernelIsolate::kCompileExpressionTag = 4
staticconstexpr

Definition at line 43 of file kernel_isolate.h.

◆ kCompileTag

constexpr int dart::KernelIsolate::kCompileTag = 0
staticconstexpr

Definition at line 39 of file kernel_isolate.h.

◆ kernel_port_

Dart_Port dart::KernelIsolate::kernel_port_ = ILLEGAL_PORT
staticprotected

Definition at line 124 of file kernel_isolate.h.

◆ kListDependenciesTag

constexpr int dart::KernelIsolate::kListDependenciesTag = 5
staticconstexpr

Definition at line 44 of file kernel_isolate.h.

◆ kName

const char * dart::KernelIsolate::kName = DART_KERNEL_ISOLATE_NAME
static

Definition at line 26 of file kernel_isolate.h.

◆ kNotifyIsolateShutdown

constexpr int dart::KernelIsolate::kNotifyIsolateShutdown = 6
staticconstexpr

Definition at line 45 of file kernel_isolate.h.

◆ kRejectTag

constexpr int dart::KernelIsolate::kRejectTag = 7
staticconstexpr

Definition at line 46 of file kernel_isolate.h.

◆ kTrainTag

constexpr int dart::KernelIsolate::kTrainTag = 3
staticconstexpr

Definition at line 42 of file kernel_isolate.h.

◆ kUpdateSourcesTag

constexpr int dart::KernelIsolate::kUpdateSourcesTag = 1
staticconstexpr

Definition at line 40 of file kernel_isolate.h.

◆ monitor_

Monitor * dart::KernelIsolate::monitor_ = new Monitor()
staticprotected

Definition at line 114 of file kernel_isolate.h.

◆ state_

KernelIsolate::State dart::KernelIsolate::state_ = KernelIsolate::kNotStarted
staticprotected

Definition at line 122 of file kernel_isolate.h.


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