27#if !defined(DART_PRECOMPILED_RUNTIME)
33DEFINE_FLAG(
bool, trace_kernel,
false,
"Trace Kernel service requests.");
35 kernel_multiroot_filepaths,
37 "Comma-separated list of file paths that should be treated as roots"
38 " by frontend compiler.");
40 kernel_multiroot_scheme,
42 "URI scheme that replaces filepaths prefixes specified"
43 " by kernel_multiroot_filepaths option");
56#ifdef SUPPORT_TIMELINE
57 TimelineBeginEndScope tbes(Timeline::GetVMStream(),
"KernelIsolateStartup");
59 char*
error =
nullptr;
64 ASSERT(create_group_callback !=
nullptr);
74#if !defined(DART_PRECOMPILER)
77#if !defined(DART_PRECOMPILER)
81 isolate =
reinterpret_cast<Isolate*
>(
83 nullptr,
nullptr, &api_flags,
nullptr, &
error));
84 if (isolate ==
nullptr) {
85 if (FLAG_trace_kernel) {
110 ASSERT(isolate->is_kernel_isolate());
114 reinterpret_cast<uword>(isolate));
119 if (FLAG_trace_kernel) {
130 auto I =
T->isolate();
131 ASSERT(
I->is_kernel_isolate());
136 error =
T->sticky_error();
137 if (!
error.IsNull() && !
error.IsUnwindError()) {
139 error.ToErrorCString());
141 error =
I->sticky_error();
142 if (!
error.IsNull() && !
error.IsUnwindError()) {
144 error.ToErrorCString());
148 if (FLAG_trace_kernel) {
161 if (root_library.
IsNull()) {
163 ": Embedder did not install a script.");
175 ": Embedder did not provide a main function.");
184 if (FLAG_trace_kernel) {
187 ": Calling main resulted in an error: %s",
188 error.ToErrorCString());
190 if (
result.IsUnwindError()) {
205 if (FLAG_trace_kernel) {
217 if (FLAG_trace_kernel) {
219 ": Attempted to start kernel isolate without setting "
220 "Dart_InitializeParams property 'start_kernel_isolate' "
225 bool start_task =
false;
229 if (FLAG_trace_kernel) {
237 bool task_started =
true;
265 if (!
I->is_kernel_isolate()) {
270 if (FLAG_trace_kernel) {
289 ASSERT(isolate ==
nullptr || isolate->is_kernel_isolate());
337 for (
int i = 0;
i < source_files_count;
i++) {
341 fileNamePairs[
i * 2] = source_uri;
344 if (source_files[
i].
source !=
nullptr) {
349 reinterpret_cast<const uint8_t*
>(source_files[
i].
source);
353 fileNamePairs[(
i * 2) + 1] = source_code;
369 new MallocGrowableArray<char*>();
374 char* token = strtok_r(temp,
",", &save_ptr);
375 while (token !=
nullptr) {
377 token = strtok_r(
nullptr,
",", &save_ptr);
385 if (strcmp(str,
value) == 0) {
387 }
else if (strstr(str,
"no-") == str && strcmp(str + 3,
value) == 0) {
396 "Comma separated list of experimental features.");
407 RegisterRequest(
this);
409 result_.
error =
nullptr;
415 UnregisterRequest(
this);
432 const_cast<uint8_t*
>(
buffer);
434 const_cast<uint8_t*
>(
buffer);
444 const uint8_t* platform_kernel,
445 intptr_t platform_kernel_size,
446 const char* expression,
447 const Array& definitions,
448 const Array& definition_types,
449 const Array& type_definitions,
450 const Array& type_bounds,
451 const Array& type_defaults,
452 char const* library_uri,
456 char const* script_uri,
463 Utils::StrDup(
"Error Kernel Isolate : unable to create reply port");
478 if (platform_kernel !=
nullptr) {
483 platform_kernel_size;
485 const_cast<uint8_t*
>(platform_kernel);
487 const_cast<uint8_t*
>(platform_kernel);
498 expression_object.
value.
as_string =
const_cast<char*
>(expression);
501 intptr_t num_definitions = definitions.
Length();
506 for (intptr_t
i = 0;
i < num_definitions; ++
i) {
510 String::CheckedHandle(thread->
zone(), definitions.
At(
i)).ToCString());
515 intptr_t num_definition_types = definition_types.
Length();
521 for (intptr_t
i = 0;
i < num_definition_types; ++
i) {
525 String::CheckedHandle(thread->
zone(), definition_types.
At(
i))
531 intptr_t num_type_definitions = type_definitions.
Length();
537 for (intptr_t
i = 0;
i < num_type_definitions; ++
i) {
541 String::CheckedHandle(thread->
zone(), type_definitions.
At(
i))
547 intptr_t num_type_bounds = type_bounds.
Length();
552 for (intptr_t
i = 0;
i < num_type_bounds; ++
i) {
556 String::CheckedHandle(thread->
zone(), type_bounds.
At(
i)).ToCString());
561 intptr_t num_type_defaults = type_defaults.
Length();
566 for (intptr_t
i = 0;
i < num_type_defaults; ++
i) {
570 String::CheckedHandle(thread->
zone(), type_defaults.
At(
i))
577 library_uri_object.
value.
as_string =
const_cast<char*
>(library_uri);
580 if (klass !=
nullptr) {
588 if (method !=
nullptr) {
604 if (script_uri !=
nullptr) {
606 script_uri_object.
value.
as_string =
const_cast<char*
>(script_uri);
612 auto source = isolate_group->source();
616 isolate_id.
value.
as_int64 =
static_cast<int64_t
>(isolate_group->id());
618 intptr_t num_dills = 0;
619 if (
source->kernel_buffer !=
nullptr) {
622 if (
source->script_kernel_buffer !=
nullptr) {
626 if (
source->loaded_blobs_ !=
nullptr) {
627 loaded_blobs =
source->loaded_blobs_;
629 for (intptr_t
i = 0;
i < loaded_blobs.
Length();
i++) {
630 weak_property ^= loaded_blobs.
At(
i);
642 intptr_t dill_num = 0;
644 source->kernel_buffer_size);
646 source->script_kernel_size);
647 if (!loaded_blobs.
IsNull()) {
649 for (intptr_t
i = 0;
i < loaded_blobs.
Length();
i++) {
650 weak_property ^= loaded_blobs.
At(
i);
655 const uint8_t*
data =
const_cast<uint8_t*
>(
656 reinterpret_cast<uint8_t*
>(externalTypedData.
DataAddr(0)));
658 externalTypedData.
Length());
670 enable_asserts.
value.
as_bool = isolate_group->asserts();
672 intptr_t num_experimental_flags = experimental_flags->
length();
675 for (intptr_t
i = 0;
i < num_experimental_flags; ++
i) {
694 &dart_platform_kernel,
697 &definition_types_object,
698 &type_definitions_object,
700 &type_defaults_object,
710 &experimental_flags_object,
712 message.value.as_array.values = message_arr;
722 VMTagScope tagScope(thread, VMTag::kLoadWaitTagId);
729 for (intptr_t
i = 0;
i < num_definitions; ++
i) {
730 delete definitions_array[
i];
732 delete[] definitions_array;
734 for (intptr_t
i = 0;
i < num_definition_types; ++
i) {
735 delete definition_types_array[
i];
737 delete[] definition_types_array;
739 for (intptr_t
i = 0;
i < num_type_definitions; ++
i) {
740 delete type_definitions_array[
i];
742 delete[] type_definitions_array;
744 for (intptr_t
i = 0;
i < num_type_bounds; ++
i) {
745 delete type_bounds_array[
i];
747 delete[] type_bounds_array;
749 for (intptr_t
i = 0;
i < num_type_defaults; ++
i) {
750 delete type_defaults_array[
i];
752 delete[] type_defaults_array;
754 for (intptr_t
i = 0;
i < num_dills; ++
i) {
755 delete dills_array[
i];
757 delete[] dills_array;
759 for (intptr_t
i = 0;
i < num_experimental_flags; ++
i) {
760 delete experimental_flags_array[
i];
762 delete[] experimental_flags_array;
770 const char* script_uri,
771 const uint8_t* platform_kernel,
772 intptr_t platform_kernel_size,
773 int source_files_count,
775 bool incremental_compile,
778 const char* package_config,
779 const char* multiroot_filepaths,
780 const char* multiroot_scheme,
789 Utils::StrDup(
"Error Kernel Isolate : unable to create reply port");
802 if (script_uri !=
nullptr) {
810 if (platform_kernel !=
nullptr) {
815 platform_kernel_size;
817 const_cast<uint8_t*
>(platform_kernel);
819 const_cast<uint8_t*
>(platform_kernel);
844 auto isolate_group = thread !=
nullptr ? thread->isolate_group() :
nullptr;
846 if (incremental_compile) {
847 ASSERT(isolate_group !=
nullptr);
852 ?
static_cast<int64_t
>(isolate_group->id())
863 ? isolate_group->asserts()
864 : FLAG_enable_asserts;
866 intptr_t num_experimental_flags = experimental_flags->
length();
869 for (intptr_t
i = 0;
i < num_experimental_flags; ++
i) {
880 if (package_config !=
nullptr) {
882 package_config_uri.
value.
as_string =
const_cast<char*
>(package_config);
889 const char* filepaths = multiroot_filepaths !=
nullptr
890 ? multiroot_filepaths
891 : FLAG_kernel_multiroot_filepaths;
892 if (filepaths !=
nullptr) {
895 const_cast<char*
>(filepaths);
903 const char* scheme = multiroot_scheme !=
nullptr
905 : FLAG_kernel_multiroot_scheme;
906 if (scheme !=
nullptr) {
908 multiroot_scheme_object.
value.
as_string =
const_cast<char*
>(scheme);
917 const_cast<char*
>(KernelCompilationVerbosityLevelToString(verbosity));
926 &dart_platform_kernel,
933 &experimental_flags_object,
935 &multiroot_filepaths_object,
936 &multiroot_scheme_object,
939 message.value.as_array.values = message_arr;
953 for (intptr_t
i = 0;
i < num_experimental_flags; ++
i) {
954 delete experimental_flags_array[
i];
956 delete[] experimental_flags_array;
988 MonitorLocker ml(&monitor_);
992 message->value.as_array.values[0]->value.as_int32);
995 LoadKernelFromResponse(response[1]);
998 LoadKernelFromResponse(response[2]);
1008 MonitorLocker locker(requests_monitor_);
1010 if (rq ==
nullptr) {
1013 rq->HandleResponseImpl(
message);
1017 MonitorLocker locker(requests_monitor_);
1018 rq->next_ = requests_;
1019 if (requests_ !=
nullptr) {
1020 requests_->prev_ = rq;
1026 MonitorLocker locker(requests_monitor_);
1027 if (rq->next_ !=
nullptr) {
1028 rq->next_->prev_ = rq->prev_;
1030 if (rq->prev_ !=
nullptr) {
1031 rq->prev_->next_ = rq->next_;
1033 requests_ = rq->next_;
1041 if (rq->port_ ==
port) {
1048 static const char* KernelCompilationVerbosityLevelToString(
1050 switch (verbosity) {
1065 static Monitor* requests_monitor_;
1081Monitor* KernelCompilationRequest::requests_monitor_ =
new Monitor();
1082KernelCompilationRequest* KernelCompilationRequest::requests_ =
nullptr;
1085 const char* script_uri,
1086 const uint8_t* platform_kernel,
1087 intptr_t platform_kernel_size,
1088 int source_file_count,
1090 bool incremental_compile,
1093 const char* package_config,
1094 const char* multiroot_filepaths,
1095 const char* multiroot_scheme,
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,
1152 kAcceptTag, kernel_port,
nullptr,
nullptr, 0, 0,
nullptr,
true,
false,
1170 kRejectTag, kernel_port,
nullptr,
nullptr, 0, 0,
nullptr,
true,
false,
1176 const uint8_t* platform_kernel,
1177 intptr_t platform_kernel_size,
1178 const char* expression,
1179 const Array& definitions,
1180 const Array& definition_types,
1181 const Array& type_definitions,
1182 const Array& type_bounds,
1183 const Array& type_defaults,
1184 const char* library_url,
1188 const char* script_uri,
1198 intptr_t token_pos_int = -1;
1199 if (token_pos.
IsReal()) {
1200 token_pos_int = token_pos.
Pos();
1205 ASSERT(is_static || (klass !=
nullptr));
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,
1214 int source_files_count,
1229 source_files,
true,
false,
false,
nullptr,
nullptr,
nullptr,
1249 isolate_id.
value.
as_int64 =
static_cast<int64_t
>(isolate_group->
id());
1254 message.value.as_array.values = message_arr;
static uint32_t buffer_size(uint32_t offset, uint32_t maxAlignment)
ObjectPtr At(intptr_t index) const
static ObjectPtr InvokeFunction(const Function &function, const Array &arguments)
static ThreadPool * thread_pool()
MutatorThreadPool * thread_pool()
static Isolate * Current()
static void KillIfExists(Isolate *isolate, LibMsgId msg_id)
MessageHandler * message_handler() const
static void FlagsInitialize(Dart_IsolateFlags *api_flags)
IsolateGroup * group() const
static Dart_IsolateGroupCreateCallback CreateGroupCallback()
KernelCompilationRequest()
~KernelCompilationRequest()
Dart_KernelCompilationResult SendAndWaitForResponse(Dart_Port kernel_port, 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, char const *library_uri, char const *klass, char const *method, int64_t token_pos, char const *script_uri, bool is_static, const MallocGrowableArray< char * > *experimental_flags)
intptr_t setDillData(Dart_CObject **dills_array, intptr_t dill_num, const uint8_t *buffer, intptr_t buffer_size)
Dart_KernelCompilationResult SendAndWaitForResponse(int request_tag, Dart_Port kernel_port, const char *script_uri, const uint8_t *platform_kernel, intptr_t platform_kernel_size, int source_files_count, Dart_SourceFile source_files[], bool incremental_compile, bool for_snapshot, bool embed_sources, const char *package_config, const char *multiroot_filepaths, const char *multiroot_scheme, const MallocGrowableArray< char * > *experimental_flags, Dart_KernelCompilationVerbosityLevel verbosity)
static constexpr int kListDependenciesTag
static constexpr int kCompileExpressionTag
static void InitializingFailed()
static void SetLoadPort(Dart_Port port)
static void FinishedExiting()
static Dart_KernelCompilationResult ListDependencies()
static Dart_IsolateGroupCreateCallback create_group_callback_
static Dart_KernelCompilationResult UpdateInMemorySources(int source_files_count, Dart_SourceFile source_files[])
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 void InitializeState()
static constexpr int kNotifyIsolateShutdown
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 void NotifyAboutIsolateGroupShutdown(const IsolateGroup *isolate_group)
static Dart_Port WaitForKernelPort()
static constexpr int kUpdateSourcesTag
static void FinishedInitializing()
static Dart_KernelCompilationResult RejectCompilation()
static void AddExperimentalFlag(const char *value)
static constexpr int kAcceptTag
static Monitor * monitor_
static Dart_KernelCompilationResult AcceptCompilation()
static bool GetExperimentalFlag(ExperimentalFeature feature)
static void InitCallback(Isolate *I)
static Dart_Port kernel_port_
static Dart_IsolateGroupCreateCallback create_group_callback()
static void SetKernelIsolate(Isolate *isolate)
static Isolate * isolate_
static constexpr int kCompileTag
static const char * kName
static MallocGrowableArray< char * > * experimental_flags_
static constexpr int kRejectTag
FunctionPtr LookupFunctionAllowPrivate(const String &name) const
bool Run(ThreadPool *pool, StartCallback start_callback, EndCallback end_callback, CallbackData data)
Monitor::WaitResult Wait(int64_t millis=Monitor::kNoTimeout)
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static ObjectPtr RawCast(ObjectPtr obj)
static void ShutdownIsolate(uword parameter)
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
bool Run(Args &&... args)
static Thread * Current()
IsolateGroup * isolate_group() const
void * DataAddr(intptr_t byte_offset) const
static char * StrDup(const char *s)
Dart_Isolate(* Dart_IsolateGroupCreateCallback)(const char *script_uri, const char *main, const char *package_root, const char *package_config, Dart_IsolateFlags *flags, void *isolate_data, char **error)
Dart_KernelCompilationStatus
@ Dart_KernelCompilationStatus_MsgFailed
@ Dart_KernelCompilationStatus_Error
@ Dart_KernelCompilationStatus_Unknown
@ Dart_KernelCompilationStatus_Ok
#define DART_KERNEL_ISOLATE_NAME
struct _Dart_Isolate * Dart_Isolate
Dart_KernelCompilationVerbosityLevel
@ Dart_KernelCompilationVerbosityLevel_Error
@ Dart_KernelCompilationVerbosityLevel_Warning
@ Dart_KernelCompilationVerbosityLevel_All
@ Dart_KernelCompilationVerbosityLevel_Info
@ Dart_CObject_kTypedData
@ Dart_CObject_kExternalTypedData
struct _Dart_CObject Dart_CObject
const uint8_t uint32_t uint32_t GError ** error
static Dart_CObject BuildFilesPairs(int source_files_count, Dart_SourceFile source_files[])
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
bool GetExperimentalFeatureDefault(ExperimentalFeature feature)
static void PassThroughFinalizer(void *isolate_callback_data, void *peer)
void * malloc(size_t size)
DEFINE_OPTION_HANDLER(CompilerPass::ParseFiltersFromFlag, compiler_passes, "List of comma separated compilation passes flags. " "Use -Name to disable a pass, Name to print IL after it. " "Do --compiler-passes=help for more information.")
const char * GetExperimentalFeatureName(ExperimentalFeature feature)
DEFINE_FLAG(bool, print_cluster_information, false, "Print information about clusters written to snapshot")
DART_EXPORT bool Dart_CloseNativePort(Dart_Port native_port_id)
static void ReleaseFilesPairs(const Dart_CObject &files)
DART_EXPORT Dart_Port Dart_NewNativePort(const char *name, Dart_NativeMessageHandler handler, bool handle_concurrently)
DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject *message)
static int8_t data[kExtLength]
DART_EXPORT void Dart_ShutdownIsolate()
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
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 A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
Dart_KernelCompilationStatus status
struct _Dart_CObject::@86::@87 as_send_port
Dart_HandleFinalizer callback
union _Dart_CObject::@86 value
struct _Dart_CObject::@86::@90 as_typed_data
struct _Dart_CObject::@86::@91 as_external_typed_data
struct _Dart_CObject::@86::@89 as_array
struct _Dart_CObject ** values
#define ARRAY_SIZE(array)