Commit Graph

1114 Commits

Author SHA1 Message Date
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 55f91b69a5 [vm] Remove unneeded HandleScope immediately after StackZone.
There's no point in unwinding the zone's scoped handle blocks just before deleting the entire zone.

TEST=ci
Change-Id: I364c717bffd16f727d6f2427a7b9693a83d74c13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499400
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-04-29 15:36:54 -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
Alexander Aprelev 8999b65531 [vm/cleanup] Remove unused start_callback, enable_vm_service, paused_for_messages.
TEST=ci

Change-Id: I101a355de9b0c2b36c8977c3af962a3e283a72d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/493862
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2026-04-08 10:05:40 -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
Lasse R.H. Nielsen cdd8311b14 Make VM run microtasks after an event handler throws.
Tested: Test added for fix.
Change-Id: Ifbefb01ef0caf9de80e44c44e5de4cc51bb129cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/489080
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2026-03-24 06:36:04 -07:00
Slava Egorov d7fa1ced6a [vm] Speedup profile data streaming in AOT
Current implementation of profile data streaming inherited its 
approach to symbolization from the implementation of vm-service's
get{,Perfetto}CpuSamples methods. These methods rather expensive
as they rely on CodeLookupTable to symbolize collected samples, and
constructing CodeLookupTable requires bringing all threads to safepoint
and iterating over old-space to collect code objects. This can take
significant amount of time - especially when old-space is large (e.g.
consider 1Gb+ heaps of Dart Analysis Server).

This CL rewrites profile data streaming to use a completely different
approach in AOT mode where Dart frames are not symbolized eagerly 
and instead stored in the timeline in their raw form: a pair of
an isolate group specific Mapping and a PC value relative to the start
of that mapping. At the end of streaming (or when isolate group
exits) an additional ModuleSymbols packet is emitted which provides
symbolization information for all collected frames. ModuleSymbols
mappings can be cheaply constructed from collected PCs using 
ReversePc lookup tables.

TEST=expanded existing tests

Change-Id: I56ef1dd4c9a17fb0d2e9c24e51f2e4656a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/482782
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2026-02-25 04:48:51 -08:00
Ryan Macnak f2e1df1997 [vm] Avoid deadlock in Isolate.debugName.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/62237
Change-Id: I57bfcc341e34aa9e873092e0f7ebf44bc2f95cfc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/476143
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-01-28 11:10:42 -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
Slava Egorov 0fee95455c [vm] Cleanup Profiler lifecycle
Move away from setting command line flags and calling Cleanup or Init
to reinitialize the profiler. Split starting and stopping the profiler
into separate methods and keep only one-time initialization/cleanup
in Init and Cleanup methods. Create a separate method for reconfiguring
the profiler Profiler::SetConfig.

This removes data races which were plaguing older code and makes it
simpler to reason about.

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

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-tsan-mac-release-arm64-try,vm-tsan-linux-release-x64-try
Change-Id: I679aa0a8724e39624e76abfad6814fe06a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472862
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2026-01-20 05:58:38 -08:00
Ryan Macnak e53115a98c [vm] Fix crash on GC after service id zone deletion.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/62154
Change-Id: Ib1ca89aa7344614de1ffc2fae6e6f93850e4a1b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/466880
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-12-08 13:17:40 -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
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 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 c1caa5c1f6 [vm/isolates] Confirm isolate terminate capability before terminating it.
Fixes https://github.com/dart-lang/sdk/issues/61313
TEST=isolate_restricted_kill_test

Change-Id: I52a41b1c71ceb02c3f91c580dc7939eb3cfae4c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445300
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-08-14 13:16:44 -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
Ryan Macnak 7973eacdd0 [vm] Rename USING_SIMULATOR to DART_INCLUDE_SIMULATOR.
We now have a mode where the simulator is available but not always used.

TEST=ci
Change-Id: If271f334150e2a125a014a4baa2e03d726300d35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435562
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-06-18 13:07:22 -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
Ryan Macnak b7e0e10f68 [vm] Fix hang in mutator slot stealing when no waiters have a timeout.
TEST=vm/dart/isolates/many_isolates_blocked_at_process_run_sync_test
Change-Id: I9d5f300c91ecfeb798f467d5624ada3baa3fb453
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427306
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-05-07 19:47: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
Ryan Macnak 81a7f3e131 [vm, gc] Remove some dead code.
- Serial scavenge
- Serial marking
- Redudant safepoint operation scope
- Redudant Thread::Current
- Unused HandleVisitor::thread_
- Profile tag updates in PRODUCT mode
- Freelist printing

TEST=ci
Change-Id: I2de4c50df37c7ebe9d267514bcbd548dd61a5a57
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426582
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-05-05 15:21:13 -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 9fa0f081cd [vm] Remove redundant VerifyOriginId.
It was made redundant by 69485e9b28, which started using isolate group id as origin id. It is populated by different random generator than the one used for isolate id.

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

Change-Id: I42545f8a491dbaa7e8b7f636df929522b4499990
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425700
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-04-30 14:00:50 -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
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
Ryan Macnak 391b9eeda4 [vm] Fix use-after-free of isolate_groups_rwlock_ during shutdown.
TEST=ffi/async_void_function_callbacks_test
Bug: https://github.com/dart-lang/sdk/issues/53248
Change-Id: I83370f2725f8b8a6bcd2fa1e5ebea2e11ae9606e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415982
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-03-17 15:28:29 -07:00
Mylo Fawcett aeb2581f30 [vm] Use toString when generating stacktrace in isolate error handler
Closes https://github.com/dart-lang/sdk/issues/50438

TEST=tests/lib/isolate/handle_error_stacktrace_test, tests/lib/isolate/handle_exiting_to_string_error_test, tests/lib/isolate/handle_throwing_to_string_error_test

Change-Id: I098153ecd65360aa724e25fc52e25368ca27ffe7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/277341
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Derek Xu <derekx@google.com>
2025-03-04 14:10:46 -08:00
Ryan Macnak 0eab4f5f78 [vm] Let active mutator stealing mark thread pool workers as blocked instead of setting the thread pool to unlimited workers.
TEST=ci (flaky resource exhaustion)
Bug: https://github.com/dart-lang/sdk/issues/54687
Change-Id: I4ba7b6ae4d5ceb460c7db883c0733434ae76de19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410641
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-02-24 10:44:28 -08:00
Liam Appelbe cb02b8726a [vm] Isolate ownership API
go/dart-isolate-ownership-api

Change-Id: Ia778a916de3fecec9f0aa1a5c8bc9fd7dd421267
Bug: https://github.com/dart-lang/native/issues/1908
TEST=runtime/vm/dart_api_impl_test.cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/407700
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
2025-02-11 20:09:11 -08:00
Ryan Macnak d9503428fa [vm, reload] Restore assertion that the reload context is gone before shutdown.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/32796
Change-Id: Idae5f2240af6069bf5bb4f1bb5868b2f39cead3d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408202
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-02-10 14:36:31 -08:00