36 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
41 uint64_t
id = isolate->random()->NextJSInt();
53 int64_t
id = cap.Id();
54 int32_t hi =
static_cast<int32_t
>(
id >> 32);
55 int32_t lo =
static_cast<int32_t
>(
id);
62 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
64 return isolate->CreateReceivePort(debug_name);
75 isolate->CloseReceivePort(
port);
82 isolate->SetReceivePortKeepAliveState(
port, active.value());
98 int64_t
id =
port.Id();
99 int32_t hi =
static_cast<int32_t
>(
id >> 32);
100 int32_t lo =
static_cast<int32_t
>(
id);
135 static const char*
Name() {
return "UntaggedObjectPtrSetTraits"; }
154 working_set_(working_set) {}
160 if (visited_->GetValueExclusive(obj) == 1) {
163 visited_->SetValueExclusive(obj, 1);
164 working_set_->Add(obj);
169 for (
ObjectPtr* ptr = from; ptr <= to; ptr++) {
174#if defined(DART_COMPRESSED_POINTERS)
175 void VisitCompressedPointers(
uword heap_base,
179 VisitObject(ptr->Decompress(heap_base));
196 const char* exception_message =
nullptr;
209 std::unique_ptr<WeakTable> visited(
new WeakTable());
211 SendMessageValidator visitor(isolate->
group(), visited.get(), working_set);
213 visited->SetValueExclusive(obj.
ptr(), 1);
214 working_set->
Add(obj.
ptr());
216 while (!working_set->
is_empty() && (exception_message ==
nullptr)) {
228 for (intptr_t
i = 0;
i < array.
Length(); ++
i) {
230 visitor.VisitObject(ptr);
243#define MESSAGE_SNAPSHOT_ILLEGAL(type) \
245 illegal_object = raw; \
246 exception_message = "is a " #type; \
260 klass = class_table->
At(
cid);
262 illegal_object = raw;
264 "is unsendable object (see restrictions listed at"
265 "`SendPort.send()` documentation for more information)";
272 ASSERT((exception_message ==
nullptr) == illegal_object.
IsNull());
273 if (exception_message !=
nullptr) {
274 working_set->
Clear();
277 args.SetAt(0, illegal_object);
282 zone, isolate, obj, illegal_object,
284 exception_message)));
299 if (!
port.IsNull()) {
312 "for isolates in one isolate group."));
326 msg_array.
SetAt(0, msg_obj);
327 if (validated_result.IsUnhandledException()) {
332 isolate->group()->api_state()->AllocatePersistentHandle();
334 isolate->bequeath(std::unique_ptr<Bequest>(
new Bequest(handle,
port.Id())));
341 error.set_is_user_initiated(
true);
386 return closure_tuple_handle_ ==
nullptr;
392 return closure_tuple_handle_;
407 const char* script_url_;
408 const char* package_config_;
409 const char* debug_name_;
412 std::unique_ptr<Message> serialized_args_;
413 std::unique_ptr<Message> serialized_message_;
417 bool errors_are_fatal_;
421 size_t len = strlen(chars);
422 char* mem =
new char[
len + 1];
423 memmove(mem, chars,
len + 1);
429 const char* script_url,
432 const char* package_config,
434 bool errors_are_fatal,
437 const char* debug_name,
439 : parent_port_(parent_port),
440 origin_id_(origin_id),
441 on_exit_port_(on_exit_port),
442 on_error_port_(on_error_port),
443 script_url_(script_url),
444 package_config_(package_config),
445 debug_name_(debug_name),
446 closure_tuple_handle_(closure_tuple_handle),
447 isolate_group_(isolate_group),
448 serialized_args_(nullptr),
449 serialized_message_(message_buffer->StealMessage()),
451 errors_are_fatal_(errors_are_fatal) {
452 ASSERT(closure_tuple_handle_ !=
nullptr);
455 auto isolate = thread->isolate();
462 const char* script_url,
463 const char* package_config,
467 bool errors_are_fatal,
470 const char* debug_name,
472 : parent_port_(parent_port),
473 on_exit_port_(on_exit_port),
474 on_error_port_(on_error_port),
475 script_url_(script_url),
476 package_config_(package_config),
477 debug_name_(debug_name),
478 isolate_group_(isolate_group),
479 serialized_args_(args_buffer->StealMessage()),
480 serialized_message_(message_buffer->StealMessage()),
483 errors_are_fatal_(errors_are_fatal) {
484 if (debug_name_ ==
nullptr) {
494 delete[] script_url_;
495 delete[] package_config_;
496 delete[] debug_name_;
513 if (obj.IsFunction()) {
521 "Unable to resolve function 'main' in script '%s'.",
script_url()));
522 return LanguageError::New(msg);
541 serialized_args_.reset();
548 serialized_message_.reset();
561 std::unique_ptr<IsolateSpawnState>
state)
562 : parent_isolate_(parent_isolate), state_(
std::move(
state)) {
567 if (parent_isolate_ !=
nullptr) {
573 const char*
name = state_->debug_name();
576 auto group = state_->isolate_group();
577 if (
group ==
nullptr) {
588 if (create_group_callback ==
nullptr) {
589 FailedSpawn(
"Isolate spawn is not supported by this Dart embedder\n");
593 char*
error =
nullptr;
611 const bool is_parent_main_isolate =
612 strcmp(parent_isolate_->
name(),
"main") == 0;
616 (create_group_callback)(state_->script_url(),
name,
nullptr,
617 state_->package_config(), &api_flags,
620 parent_isolate_ =
nullptr;
622 if (isolate ==
nullptr) {
623 FailedSpawn(
error,
false);
634 if (initialize_callback ==
nullptr) {
636 "Lightweight isolate spawn is not supported by this Dart embedder\n",
641 char*
error =
nullptr;
643 auto group = state_->isolate_group();
646 parent_isolate_ =
nullptr;
648 if (isolate ==
nullptr) {
649 FailedSpawn(
error,
false);
654 void* child_isolate_data =
nullptr;
655 const bool success = initialize_callback(&child_isolate_data, &
error);
669 if (!EnsureIsRunnable(child)) {
674 state_->set_isolate(child);
684 TransitionNativeToVM transition(thread);
685 StackZone zone(thread);
686 HandleScope hs(thread);
688 success = EnqueueEntrypointInvocationAndNotifySpawner(thread);
698 char*
error =
nullptr;
700 state_->on_exit_port(), &
error)) {
701 FATAL(
"Dart_RunLoopAsync() failed: %s. Please file a Dart VM bug report.",
706 bool EnsureIsRunnable(Isolate* child) {
711 if (!child->is_runnable()) {
712 const char*
error = child->MakeRunnable();
713 if (
error !=
nullptr) {
718 ASSERT(child->is_runnable());
722 bool EnqueueEntrypointInvocationAndNotifySpawner(Thread* thread) {
723 auto isolate = thread->isolate();
724 auto zone = thread->zone();
725 const bool is_spawn_uri = state_->is_spawn_uri();
729 if (state_->closure_tuple_handle() !=
nullptr) {
735 "Failed to deserialize the passed entrypoint to the new isolate.");
743 ReportError(
"Failed to resolve entrypoint function.");
748 func = func.ImplicitClosureFunction();
749 entrypoint_closure = func.ImplicitStaticClosure();
753 const auto& args_obj =
Object::Handle(zone, state_->BuildArgs(thread));
754 if (args_obj.IsError()) {
756 "Failed to deserialize the passed arguments to the new isolate.");
759 ASSERT(args_obj.IsNull() || args_obj.IsInstance());
760 const auto& message_obj =
762 if (message_obj.IsError()) {
764 "Failed to deserialize the passed arguments to the new isolate.");
767 ASSERT(message_obj.IsNull() || message_obj.IsInstance());
769 args.SetAt(0, entrypoint_closure);
770 args.SetAt(1, args_obj);
771 args.SetAt(2, message_obj);
776 const auto& entry_point =
778 ASSERT(entry_point.IsFunction() && !entry_point.IsNull());
782 ReportError(
"Failed to enqueue delayed entrypoint invocation.");
791 capabilities.SetAt(0, capability);
793 capabilities.SetAt(1, capability);
794 const auto& send_port =
798 message.SetAt(1, capabilities);
799 if (state_->paused()) {
800 capability ^= capabilities.At(0);
801 const bool added = isolate->AddResumeCapability(capability);
803 isolate->message_handler()->increment_paused();
808 state_->parent_port(),
815 void FailedSpawn(
const char*
error,
bool has_current_isolate =
true) {
816 ReportError(
error !=
nullptr
818 :
"Unknown error occurred during Isolate spawning.");
822 if (has_current_isolate) {
825 }
else if (state_->isolate_group() !=
nullptr) {
827 const bool kBypassSafepoint =
false;
840 void ReportError(
const char*
error) {
850 Isolate* parent_isolate_;
851 std::unique_ptr<IsolateSpawnState> state_;
882 ASSERT(closure_copy_tuple.IsArray());
884 Object::Handle(zone, Array::Cast(closure_copy_tuple).At(0)).IsClosure());
885 closure_tuple_handle =
886 isolate->group()->api_state()->AllocatePersistentHandle();
887 closure_tuple_handle->
set_ptr(closure_copy_tuple.ptr());
889 bool fatal_errors = fatalErrors.IsNull() ?
true : fatalErrors.value();
899 const char* utf8_package_config =
900 packageConfig.IsNull() ? nullptr :
String2UTF8(packageConfig);
901 const char* utf8_debug_name =
902 debugName.IsNull() ? nullptr :
String2UTF8(debugName);
903 if (closure_tuple_handle !=
nullptr && utf8_debug_name ==
nullptr) {
906 NewConstChar(closure_function.QualifiedUserVisibleNameCString());
911 closure_tuple_handle, &message_buffer, utf8_package_config,
912 paused.value(), fatal_errors, on_exit_port, on_error_port,
913 utf8_debug_name, isolate->group()));
924 const char*
result =
nullptr;
927 if (isolate_group->HasTagHandler()) {
930 if (obj.IsString()) {
932 }
else if (obj.IsError()) {
934 error_obj ^= obj.
ptr();
939 "Unable to canonicalize uri '%s': "
940 "library tag handler returned wrong type",
945 "Unable to canonicalize uri '%s': no library tag handler found.",
965 bool fatal_errors = fatalErrors.IsNull() ?
true : fatalErrors.value();
985 char*
error =
nullptr;
987 if (canonical_uri ==
nullptr) {
992 const char* utf8_package_config =
993 packageConfig.IsNull() ? nullptr :
String2UTF8(packageConfig);
994 const char* utf8_debug_name =
995 debugName.IsNull() ? nullptr :
String2UTF8(debugName);
998 port.Id(), canonical_uri, utf8_package_config, &arguments_buffer,
999 &message_buffer, paused.value(), fatal_errors, on_exit_port,
1000 on_error_port, utf8_debug_name,
nullptr));
1004 if (!checked.IsNull()) {
1006 flags->enable_asserts = checked.value();
1017 if (
name ==
nullptr) {
1035 Library::Handle(zone, isolate->group()->object_store()->root_library());
1036 return root_lib.
url();
1041 arguments->NativeArgAt(0));
1043 if (register_kernel_blob_callback ==
nullptr) {
1045 "Registration of kernel blobs is not supported by this Dart embedder.");
1047 bool is_kernel =
false;
1051 Dart_IsKernel(
reinterpret_cast<uint8_t*
>(kernel_blob.DataAddr(0)),
1052 kernel_blob.LengthInBytes());
1056 zone,
String::New(
"kernelBlob doesn\'t contain a valid kernel.\n"));
1060 const char* uri =
nullptr;
1063 uri = register_kernel_blob_callback(
1064 reinterpret_cast<uint8_t*
>(kernel_blob.DataAddr(0)),
1065 kernel_blob.LengthInBytes());
1067 if (uri ==
nullptr) {
1075 arguments->NativeArgAt(0));
1076 auto unregister_kernel_blob_callback =
1078 if (unregister_kernel_blob_callback ==
nullptr) {
1080 "Registration of kernel blobs is not supported by this Dart embedder.");
1082 unregister_kernel_blob_callback(kernel_blob_uri.ToCString());
1103 if (!
error.IsNull()) {
1120 return TypedDataBase::Cast(
instance).LengthInBytes();
1130 TypeArguments::CheckedHandle(zone, arguments->NativeArgAt(0)).IsNull());
1133 arguments->NativeArgAt(1));
1136 intptr_t array_length;
1137 if (array_instance.IsGrowableObjectArray()) {
1138 const auto& growable_array = GrowableObjectArray::Cast(array_instance);
1139 array ^= growable_array.data();
1140 array_length = growable_array.
Length();
1141 }
else if (array_instance.IsArray()) {
1142 array ^= Array::Cast(array_instance).
ptr();
1143 array_length = array.
Length();
1149 uint64_t total_bytes = 0;
1151 for (intptr_t
i = 0;
i < array_length;
i++) {
1154 if (total_bytes > kMaxBytes) {
1156 error_args.
SetAt(0, array);
1160 "Aggregated list exceeds max size %" Pu64 "", kMaxBytes)));
1166 uint8_t*
data =
reinterpret_cast<uint8_t*
>(
::malloc(total_bytes));
1167 if (
data ==
nullptr) {
1169 thread->isolate_group()->object_store()->out_of_memory());
1174 for (intptr_t
i = 0;
i < array_length;
i++) {
1179 const auto& typed_data = TypedDataBase::Cast(
instance);
1180 const intptr_t length_in_bytes = typed_data.LengthInBytes();
1182 void*
source = typed_data.DataAddr(0);
1185 offset += length_in_bytes;
1194 arguments->NativeArgAt(0));
1199 peer = thread->heap()->GetPeer(t.ptr());
1208 if (
data ==
nullptr) {
1210 "Attempt to materialize object that was transferred already."));
1219 thread->heap()->SpaceForExternal(
length)));
1225 ASSERT(finalizable_ref !=
nullptr);
1226 return typed_data.
ptr();
static uint32_t hash(const SkShaderBase::GradientInfo &v)
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
virtual TypeArgumentsPtr GetTypeArguments() const
ObjectPtr At(intptr_t index) const
void SetAt(intptr_t index, const Object &value) const
static const Bool & False()
static const Bool & Get(bool value)
static const Bool & True()
static CapabilityPtr New(uint64_t id, Heap::Space space=Heap::kNew)
ClassPtr At(intptr_t cid) const
bool is_isolate_unsendable() const
static ObjectPtr InvokeFunction(const Function &function, const Array &arguments)
virtual const char * ToErrorCString() const
static DART_NORETURN void ThrowByType(ExceptionType type, const Array &arguments)
static DART_NORETURN void ThrowOOM()
static DART_NORETURN void ThrowUnsupportedError(const char *msg)
static DART_NORETURN void Throw(Thread *thread, const Instance &exception)
static DART_NORETURN void ThrowArgumentError(const Instance &arg)
static ObjectPtr Create(ExceptionType type, const Array &arguments)
static DART_NORETURN void PropagateError(const Error &error)
static ExternalTypedDataPtr New(intptr_t class_id, uint8_t *data, intptr_t len, Heap::Space space=Heap::kNew, bool perform_eager_msan_initialization_check=true)
static FinalizablePersistentHandle * New(IsolateGroup *isolate_group, const Object &object, void *peer, Dart_HandleFinalizer callback, intptr_t external_size, bool auto_delete)
void EnsureFreedExternal(IsolateGroup *isolate_group)
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
static IsolateGroup * Current()
ClassTable * class_table() const
const char * script_url() const
Dart_Port parent_port() const
void set_isolate(Isolate *value)
const char * debug_name() const
PersistentHandle * closure_tuple_handle() const
Dart_Port on_error_port() const
const char * package_config() const
bool is_spawn_uri() const
ObjectPtr ResolveFunction()
IsolateSpawnState(Dart_Port parent_port, Dart_Port origin_id, const char *script_url, PersistentHandle *closure_tuple_handle, SerializedObjectBuffer *message_buffer, const char *package_config, bool paused, bool errorsAreFatal, Dart_Port onExit, Dart_Port onError, const char *debug_name, IsolateGroup *group)
IsolateGroup * isolate_group() const
ObjectPtr BuildArgs(Thread *thread)
Dart_IsolateFlags * isolate_flags()
Dart_Port origin_id() const
ObjectPtr BuildMessage(Thread *thread)
bool errors_are_fatal() const
Isolate * isolate() const
Dart_Port on_exit_port() const
static Isolate * Current()
void FlagsCopyTo(Dart_IsolateFlags *api_flags) const
MallocGrowableArray< ObjectPtr > * pointers_to_verify_at_exit()
void DecrementSpawnCount()
static std::unique_ptr< char[]> LookupIsolateNameByPort(Dart_Port port)
void * init_callback_data() const
void set_forward_table_new(WeakTable *table)
IsolateGroup * group() const
static Dart_IsolateGroupCreateCallback CreateGroupCallback()
void set_init_callback_data(void *value)
static Dart_UnregisterKernelBlobCallback UnregisterKernelBlobCallback()
static Dart_InitializeIsolateCallback InitializeCallback()
void IncrementSpawnCount()
void set_origin_id(Dart_Port id)
static Dart_RegisterKernelBlobCallback RegisterKernelBlobCallback()
const char * name() const
ObjectPtr LookupReExport(const String &name, ZoneGrowableArray< intptr_t > *visited=nullptr) const
static LibraryPtr IsolateLibrary()
FunctionPtr LookupFunctionAllowPrivate(const String &name) const
UntaggedObject * untag() const
intptr_t GetClassId() const
static ObjectPtr RawCast(ObjectPtr obj)
void set_ptr(ObjectPtr ref)
static bool PostMessage(std::unique_ptr< Message > message, bool before_events=false)
static bool IsReceiverInThisIsolateGroupOrClosed(Dart_Port receiver, IsolateGroup *group)
static SendPortPtr New(Dart_Port id, Heap::Space space=Heap::kNew)
Dart_Port origin_id() const
void set_message(std::unique_ptr< Message > message)
static SmiPtr New(intptr_t value)
SpawnIsolateTask(Isolate *parent_isolate, std::unique_ptr< IsolateSpawnState > state)
~SpawnIsolateTask() override
void RunLightweight(const char *name)
void RunHeavyweight(const char *name)
static StringPtr NewFormatted(const char *format,...) PRINTF_ATTRIBUTE(1
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
void ToUTF8(uint8_t *utf8_array, intptr_t array_len) const
static const char * ToCString(Thread *thread, StringPtr ptr)
static Thread * Current()
static void ExitIsolateGroupAsHelper(bool bypass_safepoint)
IsolateGroup * isolate_group() const
static bool EnterIsolateGroupAsHelper(IsolateGroup *isolate_group, TaskKind kind, bool bypass_safepoint)
FinalizablePersistentHandle * handle() const
static TransferableTypedDataPtr New(uint8_t *data, intptr_t len)
static intptr_t MaxElements(intptr_t class_id)
static UnhandledExceptionPtr New(const Instance &exception, const Instance &stacktrace, Heap::Space space=Heap::kNew)
static bool IsMatch(const ObjectPtr a, const ObjectPtr b)
static const char * Name()
static bool ReportStats()
static uword Hash(const ObjectPtr obj)
intptr_t VisitPointers(ObjectPointerVisitor *visitor)
static UnwindErrorPtr New(const String &message, Heap::Space space=Heap::kNew)
static intptr_t Length(int32_t ch)
char * PrintToString(const char *format,...) PRINTF_ATTRIBUTE(2
struct _Dart_Isolate * Dart_Isolate
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const uint8_t uint32_t uint32_t GError ** error
#define MESSAGE_SNAPSHOT_ILLEGAL(type)
static dart::SimpleHashMap * environment
static ObjectPtr ValidateMessageObject(Zone *zone, Isolate *isolate, const Object &obj)
@ kInternalToIsolateGroup
ObjectPtr ReadMessage(Thread *thread, Message *message)
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
bool CanShareObjectAcrossIsolates(ObjectPtr obj)
static const char * NewConstChar(const char *chars)
DART_EXPORT bool Dart_IsKernel(const uint8_t *buffer, intptr_t buffer_size)
ObjectPtr ReadObjectGraphCopyMessage(Thread *thread, PersistentHandle *handle)
const char * FindRetainingPath(Zone *zone_, Isolate *isolate, const Object &from, const Object &to, TraversalRules traversal_rules)
static bool InSameGroup(Isolate *sender, const SendPort &receiver)
void * malloc(size_t size)
static ObjectPtr DeserializeMessage(Thread *thread, Message *message)
ObjectPtr CopyMutableObjectGraph(const Object &object)
static void ThrowIsolateSpawnException(const String &message)
static const char * String2UTF8(const String &str)
static constexpr intptr_t kSlotsPerInterruptCheck
DART_EXPORT bool Dart_RunLoopAsync(bool errors_are_fatal, Dart_Port on_error_port, Dart_Port on_exit_port, char **error)
std::unique_ptr< Message > WriteMessage(bool same_group, const Object &obj, Dart_Port dest_port, Message::Priority priority)
DEFINE_NATIVE_ENTRY(List_allocate, 0, 2)
static const char * CanonicalizeUri(Thread *thread, const Library &library, const String &uri, char **error)
DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject *message)
Isolate * CreateWithinExistingIsolateGroup(IsolateGroup *group, const char *name, char **error)
static int8_t data[kExtLength]
DART_EXPORT void Dart_ShutdownIsolate()
static void ExternalTypedDataFinalizer(void *isolate_callback_data, void *peer)
static intptr_t GetTypedDataSizeOrThrow(const Instance &instance)
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
std::function< void()> closure
#define GET_NATIVE_ARGUMENT(type, name, value)
#define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value)
union _Dart_CObject::@86 value
#define TIMELINE_DURATION(thread, stream, name)