Commit Graph

22486 Commits

Author SHA1 Message Date
Slava Egorov b24698b9b5 Revert "[vm] Add NativeRuntime.streamTimelineTo"
This reverts commit 553887bc56.

Reason for revert: Broken android builds

Original change's description:
> [vm] Add NativeRuntime.streamTimelineTo
>
> This API allows to programmatically generate timeline information 
> including profiling samples if timeline format supports it.
>
> This change also includes Perfetto timeline writer and profiler 
> into non-mobile PRODUCT builds. The size of Mac OS X dartaotruntime
> has increased by 34352 bytes (0.7%).
>
> TEST=vm/dart/stream_timeline_to_test
>
> CoreLibraryReviewExempt: VM specific dart:developer API.
> Change-Id: I326f5fd29ee82a503160f5f5a2a857a7c55330ec
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426220
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Slava Egorov <vegorov@google.com>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I583ad74b850514fb47054149da464a07874fc2f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457000
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2025-10-23 04:58:29 -07:00
Vyacheslav Egorov 553887bc56 [vm] Add NativeRuntime.streamTimelineTo
This API allows to programmatically generate timeline information 
including profiling samples if timeline format supports it.

This change also includes Perfetto timeline writer and profiler 
into non-mobile PRODUCT builds. The size of Mac OS X dartaotruntime
has increased by 34352 bytes (0.7%).

TEST=vm/dart/stream_timeline_to_test

CoreLibraryReviewExempt: VM specific dart:developer API.
Change-Id: I326f5fd29ee82a503160f5f5a2a857a7c55330ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426220
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-10-23 04:47:13 -07:00
Alexander Markov d16ce70617 [vm] Improve inline 'is' tests against Function and Record
Testing for kClosureCid/kRecordCid is exhaustive in those cases,
so we do not need a subsequent STC type test.

Follow-up to https://dart-review.googlesource.com/c/sdk/+/456406.

TEST=ci

Change-Id: I7cb4487408b3b181f1f5384966340cc4c9a9a86f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456720
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-10-22 14:10:49 -07:00
Ryan Macnak 4fe0461368 [test] Further weaken many_interfaces_flat_test to avoid timeouts.
Change-Id: Iec6987c816b07b4402b82579af32265e49054be1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456484
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-10-22 09:36:20 -07:00
Alexander Markov 2626836f36 [aot,dyn_modules] Fix inlined 'is' tests for classes which can be extended in dynamic modules
Bug: b/453914353
Change-Id: I5739913010b9331f6e060150680a0051ed580a2d
TEST=pkg/dynamic_modules/test/data/extend_class3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456406
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-10-22 08:51:48 -07:00
Ryan Macnak a4a5bc4fc9 [vm] Fix TSAN crashes due to TSAN's own overflow.
TEST=vm/cc/DartAPI_StackOverflow
Change-Id: If5456f4f0a194332b38901f9bd677f3cd9af561c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456421
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-10-21 15:57:35 -07:00
Ryan Macnak fca41fa22f [vm, compiler] Refactor IA32 leaf runtime calls to be more like the other architectures.
TEST=ci
Change-Id: I2e5902649df3a09c83240ecda26d0f514755e56d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456101
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-21 10:22:01 -07:00
Ryan Macnak 16dac1c61d Roll Clang from 9d7449a82b83 to 8b93f27cf7e6
TEST=build
Change-Id: I4c7ad19d9b5d9a7f329516296c1cd01dd64053b5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456160
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
2025-10-21 09:22:50 -07:00
Ryan Macnak 90cb9e4c31 [dartfuzz] Fix flag fuzzer after dart2wasm change that requires output have the wasm extension.
Change-Id: I9e89e6e91b5b279e5310e3fd3f51f5e3b6c6c1b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456108
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-10-21 08:00:00 -07:00
Ryan Macnak 4e3f44fb95 [vm] Synchronize between switchable call patching and loading in the runtime.
TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/61718
Change-Id: I8938b3243144a24febaa58a48a98fe6d328fd6be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456105
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-20 17:51:13 -07:00
Ryan Macnak f8e61ad148 [vm] Fix TSAN symbolization for Mac.
TEST=tsan
Change-Id: I44456d685737c0fe59c25d0f2cc9f6fc8a4ded56
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456106
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-20 15:58:20 -07:00
Ryan Macnak fd7ddd4cd0 [vm] Fix Android ARM32 build.
Change-Id: I9467bc4145f09ffbbf4a10ecde627dec59fc023c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456140
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-20 15:36:20 -07:00
Ryan Macnak 0a1678c06c [vm] Record stack for JIT TSAN.
The main interesting thing is that deopt can expand one optimized frame to multiple unoptimized frames, so deopt needs to call  __tsan_func_entry enough times to rebalance the stack.

