Skip to content

Commit 6225f46

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[vm/concurrency] Update documentation of SendPort.send to be more precise
In addition to making the documentation of [SendPort.send] more precise by describing what objects are disallowed for sending objects between isolates within the same isolate group, it also makes [Isolate.exit] link to [SendPort.send]. Closes #46623 TEST=Updates documentation only. Change-Id: I9bc1d88faaf2b70589af5e56168976ba89a35558 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/219080 Commit-Queue: Martin Kustermann <[email protected]> Reviewed-by: Alexander Aprelev <[email protected]>
1 parent 05aecf5 commit 6225f46

File tree

1 file changed

+35
-14
lines changed

1 file changed

+35
-14
lines changed

sdk/lib/isolate/isolate.dart

Lines changed: 35 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -563,9 +563,9 @@ class Isolate {
563563
/// This operation is potentially dangerous and should be used judiciously.
564564
/// The isolate stops operating *immediately*. It throws if the optional
565565
/// [message] does not adhere to the limitations on what can be sent from one
566-
/// isolate to another. It also throws if a [finalMessagePort] is associated
567-
/// with an isolate spawned outside of current isolate group, spawned via
568-
/// [spawnUri].
566+
/// isolate to another (see [SendPort.send] for more details). It also throws
567+
/// if a [finalMessagePort] is associated with an isolate spawned outside of
568+
/// current isolate group, spawned via [spawnUri].
569569
///
570570
/// If successful, a call to this method does not return. Pending `finally`
571571
/// blocks are not executed, control flow will not go back to the event loop,
@@ -575,9 +575,9 @@ class Isolate {
575575
/// code will run in the isolate.)
576576
///
577577
/// If [finalMessagePort] is provided, and the [message] can be sent through
578-
/// it, then the message is sent through that port as the final operation of
579-
/// the current isolate. The isolate terminates immediately after
580-
/// that [SendPort.send] call returns.
578+
/// it (see [SendPort.send] for more details), then the message is sent
579+
/// through that port as the final operation of the current isolate. The
580+
/// isolate terminates immediately after that [SendPort.send] call returns.
581581
///
582582
/// If the port is a native port -- one provided by [ReceivePort.sendPort] or
583583
/// [RawReceivePort.sendPort] -- the system may be able to send this final
@@ -599,9 +599,10 @@ class Isolate {
599599
/// when sent.
600600
abstract class SendPort implements Capability {
601601
/// Sends an asynchronous [message] through this send port, to its
602-
/// corresponding `ReceivePort`.
602+
/// corresponding [ReceivePort].
603603
///
604-
/// The content of [message] can be:
604+
/// The transitive object graph of [message] can contain the following
605+
/// objects:
605606
/// - [Null]
606607
/// - [bool]
607608
/// - [int]
@@ -612,14 +613,34 @@ abstract class SendPort implements Capability {
612613
/// - [SendPort]
613614
/// - [Capability]
614615
///
615-
/// In the special circumstances when two isolates share the same code and are
616-
/// running in the same process (e.g. isolates created via [Isolate.spawn]),
617-
/// it is also possible to send object instances (which would be copied in the
618-
/// process).
619-
///
620-
/// The send happens immediately and doesn't block. The corresponding receive
616+
/// If the sender and receiver isolate share the same code (e.g. isolates
617+
/// created via [Isolate.spawn]), the transitive object graph of [message] can
618+
/// contain any object, with the following exceptions:
619+
///
620+
/// - Objects with native resources (subclasses of e.g.
621+
/// `NativeFieldWrapperClass1`). A [Socket] object for example referrs
622+
/// internally to objects that have native resources attached and can
623+
/// therefore not be sent.
624+
/// - [ReceivePort]
625+
/// - [DynamicLibrary]
626+
/// - [Pointer]
627+
/// - [UserTag]
628+
/// - `MirrorReference`
629+
///
630+
/// Apart from those exceptions any object can be sent. Objects that are
631+
/// identified as immutable (e.g. strings) will be shared whereas all other
632+
/// objects will be copied.
633+
///
634+
/// The send happens immediately and may have a linear time cost to copy the
635+
/// transtive object graph. The send itself doesn't block (i.e. doesn't wait
636+
/// until the receiver has received the message). The corresponding receive
621637
/// port can receive the message as soon as its isolate's event loop is ready
622638
/// to deliver it, independently of what the sending isolate is doing.
639+
///
640+
/// Note: Due to an implementation choice the Dart VM made for how closures
641+
/// represent captured state, closures can currently capture more state than
642+
/// they need, which can cause the transitive closure to be larger than
643+
/// needed. Open bug to address this: http://dartbug.com/36983
623644
void send(Object? message);
624645

625646
/// Tests whether [other] is a [SendPort] pointing to the same

0 commit comments

Comments
 (0)