dart-sdk/runtime
Martin Kustermann 06b2967188 [vm] Disentagle PortMap/MessageHandler from port status tracking
The main purpose of the low-level [PortMap] is to coordinate between
ports being opened & closed and concurrent message senders. That's the
only thing it should do.

Each isolate owns [ReceivePort]s. Only the isolate mutator can create
ports, delete them or change their "keeps-isolate-alive" state. Right
now it requires going via [PortMap] (which acquires lock) and
[MessageHandler] (which acquires lock) to change the
"keeps-isolate-alive" state of a port.

We'll move information whether a dart [ReceivePort] is closed and
whether it keeps the isolate alive into the [ReceivePort] object itself.

=> Changing the "keeps-isolate-alive" state of the port no longer
requires any locks. We could even avoid the runtime call itself in a
future CL.

Isolates are kept alive if there's any open receive ports (that have not
been marked as "does not keep isolate alive"). This is a property of an
isolate not of the message handler. For native message handlers we do
have a 1<->1 correspondence between port and handler (i.e. there's no
"number of open ports" tracking needed).

=> We'll move the logic of counting open receive ports and ports that
keep the isolate alive to the [Isolate].
=> We'll also remove locking around incrementing/decrementing or
accessing the counts.
=> The [IsolateMessageHandler] will ask the [Isolate] whether there's
any open ports for determining whether to shut down.
=> For native ports, the `Dart_NewNativePort()` & `Dart_CloseNativePort()`
functions will manage the lifetime (as their name also suggests).

Overall this makes the [Isolate] responsible for creation of dart
[ReceivePort]s and tracking whether the isolate should be kept alive:
  * Isolate::CreateReceivePort()
  * Isolate::SetReceivePortKeepAliveState()
  * Isolate::CloseReceivePort()

TEST=ci

Change-Id: I847ae357c26254d3810cc277962e05deca18a1de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317960
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-08-08 10:57:47 +00:00
..
bin [vm] Separate for-snapshot vs embed-sources bools when compiling to kernel 2023-07-28 10:01:53 +00:00
docs [vm] Update lingering references to RawObject. 2023-07-26 21:53:49 +00:00
include [vm] Separate for-snapshot vs embed-sources bools when compiling to kernel 2023-07-28 10:01:53 +00:00
lib [vm] Disentagle PortMap/MessageHandler from port status tracking 2023-08-08 10:57:47 +00:00
observatory [vm] Fix expression evaluation in context of closures 2023-08-04 11:07:46 +00:00
observatory_2 [vm, service] Fix discrepancy between VM generating kind _TypeParameters and service.md claiming the existence of kind TypeParameters. 2023-08-01 20:34:21 +00:00
platform [vm] Allow non-TSAN gen_snapshot target TSAN AOT runtime 2023-07-10 11:53:58 +00:00
tests [test] Skip high-memory tests on Linux ARM64. 2023-08-07 17:58:07 +00:00
third_party Spelling pkg analyzer lib 2023-01-25 14:08:27 +00:00
tools [vm] Enable clang-tidy for arm, arm64, riscv64, product, release, precompiler. 2023-07-11 15:13:58 +00:00
vm [vm] Disentagle PortMap/MessageHandler from port status tracking 2023-08-08 10:57:47 +00:00
.clang-tidy
.gitignore
BUILD.gn Add a GN flag for the non-debug optimization level 2023-07-15 14:14:59 +00:00
codereview.settings
configs.gni [Runtime] Add extra_product_deps and extra_nonproduct_deps params to "library_for_all_configs_with_compiler" template 2023-04-14 19:51:40 +00:00
CPPLINT.cfg [cpplint] Disable runtime/references lint 2023-01-23 18:21:48 +00:00
OWNERS [infra] Add OWNERS to the Dart SDK 2022-02-14 14:06:34 +00:00
PRESUBMIT.py Reland "Reland "[VM] Begin supporting Perfetto file recorder"" 2023-04-18 19:39:05 +00:00
runtime_args.gni Add a GN flag for the non-debug optimization level 2023-07-15 14:14:59 +00:00