Also fixes stack balance for throw error slow paths for AOT.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/61352
Change-Id: I3fdc8481bc8db7a3aec0fa1938ac3e0e96ac13a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452943
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-10-20 10:49:20 -07:00
Ryan Macnak c59549e957 [vm, compiler] More specific assembly comments for runtime calls.
TEST=ci
Change-Id: Iaabdbceedbddffd2f980fb0828a8fc211524a3d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/455180
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-10-15 09:21:52 -07:00
Alexander Markov 72bd9baa54 [vm,aot] Fix unboxing info (including calling conventions) on unreachable fields
For some reason unboxing information was not generated for unreachable
fields. However, unreachable field can be used as an interface target,
and unboxing info contains a flag indicating if register calling
convention should be used which affects how the call via this field
as an interface target is going to be performed.
So it is incorrect to omit such unboxing info and this change fixes
this bug.

TEST=vm/dart/regress_b_450678575_test

Bug: b/450678575
Change-Id: Ic1f299d9c0b09005c8bbfd95d1a409c113630263
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454681
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-10-14 13:35:02 -07:00
Slava Egorov dec87b98f0 [io] Provide dart::bin::SetupDartIoLibrary
Instead of requiring embedder to initialize dart:io by bits and pieces
by invoking various hooks and setting fields provide a structured C++
API for preparing dart:io for execution.

TEST=ci

