Commit Graph

761 Commits

Author SHA1 Message Date
Tony 57b27a7b44 Refactor Dart runtime to replace DART_DYNAMIC_MODULES with DART_BYTECODE_INTERPRETER
- Updated conditional compilation flags throughout the runtime codebase to transition from DART_DYNAMIC_MODULES to DART_BYTECODE_INTERPRETER.
- Adjusted logic in various files including object_graph_copy.cc, object_reload.cc, profiler.cc, and others to ensure compatibility with the new interpreter model.
- Ensured that all references to dynamic modules are replaced with bytecode interpreter checks, maintaining functionality for interpreted code execution.
- Modified stack frame handling and service-related code to align with the new interpreter architecture.
- Updated tests and service implementations to reflect the changes in the runtime environment.

Signed-off-by: Tony <tonylu@tony-cloud.com>
2026-06-25 01:58:41 +08:00
Alexander Aprelev 8f1a38f07b [vm/isolate_api] Ensure isolate acquisition fails gracefully when target isolate is exiting.
Introduce `is_acquirable` isolate property that tracks whether isolate can be entered, avoid a `pool_` check that does not work correctly as isolate being shutdown.

BUG=https://github.com/dart-lang/sdk/issues/63515
BUG=https://github.com/dart-lang/sdk/issues/63514
TEST=ci

Change-Id: I84577ad082d87ead8cdb9f591fabdf918e2f4bd0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509221
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-06-10 09:59:06 -07:00
Alexander Aprelev 488ba69e41 [vm/shared] Introduce isolate event loop handling dart api.
Implement api methods to create and shutdown isolates from IsolateGroup-bound callbacks (normally invoked from native code), run dart code on such isolates.
The rest of the api is not implemented yet.

TEST=tests/ffi/threading_test.dart
BUG=https://github.com/dart-lang/sdk/issues/62407
CoreLibraryReviewExempt: vm-only change to isolate library
Change-Id: I0271ead8ba011dfe9d7953769415d6a88a962854
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486522
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2026-05-27 11:31:11 -07:00
Alexander Aprelev 58047e7d94 [vm/native_api] Ensure isolate is not available for duration of native port operations.
Follow-up to 5a98fe5564.

TEST=ci

Change-Id: I62269b713968f0d0e436d86b7d7b481fc5b52cc5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501620
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2026-05-20 08:40:17 -07:00
Ryan Macnak d36adbacaf [vm] Remove the VM isolate.
The former contents of the VM isolate are now included into each isolate group. This makes each isolate group's heap independent, and in particular allows each heap to be allocated to a separate pointer cage (not done in this CL).

The duplicated stubs that allowed PC relative calls are removed, since the originals can now be the target of PC relative calls.

The bootstrapping needing to load an AppJIT or AppAOT snapshot is reduced to allocating the oddballs. The code is entirely dropped in the AOT runtime, but the JIT runtime still has it to allow for flags to affect the compilation of the stub code. Further refactoring might be able to remove this for the JIT runtime too, with only gen_snapshot knowing how to bootstrap.

Class serialization no longer distinguishes predefined classes.

The page containing null is marked as never-evacuate. null, false and true must not move because the compiler relies on their low bits having certain patterns for some optimizations. (Previously, the entire VM isolate heap never moved.)

Compaction is disabled for IA32. Due to register pressure, some stub calls must not use a scratch register and embed the address of Code.

The page containing the call-through-safepoint stub is frozen when running with --write-protect-code and the stub is created at runtime (instead of loaded from an AppJIT or AppAOT snapshot). This stub must remain executable even during a safepoint, as a foreign call might during return during a safepoint and only block after the stub directs it to the runtime.

The snapshot symbols are renamed to kDartSnapshotData and kDartSnapshotText. There is no need to distinguish the VM isolate's snapshot, and snaphots are per isolate group not per isolate. Aliases with the old names are added to ease migration.

Some global flags that were automatically set based on the VM isolate's snapshot are now isolate group flags and automatically set by the isolate group's snapshot.

TEST=ci
Change-Id: Iee82016057d609112e9b021d178fc3d4d18b5044
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500621
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
SLSA-Policy-Verified: SLSA Policy Verification Service <devtools-gerritcodereview-exitgate@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-05-18 11:35:03 -07:00
Ryan Macnak 350163cc25 [vm] Per-group callback thunks.
With no VM isolate, the lifetime of the template stub will be the lifetime of the group instead of the VM.