CoreLibraryReviewExempt: VM specific changes only
Change-Id: I66e95c0a451d384b4f7582d1df059e506a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454062
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-10-14 13:15:21 -07:00
Ryan Macnak f80d794475 [vm] Fixes for TSAN in debug mode.
TEST=local build
Change-Id: I99550b012531717dd942f397495a25599154ec69
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454180
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-13 13:24:35 -07:00
Konstantin Shcheglov d9686112c8 Elements. Migrate runtime/tools/dartfuzz from deprecated analyzer APIs.
Change-Id: I1f4f38ffd0054997e9cf6dc9cff95a7805dc8760
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454620
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-13 09:28:52 -07:00
Slava Egorov 07c9599ead [vm] Tweak location of Perfetto protos
This CL tries to address version skew issues which occur in internal
monorepo which we created by checking in *.pbzero.h files into
runtime/vm/protos/*. These files refer to protozero internal headers,
which in the internal monorepo come from a shared Perfetto dependency
which does not necessarily match the version we pinned in our DEPS and
used to generated these files.

This version skew caused problems for the Perfetto team, see
https://github.com/google/perfetto/pull/3195

To resolve this change layout of our repo to allow us to depend on the
shared Perfetto entirely - including its version of *.pbzero.h headers.

We change include paths in the VM source to

    #include "third_party/perfetto/protos/..."

which match location of these headers in the internal monorepo.

To make the code compile in the normal SDK checkout we shift location of
Perfetto and checked in code:

* Perfetto source moves from third_party/perfetto to
  third_party/perfetto/src.
* Generated code moves from runtime/vm/protos into
  third_party/perfetto/protos.

Note: experiments show that *.pbzero.h files tree-shake very well and
you pay only for things that you use. That means depending on *.pbzero.h
files generated from full message definitions rather than our manually
tree-shaken versions does not actually increase the size of the VM
binaries. We could switch our external build to do the same but this
would make protoc a build time dependency, which seems excessive.

TEST=ci

Change-Id: I724b9d9304be83302a5d83c2337154b36a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454260
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-10-13 02:09:31 -07:00
Tess Strickland df693c20b0 [vm,dyn_modules] Add flags to bytecode source positions.
There are two possible flags for each source position currently:
a flag that marks the source position as synthetic and a flag that
marks the source position as within a yield point.

Synthetic source positions in bytecode are treated the same as synthetic
source positions in compiled code. That is, they encode the source
position in the text that caused them to be synthesized, but denote that
the covered instructions are internal and not to be used for debugger
pause points or for call site/branch coverage information.

Adding these flags allow us to mark appropriate parts of the async
machinery as synthetic, and also allow us to mark all the bytecode
involved in yield points as having the same token position.

The latter fixes tests where the code would step over a previous
expression, thus being paused at the start of the await bytecode,
and would record the fp and token position there as the ones to
ignore. However, since a new source position wasn't emitted until the
direct call to the await method, the recorded token position would
be the token position prior to the await call, and so the change
in token position at the await call would trigger an early pause.

TEST=pkg/vm_service/test/async_single_step_exception_test
     pkg/vm_service/test/async_single_step_into_test
     pkg/vm_service/test/async_single_step_out_test
     pkg/vm_service/test/async_star_single_step_into_test
     pkg/vm_service/test/async_step_out_test
     pkg/vm_service/test/positive_token_pos_test
     pkg/vm_service/test/step_into_async_no_await_test

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-mac-debug-arm64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-product-x64-try
Change-Id: Ic7642a74fb76227a473f461f360e84dd3d5a45a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453322
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-10-09 09:15:42 -07:00
Tess Strickland 3c26fcf597 [vm] Delimit and escape string constants when disassembling to stdout.
TEST=ci (only affects output used for debugging the VM)

Change-Id: If9732db5695a19943ecf88362deb96a93a2bd843
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454000
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-10-09 02:19:50 -07:00
Ryan Macnak 9bcd33c50b Reapply "[standalone] Use fewer syscalls to get entropy on Linux and Mac."
Use SecRandomCopyBytes on Mac/iOS.

TEST=ci, local engine build
Change-Id: I48e1fc0186e4a65419fd9bf02be4d91983f8d8d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453581
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-10-08 08:16:42 -07:00
Tess Strickland 5b69fdd521 [vm] Fix v8 snapshot profile issue with deferred libaries.
TEST=vm/dart/regress_flutter169921

Issue: https://github.com/flutter/flutter/issues/169921
Change-Id: I9a996dcc1213712e6545cf134b436d60ea76b71d
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453881
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-10-08 05:09:00 -07:00
Slava Egorov 505f08b49a [lib] Avoid empty stack-traces in Stream methods
This change leans on VMs ability to provide a awaiter stack traces (if
the code is written using async syntax sugar or properly annotated with
@pragma('vm:awaiter-link').

Currently doing

    await Stream.fromIterable([]).first;

would result in an empty stack trace. However after this change
we actually get a meaningful stack trace when running on the VM.

Fixes https://github.com/dart-lang/sdk/issues/51025

TEST=vm/dart/awaiter_stacks/stream_methods

CoreLibraryReviewExempt: No functional or API changes. Just better error messages on exceptional code paths.
Change-Id: Ifc3e446c00121cc97f2f870c3e3f5bf56a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453940
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-10-08 04:11:51 -07:00
Slava Egorov c70a4b08a2 [io] Fix Mac OS X file watcher
Fixes bug in commit 25df2b3f11.

The code for converting FSEventStream notification into Dart format 
was checking file existence using relative path instead of absolute
path. This caused it to incorrectly classify rename events which
were creations as deletions.

This was not caught by testing because this was not well covered
by the test and the test closest to checking this was even 
disabled on Mac. CL updates updates the test to cover this better. 

Fixes https://github.com/dart-lang/sdk/issues/61693

TEST=standalone/io/file_system_watcher_test

Change-Id: I2a7c984dfcec0be74c974f13b6ead7d86a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453880
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-08 02:25:17 -07:00
Ryan Macnak f1aa58931d [vm] Remove Isolate, IsolateGroup and global Random.
The per Thread instance is sufficient.

TEST=ci
Change-Id: Iff2c4279937637089f7ae4194cb1097b5e6eef67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452881
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-07 15:13:14 -07:00
Ryan Macnak 6938441679 [build] Increase android_api_level from 21 to 24.
Bug: https://github.com/dart-lang/sdk/issues/61664
Change-Id: I10a99fbe03df32f056765913e75f14b63bc33bc1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453681
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-07 13:17:21 -07:00
Ryan Macnak aea69bc76e [vm] Disallow simultaneous switchable call updates.
Note it is okay for the lookup part of a switchable call miss to race with the update of another thread's miss.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/61670
Bug: https://github.com/dart-lang/sdk/issues/61671
Change-Id: Iad28f0f180f311de69e982a64b872f773f9eaaba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453680
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-07 10:44:02 -07:00
Tess Strickland 48b5eeb1ed [vm,dyn_modules] Fix constant coverage info for scripts without sources.
Also the pending objects list can be added to while handling other
pending objects, so the length of the list must be re-retrieved on each
iteration.

TEST=pkg/vm_service/test/coverage_leaf_function_test.dart

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try
Change-Id: I1089515f3e967ddc41fb82ce9f0541a81b9529d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452784
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-10-02 09:11:22 -07:00
Alexander Markov 90d03192f7 [gardening] Skip slow vm/dart/use_dwarf_stack_traces_flag_* tests on reload bots
TEST=ci
Closes https://github.com/dart-lang/sdk/issues/61584

Change-Id: I468675cc1f191327647610b38719ef74d93dfedd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452844
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-10-02 09:05:20 -07:00
Alexander Markov e48ff95649 Revert "[standalone] Use fewer syscalls to get entropy on Linux and Mac."
This reverts commit ea162825d3.

Revert "[standalone] Fix Linux Crypto::GetRandomBytes on MSAN."

This reverts commit c3e5b7c268.

Reason for revert: build failures on "Mac mac_ios_engine" Flutter bot:
```
../../../flutter/third_party/dart/runtime/bin/crypto_macos.cc:10:10: fatal error: 'sys/random.h' file not found
   10 | #include <sys/random.h>
      |          ^~~~~~~~~~~~~~
1 error generated.
```

https://ci.chromium.org/ui/p/flutter/builders/try/Mac%20mac_ios_engine/50544/overview

TEST=ci

Change-Id: Ib0656cbf1268fc48f42097b09ca60c5bf2c1e2bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452843
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-10-02 07:37:07 -07:00
Ryan Macnak c3e5b7c268 [standalone] Fix Linux Crypto::GetRandomBytes on MSAN.
TEST=msan
Change-Id: Ifcf3c2939363eade8fb9e2e169b74a6d102c74a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452908
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-01 15:28:50 -07:00
Alexander Aprelev ad318128f5 [io] Fix race between closing socket and requesting its type.
Fixes https://github.com/dart-lang/sdk/issues/61582

Revert "[io/socket] Make Socket::fd_ atomic since it can get updated from multiple threads."
Revert "[gardening] Fix fuchsia build - assign atomic to intptr_t before reinterpret_cast to pointer."

TEST=ci

Change-Id: Ia755d6623e46b7940800a12bf4a5d8d9cb674522
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451822
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-10-01 15:15:20 -07:00
Ryan Macnak ea162825d3 [standalone] Use fewer syscalls to get entropy on Linux and Mac.
TEST=ci
Change-Id: Ib4737145a34b1d5e4aeab4377f918745abe8e1fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452220
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-10-01 13:01:38 -07:00
Slava Egorov 25df2b3f11 [io] Rewrite Mac OS X FS watcher
Watcher used pipes to fit into the "socket"-like implementation used by
other OSes. However it turns out that pipe buffer on Mac OS X is not
necessarily large enough to fit the whole FSEvent structure meaning that
we can't expect to be able to read FSEvents atomically from a pipe.

This situation happens because Mac OS X inherits BSD behavior of
limiting total number of kernel memory reserved for pipe buffers. Once
kern.ipc.maxpipekva limit is crossed pipe buffers no longer grow to 64KB
and remain 512 bytes large (which is absolute minimum allowed by POSIX
which requires writes smaller than PIPE_BUF to be atomic).

So our code needs to be prepared that only half of FSEvent structure
(which is 1032 bytes large) will fit into pipe buffer.

We could fix this by reading each FSEvent in chunks but this seems
ridiculously ineffecient. Instead we rewrite the code to pass file
system events via SendPort instead.

Fixes https://github.com/dart-lang/sdk/issues/61551

TEST=runtime/tests/vm/dart/regress_61551_test.dart

CoreLibraryReviewExempt: VM only changes.
Change-Id: I6a6a696499044832cfb61998bc6a519bbaadf8bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451260
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-01 11:28:05 -07:00
Slava Egorov ed6bab847b [io] Rewrite _FileSystemWatcher implementation
Existing implementation is an entangled mess which consists of shared
code residing in the base class which in random places invokes a number
of undocumented poorly named methods overloaded in OS specific
subclasses. Some of these methods mutate static state. There are no
clear lifetime guarantees for different parts of the system (including
comments saying that some values might or might not be valid at certain
points).

The rewrite aims to clean most of this up - sharing everything that can
be shared and moving OS specific logic to clearly documented methods.

Furthermore, we change the code to ensure proper lifetime guarantees -
so we no longer find ourself in situations where we don't know whether
pathId is valid or not.

This refactoring by itself fixes a number of issues, most specifically a
bug where watcher would stop receiving events on Windows because
DirectoryWatchHandle ends up allocated at precisely the same address as
a previous destroyed one - which confuses Dart side to think that newly
created handle is the same as the old one (due to a race between event
handler thread and Dart thread).

We fix Windows lifetime issue by a) not keeping pathId based mapping in
the watcher anymore and b) keeping DirectoryWatchHandler alive until it
is stoped by the Dart side - this is achieved by retaining it after it
is created and releasing it once path is unwatched. This way Dart side
is always sure that pathId values are valid until they are explicitly
released via _unwatchPath - which makes code very uniform.

To make sure that native objects created by _watchPath are released when
surrounding isolate exists abruptly (e.g. via Isolate.exit - without
letting Dart code to shutdown and call _unwatchPath naturally) we attach
NativeFinalizer to them. This fixes the existing leak of file watchers
on Mac OS X - as Node objects it created were not freed if surrounding
isolate exited. Note that inotify descriptors did not leak in the same
way because they were wrapped into sockets.

Finally, this refactoring also make sure that the last subscriber
cancelling subscription on filesystem event stream will get a proper
cancellation future back and can wait for the watcher to shutdown.
Previously implementation used broadcast streams which simply return an
already completed future when subscriber cancels. New implementation
uses Stream.multi instead which gives a better result. Now doing
watch().listen().cancel() returns a future which will only complete once
watcher is fully disposed (e.g. inotify descriptor is closed). Bad
behavior was revealed by analysing standalone/regress_52715 - which
revealed that repeatedly watching and cancelling might flakely cause us
to hit fd limit depending on whether eventhandler thread can keep up
closing file descriptors created by the main thread or not.

Fixes https://github.com/dart-lang/sdk/issues/61378

TEST=standalone/{regress_61378,file_system_watcher_isolate_exit_leak}

CoreLibraryReviewExempt: VM only changes.
Change-Id: I6a6a69642b1f2673f2be78434bc64270846ad8c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450921
Reviewed-by: Lasse Nielsen <lrn@google.com>
2025-10-01 11:28:05 -07:00
Slava Egorov f434804f6b [io] Simplify Mac OS X FileSystemWatcher
Use a single dispach queue instead of manually managed threads with run
loops.

TEST=ci

Change-Id: I6a6a696489ebd41305027b5cef7fccb73b1f6731
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452140
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-01 11:28:05 -07:00
Slava Egorov 3dfad7dd69 [vm] Remove traces of dart:concurrent from Builtin.
This library no longer has old school natives and uses FFI natives
instead which are configured in bootstrap instead.

TEST=ci

Change-Id: I6a6a6964e1ee692153dfeb8dbaf692b35851e893
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452141
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-01 11:28:05 -07:00
Ryan Macnak 158398dc26 [vm] Switchable call site updates without RunWithStoppedMutators.
TEST=iso-stress
Change-Id: Idb00490737e22348d6609291f052ac6785a42424
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441864
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-01 10:06:20 -07:00
Tess Strickland 99a370942b [vm,dyn_modules] Update some coverage information for bytecode.
Add a flag to SourceFile which is true if the associated script
contains a list of covered const constructors, and serialize said
list if true.

Delay reading and resolving the list of covered const constructors in
the bytecode reader until code is read.

Update usage counters for interpreted functions in Entry instructions.

Fix up cases where SourceReport assumed compiled code as appropriate.

Remaining:
* Record call and assert coverage information if the current isolate
  group has coverage enabled.
* Record branch coverage information if the current isolate group
  has branch coverage enabled.

TEST=pkg/vm_service pkg/dart2bytecode

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-mac-debug-arm64-try
Change-Id: I14b6ffba1e175993e992c0fe939473557303bfeb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449900
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-10-01 09:51:59 -07:00
Ryan Macnak f1ba8ceacf [vm] Make some IgnoreRace functions inlinable.
Fix GCC TSAN build.
Cleanup sanitizer includes.

TEST=ci
Change-Id: Ib68bbfa701b4309c03514ed689391051094208e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452226
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-01 09:41:26 -07:00
Ryan Macnak 95222f13c8 [vm] Don't use _setjmp/_longjmp on Mac under TSAN.
TSAN is missing an interceptor for _longjmp (but seems to have it for _setjmp).

TEST=vm/dart/regress47472_test
Bug: https://github.com/dart-lang/sdk/issues/61536
Change-Id: I569de111f8919e50ab0faf1e8e1e5a9ebba3a63a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452525
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-09-30 15:17:12 -07:00
Ryan Macnak d61d6adaf6 [vm] More TSAN profiler issues.
TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/61594
Change-Id: I82598218a98b764d66deb671f8ec841c8e1c3cab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452280
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-09-29 21:54:41 -07:00
Alexander Markov 1f89a5e623 [vm,dyn_modules] Disable dart:mirrors in standalone VM when using interpreter
Bytecode doesn't fully support dart:mirrors and support for
dart:mirrors is already disabled in dart2bytecode.

This change disables dart:mirrors in the standalone VM running with
--interpreter flag and updates status files.

TEST=ci

Change-Id: Id9423bafb10926e8274835b77a6f50a825ad7fd7
Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try,vm-ffi-dyn-mac-debug-simarm64_arm64-try,vm-ffi-dyn-mac-release-simarm64_arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451580
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Bob Nystrom <rnystrom@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-09-29 11:04:13 -07:00
Ryan Macnak 1b8bcf23f7 [vm] Add some notes for debugging with QEMU.
Change-Id: Ie3e461641d196ff493bfa81cb384405e37de8360
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451320
Reviewed-by: Liam Appelbe <liama@google.com>
2025-09-29 09:31:21 -07:00
Alexander Aprelev 79ae34cf06 [gardening] Remove multiple_timer_test from isolate stress test suite.
The test makes assumptions about timing making it unsuitable for isolate
stress testing bot.

Fixes https://github.com/dart-lang/sdk/issues/61592
TEST=ci

Change-Id: I1537fd4f12a8ff834c05f4e5defffd48f2009e42
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451800
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-09-26 13:14:01 -07:00
Alexander Aprelev dee968bcd8 [gardening] Fix fuchsia build - assign atomic to intptr_t before reinterpret_cast to pointer.
Follow-up to https://dart.googlesource.com/sdk/+/a5b0fc041990624b8c8a9a9c846bdba98d3b07d7.

TEST=ci

Bug: https://ci.chromium.org/ui/p/dart/builders/ci.sandbox/vm-fuchsia-release-x64/11814/overview
Change-Id: I08abe6fb4ca26475fa689ad817add38fa27b9f24
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451551
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2025-09-26 08:38:53 -07:00
Alexander Aprelev a5b0fc0419 [io/socket] Make Socket::fd_ atomic since it can get updated from multiple threads.
Follow-up to https://dart.googlesource.com/sdk/+/ba7aaa929f579aaa55a2fc09a098f81df6b27804, sink the "is fd closed" check to avoid multiple reads.

Fixes https://github.com/dart-lang/sdk/issues/61582
TEST=ci

Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451600
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-09-26 07:01:23 -07:00
Alexander Aprelev ba7aaa929f [io/win] Ensure to check if socket is still open when requesting its type.
Fixes https://github.com/dart-lang/sdk/issues/61571
TEST=stdin_cancel_type_test

Change-Id: I5e0a1837e72a6e41a53fc7fe163b8931082e7405
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451381
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-09-24 21:10:40 -07:00
Ryan Macnak 305189ec8f [vm] Fix IA32.
TEST=ci
Change-Id: I5559a1cf11d8ec5ae96deb87d098cf7ee9caac8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451401
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-09-24 15:14:32 -07:00