TEST=ci
Change-Id: I4ed2f5e5c6e8f4c92c430898dc38355a227d4057
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500620
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-05-18 08:11:36 -07:00
Nourhan Hasan 046d473d5e [vm/service]: use a map for service ID zones to avoid ID reuse and unbounded growth (#62205)
Replace the growable array with a hash map so that zones are truly
removed on deletion and IDs are never reused.

TEST=Manually tested with test_zones.dart (IDs increase, map size
toggles); existing service tests pass

Fixes: https://github.com/dart-lang/sdk/issues/62205
Change-Id: I0bbec4a0fc0aef9ed8679a3aa5ce832fea9bfde8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489720
Commit-Queue: Slava Egorov <vegorov@google.com>
Auto-Submit: Nourhan Hasan <nourhan.m.hasan@gmail.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2026-05-18 03:57:44 -07:00
Alexander Aprelev 00cda4d60f [ffi/isolate_group] Move IsolateGroupBound callbacks from isolate to isolate group.
This allows creation of isolategroup-bound callbacks when isolate is not available. For example, to support proposed Isolate::onEvent/Isolate::handleEvent api https://github.com/dart-lang/language/blob/main/working/333%20-%20shared%20memory%20multithreading/shared_native_memory.md#additional-isolate-apis.

BUG=https://github.com/dart-lang/sdk/issues/63291
TEST=isolate_group_bound_callback_test

CoreLibraryReviewExempt: vm ffi-specific comments changes
Change-Id: I9a757a39ba8e152db64f59a66d337ca672103277
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499661
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2026-05-05 08:37:06 -07:00
Ryan Macnak e98e6a1198 [vm] Per isolate group roots accessed via TLS.
Remove special case for null in message snapshots; snapshots are sometimes read or written with no current isolate group.

Currently still all copies pointing into the VM isolate.

TEST=ci
Change-Id: I4d2e35a01880885d4e92e1c623c0f39a35e06065
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/493866
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-04-08 15:26:06 -07:00
Ryan Macnak 4ed176799e [vm] Move direct roots from IsolateGroup to ObjectStore.
TEST=ci
Change-Id: I8ac97b83c427ab83dec2d7418a55893d2b5342ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491980
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-04-01 09:56:13 -07:00
Alexander Aprelev 37b14e84f4 [core/shared] Allow for RegExp to work in isolategroup-bound callbacks.
TEST=run_isolate_group_run_test

Bug: https://github.com/dart-lang/sdk/issues/61030
Change-Id: I3c4734464e1902458edb4a03f5a9e9384509356b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476860
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2026-01-30 11:16:13 -08:00
Ryan Macnak 1dc4277e5b [vm] Remove dead code.
TEST=ci
Change-Id: Ic162deea4a39869a158726616e5c8dc0ff058817
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475781
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-01-27 09:14:39 -08:00
Alexander Aprelev 6b72a9c0bc Reapply "[vm] Add graph intrinsics for ThreadLocal hasValue and getValue methods."
This reverts commit 4d7467abd6.

The fix for the failure that caused revert is in patchset 2.

TEST=ci
Change-Id: I9b7ff0dd049062b086ad43c8368c6ede130edf35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465781
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-12-03 06:30:20 -08:00
Alexander Aprelev 4d7467abd6 Revert "[vm] Add graph intrinsics for ThreadLocal hasValue and getValue methods."
This reverts commit 3a4d3681d7.

Reason for revert: broke vm-aot-android-release-arm_x64 lib/math/pi_test, https://github.com/dart-lang/sdk/issues/62149

Original change's description:
> [vm] Add graph intrinsics for ThreadLocal hasValue and getValue methods.
>
> This gets rid of native calls for ThreadLocal hasValue/getValue
>
> ===
> - 51.34%     4.46%  DartWorker       JsonEncode.dart.bin   [.] double.toString
>  - 46.89% double.toString
>   - 43.06% double._toString
>    - 42.48% stub CallBootstrapNative
>     - 41.52% dart::NativeEntry::BootstrapNativeCallWrapper(_Dart_NativeArguments*, void (*)(_Dart_NativeArguments*
>      + 27.38% dart::Number::ToString(dart::Heap::Space) const
>      + 5.79% dart::OneByteString::New(unsigned char const*, long, dart::Heap::Space)
>      + 1.79% dart::BootstrapNatives::DN_Double_toString(dart::Thread*, dart::Zone*, dart::NativeArguments*)
>        1.27% __strlen_evex
>        0.92% dart::TransitionGeneratedToVM::TransitionGeneratedToVM(dart::Thread*)
>        0.88% dart::StackZone::StackZone(dart::ThreadState*)
>        0.72% __memmove_evex_unaligned_erms
>        0.71% dart::StackZone::~StackZone()
>     1.47% _DoubleToStringCache.store
>  + 4.44% start_thread
> ===
>
> Benchmark improvements:
> - JsonEncode.Numbers.FromString (Raspberry Pi 4) 50.25%
> - JsonEncode.Numbers.FromBytes  (Raspberry Pi 4) 48.69%
>
> BUG=https://github.com/dart-lang/sdk/issues/62046
> TEST=ci
>
> Change-Id: I3cdbaf085dfc23fcad4544be8a299b7520c7d825
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464320
> Commit-Queue: Alexander Aprelev <aam@google.com>
> Reviewed-by: Slava Egorov <vegorov@google.com>

Bug: https://github.com/dart-lang/sdk/issues/62046
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I06db44ff6b7eb5021c2a2f4d5af6ff659205cb2a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/465641
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2025-12-02 09:34:58 -08:00
Alexander Aprelev 3a4d3681d7 [vm] Add graph intrinsics for ThreadLocal hasValue and getValue methods.
This gets rid of native calls for ThreadLocal hasValue/getValue

===
- 51.34%     4.46%  DartWorker       JsonEncode.dart.bin   [.] double.toString
 - 46.89% double.toString
  - 43.06% double._toString
   - 42.48% stub CallBootstrapNative
    - 41.52% dart::NativeEntry::BootstrapNativeCallWrapper(_Dart_NativeArguments*, void (*)(_Dart_NativeArguments*
     + 27.38% dart::Number::ToString(dart::Heap::Space) const
     + 5.79% dart::OneByteString::New(unsigned char const*, long, dart::Heap::Space)
     + 1.79% dart::BootstrapNatives::DN_Double_toString(dart::Thread*, dart::Zone*, dart::NativeArguments*)
       1.27% __strlen_evex
       0.92% dart::TransitionGeneratedToVM::TransitionGeneratedToVM(dart::Thread*)
       0.88% dart::StackZone::StackZone(dart::ThreadState*)
       0.72% __memmove_evex_unaligned_erms
       0.71% dart::StackZone::~StackZone()
    1.47% _DoubleToStringCache.store
 + 4.44% start_thread
===

Benchmark improvements:
- JsonEncode.Numbers.FromString (Raspberry Pi 4) 50.25%
- JsonEncode.Numbers.FromBytes  (Raspberry Pi 4) 48.69%

BUG=https://github.com/dart-lang/sdk/issues/62046
TEST=ci

Change-Id: I3cdbaf085dfc23fcad4544be8a299b7520c7d825
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464320
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-12-02 07:55:25 -08:00
Alexander Aprelev de77c6b766 [vm/shared] Introduce ScopedThreadLocal to allow keeping state on
thread, outside of isolate, on isolate-group bound callback.

Fixes https://github.com/dart-lang/sdk/issues/61523
TEST=scoped_thread_local_test

Change-Id: I0c8280d2808d940a5fb0d628db191932400a5edb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451402
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-11-13 09:50:34 -08:00
Ryan Macnak a08c958346 [vm] Remove leftover from Zones moving from Isolate to Thread.
TEST=ci
Change-Id: I1fc0217dff937ce0aefe333b96eba30a223ec467
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461240
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-11-12 07:17:59 -08:00
Vyacheslav Egorov 489f63a3bd [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%).

This relands commit 553887bc56 with fixes
for Android builds.

TEST=vm/dart/stream_timeline_to_test

CoreLibraryReviewExempt: VM specific dart:developer API.
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-product-arm-try,vm-ffi-android-release-arm-try,vm-aot-android-release-arm64c-try
Change-Id: Ifb7c66982fe9d17d2f5c9acb163a94c56a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457301
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-10-24 04:34:01 -07:00
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
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 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 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
Ryan Macnak 7271e104a2 [vm] More profiler false-positives under Mac TSAN.
TEST=tsan
Cq-Include-Trybots: luci.dart.try:vm-tsan-mac-release-arm64-try
Change-Id: Ic7c2e1bfbe996d61efa48501ad0fd9f1c11149da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451123
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-09-24 09:25:41 -07:00
Alexander Aprelev 60ce47987d [vm/shared] Ensure mutator thread is registered without possibilty of a race.
Registration of the mutator thread in isolate group should be done as thread is added, under the same atomic operation.
Mutator count changes should be done separately as before, under the same mutex used by `ContainsOnlyOneIsolate`.

Follow-up to https://dart.googlesource.com/sdk/+/acc4ee0b1e3fc94a25bdf24431e7567e20cc663d

Fixes https://github.com/dart-lang/sdk/issues/61459
TEST=isolate_group_bound_init_test

Change-Id: I48bf4121bd097d3745915294c04d1eaae3879e0d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448503
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-09-08 08:46:51 -07:00
Alexander Aprelev acc4ee0b1e Reapply "[vm/shared] Ensure to iterate over mutators, rather than only isolates during deopt."
This reverts commit ce9c2d3dd1 and as patchset 2 applies the fix to crash revealed on mac bots.

TEST=isolate_group_bound_lazy_deopt_test

Change-Id: I8aa05a482954dfbd4599d68637287f8b93716ce2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448641
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-09-05 12:13:14 -07:00
Alexander Aprelev ce9c2d3dd1 Revert "[vm/shared] Ensure to iterate over mutators, rather than only isolates during deopt."
This reverts commit e5f66118aa.

Reason for revert: isolate_group_bound_init_test failures on mac bots: https://dart-ci.appspot.com/log/vm-aot-mac-release-x64/vm-aot-mac-release-x64/4425/ffi/isolate_group_bound_init_test/2

Original change's description:
> [vm/shared] Ensure to iterate over mutators, rather than only isolates during deopt.
>
> Iterating over only isolates ignores isolategroup-bound dart code.
>
> Fixes https://github.com/dart-lang/sdk/issues/61326
> TEST=isolate_group_bound_lazy_deopt_test
>
> Change-Id: Ic27679ab7eb37aa2ca703937355dc83d751e0054
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448254
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Commit-Queue: Alexander Aprelev <aam@google.com>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: Ieb04abbf1b4a7fbc7637e5a7c3a3dce2010f2101
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448602
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2025-09-05 09:25:18 -07:00
Alexander Aprelev e5f66118aa [vm/shared] Ensure to iterate over mutators, rather than only isolates during deopt.
Iterating over only isolates ignores isolategroup-bound dart code.

Fixes https://github.com/dart-lang/sdk/issues/61326
TEST=isolate_group_bound_lazy_deopt_test

Change-Id: Ic27679ab7eb37aa2ca703937355dc83d751e0054
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/448254
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-09-05 08:41:36 -07:00
Alexander Aprelev 0e5bd0e18d [vm/shared] Introduce tag_table_lock to ensure data-race-safe access to tag_table.
Fixes https://github.com/dart-lang/sdk/issues/61404
TEST=tsan ci

Change-Id: I606a6fde54b7948bce206cb3d13d9534e50019ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447003
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-08-26 14:39:33 -07:00
Alexander Aprelev 2d7c7b039c [vm/usertag] Move usertags from Isolate to Thread.
This allows use of usertag api in isolategroup-bound context.

BUG=https://github.com/dart-lang/sdk/issues/61325
TEST=ci

Change-Id: I73d5631ba6eddcc06965b982bc199221ac021cd5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445967
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-08-25 14:43:41 -07:00
Alexander Aprelev a36f38b10a [vm/shared] Rename IsolateGroupShared to IsolateGroupBound.
TEST=ci

CoreLibraryReviewExempt: vm-only change
Change-Id: If9c8bbd0e90e4ec1f70742c704ad31fce5681ec1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/441063
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-07-29 12:03:37 -07:00
Alexander Aprelev c47a8b0ada [vm/shared] Restore fast-path for RunWithStoppedMutators.
The fastpath was removed in https://dart.googlesource.com/sdk.git/+/bd0d029792bce2bc4b0b7fa1659d24350266b3d1 because the fastpath didn't take into account isolategroup-shared mutators and holding an active_mutators_monitor_ caused tsan-identified potential circular locking. Removal actually resulted in regressions in flutter reassemble benchmarks.

This PR restores fastpath and instead of holding active_mutators_monitor_ it just keeps track of isolategroup-shared mutators counter, which this PR adds as well.

BUG=https://github.com/flutter/flutter/issues/171722
TEST=ci, manual patch into flutter and run reload

Change-Id: I00e01d930788697c8ae91fda73b09e013e718fad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439802
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-07-11 07:23:10 -07:00
Ryan Macnak 67e35919a3 [vm] Remove dead Isolate::boxed_field_list_.
TEST=ci
Change-Id: I072ab19a8195c5b1cf1b32a6541a31a25bc8a1fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439343
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-07-08 14:29:41 -07:00
Ryan Macnak d8117e1b08 [vm] Finer labeling of roots in heap snapshots.
Add missing object id zone roots, which should have been part of ffbbdb5a10 when they switched from weak to strong.

TEST=examine snapshot after using inspect
Bug: https://github.com/dart-lang/sdk/issues/61036
Change-Id: I3bea765e4ae487babfd86eccbaa87bab80320dcf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439160
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-07-07 17:02:17 -07:00
Ryan Macnak 4eeb8cfbe6 [vm, gc] Remove force_growth option from RunWithStoppedMutators.
Adjust wait for sweeper to account for whether we're already under a safepoint operation.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/61019
Change-Id: Ic30500a1348dc8a719e72be64d69e496986107aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437901
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-06-30 15:50:40 -07:00
Alexander Aprelev bd0d029792 [vm/shared] Remove "single mutator" fastpath from RunWithStoppedMutators.
In presence of isolate-less mutators, the check for "single mutator"-scenario is not-trivial, acquiring active_mutator_count mutex results in circular mutex dependencies.

BUG=https://github.com/dart-lang/sdk/issues/60857
BUG=https://github.com/dart-lang/sdk/issues/60953
TEST=ci

Change-Id: I5a12f9b8d4bc54042137012668ed1afee7c7739f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435241
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-06-30 10:31:57 -07:00
Alexander Aprelev 4715ebd181 [vm/shared] Update mutator count as entering/exiting mutator thread.
Running dart code on mutator thread outside of isolate still should follow limits on number of concurrent mutators in the vm.
Also this fixes inconsistency when entering isolate group as mutator, where original worker was marked as blocked while thread was actually running dart code. That inconsitency showed up as sporadic crash on isolate_group_shared_init_test with increased number of spawned isolates.

TEST=isolate_group_shared_init_test
BUG=https://github.com/dart-lang/sdk/issues/60877

Change-Id: I8917be903bb5517940dad3e5dab143d5ed5fdf79
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432900
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-06-09 10:34:40 -07:00
Alexander Aprelev ef4e39a6ef [vm/shared] Ensure exclusive execution of shared field initialization.
Add a mutex to guard execution of vm:shared field initialization.

TEST=isolate_group_shared_init_test
BUG=dartbug.com/60699

Change-Id: If544351fc26bfcc7fb9703954efe785989d488bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431742
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-06-05 14:12:33 -07:00
Alexander Aprelev 65d0d8581a [vm/shared] Move forward_table from Isolate to Thread.
Having forwarding tables on the Thread allows for those tables to be used in dart mutator thread running in IsolateGroup-shared context. On 32-bit platforms(arm) the forwarding tables are used during [SendPort.send] message verification.

Fixes https://github.com/dart-lang/sdk/issues/60817
TEST=isolate_group_shared_send_test

Change-Id: I58b33c14026584330b594776e812fe1d48bc2fd5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431942
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-06-02 10:04:39 -07:00
Alexander Aprelev 3718baa446 [ffi/isolate_group_shared] Keep isolate alive for isolate group shared callback.
To fix encountered tsan race(patchset 3)  split Metadata into MetadataEntry as discussed on https://github.com/dart-lang/sdk/issues/60728#event-17760701621

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

Change-Id: I9308d6fb6a9b819221f7fe4668aefb3a578fe8a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430122
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-22 09:02:01 -07:00
Alexander Aprelev 50e0e0d99d [vm/shared] Introduce NativeCallable.isolateGroupShared
This method allows for synchronous execution of dart callbacks from native code. The execution happens on dart mutator thread, from which dart code can only access isolate-group variables - those which are tagged with .

Bug: https://github.com/dart-lang/sdk/issues/54530
Bug: https://github.com/dart-lang/sdk/issues/56841
Change-Id: Ia1a6b01327be493f003f1eea82e558bb6b147dd3
CoreLibraryReviewExempt: only internal library change
TEST=isolate_group_shared_callback_test
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422920
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-06 13:28:44 -07:00
Alexander Aprelev b32e5e5a91 [vm/shared] Throw AccessError when isolategroup mutator accesses static fields.
Sample snapshot size comparison before/after:

===
dart2js_aot.dart.snapshot before: 19946368
                          after:  19998800  (with flag turned on)
                          delta:     52432 0.26%
===

Bug: https://github.com/dart-lang/sdk/issues/54530
Bug: https://github.com/dart-lang/sdk/issues/56841
CoreLibraryReviewExempt: internal library change only
Change-Id: I34b1945c040bbad22cb3ec6fdb6e6776df31a82f
TEST=run_isolate_group_run_test.dart
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422360
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-05-06 10:42:44 -07:00
Alexander Aprelev fddb38ecab [vm/shared] Introduce IsolateGroup.runSync()
Allow dart code execution on mutator thread, do not require an isolate.

It moves some states that was kept on an isolate to thread or isolate group.

Bug: https://github.com/dart-lang/sdk/issues/54530
Bug: https://github.com/dart-lang/sdk/issues/56841

TEST=run_isolate_group_run_test

CoreLibraryReviewExempt: only internal library is being updated
Change-Id: I99df09e23954755387ea6230bfd166493d78e989
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418503
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-05 14:52:07 -07:00
Alexander Aprelev 1a6755cbf4 [vm] Clean up bool return value for EnterIsolate methods.
Effectively these methods always succeed, so return value checking just can be source of confusion.

TEST=ci
Change-Id: I0a93f130b03c0f66be733c939a1d795d704291d1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423963
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-04-24 08:33:05 -07:00
Alexander Aprelev 69485e9b28 [vm] Move origin_id from isolate to isolate group.
Isolates in one group share same origin_id anyway, so it makes sense to store it on the group too.


Remove isolate's _originNumber from service api - isolate group should be used instead.

Based on feedback from https://dart-review.git.corp.google.com/c/sdk/+/418503/21/runtime/lib/isolate.cc#107

TEST=ci
Change-Id: Iab4b6393a042c9302e911a276a6afc6dab63e70d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424140
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-04-23 15:26:21 -07:00
Ryan Macnak 3ef86d2807 [vm] Use atomics for isolate group flags.
TEST=tsan
Change-Id: I1aaa29046ff6808e9aa19b83a2854d31f1776757
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422542
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-04-15 15:04:10 -07:00
Ryan Macnak a9dd011f94 [vm] Make out-of-memory scenarios a bit more robust.
- Don't scavenge when there is no OOM reservation, so refilling the OOM reservation will get the first go once free space is available instead it being consumed by promotions.
 - Increase the desired free space in new space needed to continue scavenging. Since new space became paged, 1 KB / 64 pages only guarentees the ability to allocate a 16 byte object.
 - Stop issuing stress test reloads after an OOM is encountered.
 - Add a HANDLESCOPE to reload to make memory collectible sooner after an error.

TEST=vm/out_of_memory
Bug: https://github.com/dart-lang/sdk/issues/48920
Bug: https://github.com/dart-lang/sdk/issues/53455
Bug: https://github.com/dart-lang/sdk/issues/43642
Change-Id: Ife8bed52e341648a66f78d55bfa60b3944be5d46
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422324
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-04-15 10:39:32 -07:00
Alexander Aprelev 7c9ded3a8d [vm] Avoid mutex lock when clearing catch entry cache.
Fixes https://github.com/dart-lang/sdk/issues/60535
TEST=iso_stress_linux ci

Change-Id: I8f7c6faf23645f6e35b9abdf5b5e8a3684879624
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422346
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-04-14 12:33:19 -07:00
Alexander Aprelev 7a44485843 [vm] Move catch_entry_cache, handler_info_cache to IsolateGroup.
This should help speeding up new isolate creation (or running dart code on mutator thread when it is supported).

TEST=ci

Change-Id: I88b5deeb33e72694cb3e2727cf5668ce15fd8c6b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420361
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-04-08 09:13:39 -07:00
Ryan Macnak 49bf6449d0 [vm] Fix race between Page::Deallocate during isolate group shutdown and Page::Cleanup during Dart_Cleanup.
Dart_Cleanup waited only for the isolate group to be unregistered, which happens before the group's heap is deleted.

TEST=tsan
Change-Id: I20046516635adbcbf63eae460d7b09e7e26169d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416283
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-03-18 14:53:50 -07:00