Commit Graph

612 Commits

Author SHA1 Message Date
Slava Egorov bc16ca4d51 [vm] Preserve ThreadLocal value if dart::Thread is reclaimed
dart::Thread object representing Isolate's mutator can be reclaimed when
thread is suspended, so we need to preserve thread_locals on Isolate
itself.

TEST=vm/dart/thread_local_test

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

Change-Id: I7502b9bc67a07fb2e82479d3052740516a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504921
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2026-05-20 06:21:29 -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
Ryan Macnak 94347fdf01 [vm] Don't use ApiError to represent errors during startup.
With the removal of the VM isolate and less bootstrapping being repeated in the AOT runtime, ApiError cannot be instantiated until after snapshot loading succeeds.

TEST=ci
Change-Id: I5be295e87e6d6351ada40d2837825b1f93672ac7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501262
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-05-12 08:41:20 -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 e118f9cf00 [vm] Add flag to check core snapshots also match on OS and architecture.
For checking g3 roll in advance of hard requirement.

TEST=ci
Change-Id: Ia720c66941bf303af2a66e1afcb7d1c99f8e5d4c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498981
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-04-28 11:05:30 -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
Ryan Macnak e7f818b866 [vm, fuchsia] Always look for VmexResource.
TEST=ci
Bug: https://dartbug.com/52579
Change-Id: I856fb8ae5a5bc282471c1ecf3774fc49f7c5b57a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491926
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2026-03-31 19:59:09 -07:00
Ryan Macnak 1cea4f514e [vm] Gather global variables pointing into the VM isolate.
TEST=ci
Change-Id: Ia2110904f4b88aa13b06210902c5a673d9be475c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491705
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-03-31 12:55:51 -07:00
Ryan Macnak 0a30a91dd7 [vm] Update ApiNativeScope to C11 thread locals.
TEST=ci
Change-Id: Iec314b13981c0cd11f6dd28c2e881281c3a10a8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/490300
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-03-24 11:26:23 -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 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 651d22c6cc [vm] Cleanup Profiler after isolates are stopped
Otherwise methods like OSThread::EnableThreadInterrupts (called by 
ResumeThreadInternal, called by Thread::EnterIsolate) race with
Profiler::Cleanup.

The actual race is very hard to catch, but it occured on 
fuzzer bots.

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

TEST=manual testing with hundreds of processes

Change-Id: I995ef35824593a12533715b2172730916a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475640
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2026-01-26 04:34:32 -08:00
Slava Egorov 199a68ee7e [vm] Make sure to Profiler::Init if needed.
Profiler is included in PRODUCT builds if DART_INCLUDE_PROFILER is
defined - this means we have to call Profiler::Init on startup and
Profiler::Cleanup on shutdown. Otherwise trying to start or stop
profiler will segfault as these methods expect Profiler::monitor_ 
to be initialized.

This was broken by commit 0fee95455c but
not caught because we do not have PRODUCT mode tests covering this.
This CL adds an appropriate test.

TEST=pkg/perf_witness/test/recorder_server_test

Change-Id: Ia765a345f96357e42d5e1a268ac633f96a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/474642
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2026-01-22 00:28:02 -08:00
Ryan Macnak 674a42d292 [vm, compiler] Check for ASAN and MSAN violations from Dart generated code.
Inform ASAN and MSAN about reads and writes through FFI pointers or external typed data. Previously we only informed MSAN about writes, which was enough to prevent false positives in foreign code, but gave false negatives for Dart code. This mostly uses the same machinery used for TSAN, and replaces some of the existing MSAN unpoison calls.

Also fixes some marshalling of compounds by value that generate loads extending past the end of the compound.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/62221
Change-Id: Ia3573edb5a0aec32b6a57035a63e8f323a655ecc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467401
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-12-17 07:37:29 -08:00
Alexander Markov 07c7c4ea50 [vm] Generate Dart declarations for runtime offsets
TEST=dart tools/run_offsets_extractor.dart
Issue: https://github.com/dart-lang/sdk/issues/61635
Change-Id: Ic24111aa923214cfc332a8fb4677d8941a2999d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/446700
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-12-11 08:23:57 -08:00
Ryan Macnak 7708addac2 [vm, compiler] Add --target-address-sanitizer.
The throw stub will need to be different under ASAN.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/62095
Change-Id: Idd079fbab22d1c3f29c0d7e216998d54a521545c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464786
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-12-01 16:15:39 -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
Alexander Aprelev 1b6700115d [vm/tags] Reset default/current tags as thread is released.
Fixes https://github.com/dart-lang/sdk/issues/61473
TEST=ci

Change-Id: I36606a38bf282ff1cae58d6c3184cc3212df29f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449070
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-09-15 10:24:03 -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
Derek Xu ad27629118 [VM] Delete streamable_ field from UntaggedUserTag
TEST=CI

Issue: https://github.com/dart-lang/sdk/issues/61267
Change-Id: I5ae405b2edbe478b6a14aa2416e8e4ee590349cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445520
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2025-08-20 08:13:47 -07:00
Tess Strickland c9c5be0468 [vm] Fix range checks in CheckOffsets.
Adjust the checks for runtime API ranges in CheckOffsets to account for
ranges where the first index is not 0-valued when cast to an intptr_t.

TEST=ci

Change-Id: I5478f6bf44b41f0ce7d4689e0ae37cd825838a40
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/444020
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Tess Strickland <sstrickl@google.com>
2025-08-06 06:49:38 -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
Ben Konyi 60b217ff2d [ Observatory ] Remove Observatory from the Dart VM
Also cleans up some references to Observatory in various places.

Work towards https://github.com/dart-lang/sdk/issues/50233

TEST=N/A
CoreLibraryReviewExempt: Not modifying public core libraries.
Change-Id: I1f36b4e6f1fd9a59a579d719aafa599906eedb3f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429141
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2025-06-11 15:19:55 -07:00
Ryan Macnak 3d32a60b55 [vm] Fix race between VM shutdown and in-flight API call.
TEST=vm/cc/DartAPI_TimelineEvents_Loop
Change-Id: I4175fb50991f8bf842437507cc4bf18fc926889d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428622
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-05-19 10:44:33 -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
Derek Xu 2877d78576 Reland "[VM/Service] Record timeline events representing completed microtasks"
This is a reland of commit 22021cc120

I showed some excerpts of Golem results to @mraleph for varying targets
and constant CPU, patch A, and patch B. Those constants being:
  CPU: Intel Xeon
  patch A: revision=115869&patch=20143
  patch B: revision=115876
(example results:
https://golem.corp.goog/Comparison?repository=dart#targetA%3Ddart%3BmachineTypeA%3Dlinux-x64%3BrevisionA%3D115869%3BpatchA%3Dderekx-Reland---VM%2FService--Record-timeline-events-representing-completed-microtasks--4%3BtargetB%3Ddart%3BmachineTypeB%3Dlinux-x64%3BrevisionB%3D115876%3BpatchB%3DNone)

He said that this change could be relanded as long as the following
"RunTime as Score" regressions of the "dart" target were noted in the
commit message:
  - StreamSingleSubTest: -3.907% (-0.8 noise)
  - ScheduleMicrotaskTest: -12.67% (-0.6 noise)

TEST=pkg/vm_service/test/timeline_events_for_completed_microtasks_test

Original change's description:
> [VM/Service] Record timeline events representing completed microtasks
>
> TEST=pkg/vm_service/test/timeline_events_for_completed_microtasks_test
>
> CoreLibraryReviewExempt: This CL does not include any core library API
> changes, it only modifies the implementation of microtasks (by
> instrumenting them).
> Change-Id: I54d886db9519c73f9e3218a9cc1c46bc9fe9acc3
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420221
> Commit-Queue: Derek Xu <derekx@google.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>

CoreLibraryReviewExempt: This CL does not include any core library API
changes, it only modifies the implementation of microtasks (by
instrumenting them).
Change-Id: Ia7741a9bb9ab948e8d5fff1cf9abe9915e247d81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423921
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2025-04-25 08:51:22 -07:00
Derek Xu 26d1f3d77e Revert "[VM/Service] Record timeline events representing completed microtasks"
This reverts commit 22021cc120.

Reason for revert: I didn't gate stacktrace collection behind `--profile-microtasks` correctly

Original change's description:
> [VM/Service] Record timeline events representing completed microtasks
>
> TEST=pkg/vm_service/test/timeline_events_for_completed_microtasks_test
>
> CoreLibraryReviewExempt: This CL does not include any core library API
> changes, it only modifies the implementation of microtasks (by
> instrumenting them).
> Change-Id: I54d886db9519c73f9e3218a9cc1c46bc9fe9acc3
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420221
> Commit-Queue: Derek Xu <derekx@google.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I82b4a49764956254c51bd3abfee0cb3cd1b329d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423920
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Jessy Yameogo <yjessy@google.com>
Commit-Queue: Jessy Yameogo <yjessy@google.com>
Auto-Submit: Derek Xu <derekx@google.com>
2025-04-22 11:48:48 -07:00
Derek Xu 22021cc120 [VM/Service] Record timeline events representing completed microtasks
TEST=pkg/vm_service/test/timeline_events_for_completed_microtasks_test

CoreLibraryReviewExempt: This CL does not include any core library API
changes, it only modifies the implementation of microtasks (by
instrumenting them).
Change-Id: I54d886db9519c73f9e3218a9cc1c46bc9fe9acc3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420221
Commit-Queue: Derek Xu <derekx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-04-22 07:42:27 -07:00
Alexander Aprelev 4a46bed718 [vm/prealloc] Don't preallocate oom, unwind errors, stacktrace object during isolate startup.
For out-of-memory events vm reserves (and if used, then replenishes) small chunk of memory for handling those, so preallocation of oom and stacktrace is not needed.
Unwind error can be created once as part of vm launch, kept in vm isolate.

This should reduce overhead of starting new isolate.

TEST=ci

Change-Id: Ibe2c85f250a521a8e838cc5690984fe9fa287a98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419261
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-03-31 11:17:18 -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
Vyacheslav Egorov 939699a9cf [vm] Add NOTIFY_DEBUGGER_ABOUT_RX_PAGES hook
Estimated: adds ~500ms of latency per code space page allocation.

TEST=manually

Change-Id: I31bc1927fd9a775c312974a1c435d29c875d01eb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412281
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-02-28 02:24:38 -08:00
Alexander Markov 7fd0d073a9 [vm] Cleanup experimental createUriForKernelBlob API
This API was added in https://dart-review.googlesource.com/c/sdk/+/232682
in order to support one of the strategies for running macros,
but it is no longer needed.

TEST=ci

Change-Id: I8da233932351f27fd5dfd01b66f481195d7ca0e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/407540
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2025-02-03 12:55:53 -08:00
Ryan Macnak 810b842577 [vm, reload] Fix allocation on the wrong side of a safepoint transition during a failed reload.
Ignore identity reload failures during VM shutdown.

TEST=ci, rr chaos mode
Change-Id: I8ba8ccae4294f96f2e0f2b57baa74a600c8d4080
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399840
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-12-09 23:02:48 +00:00
Ryan Macnak 3feb138f61 [vm] Fix race calling Dart_CloseNativePort during/after Dart_Cleanup.
Fix race between service/kernel isolate startup and Dart_Init.

TEST=DartAPI_InvokeVMServiceMethod[_Loop] under rr chaos mode
Bug: https://github.com/dart-lang/sdk/issues/57096
Change-Id: I50a26d61efa9106ce4bff0b268e68088570f97d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397984
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-12-02 18:13:44 +00:00
Vyacheslav Egorov bf36861cb3 [vm] Fix race in NativeMessageHandler
Introduce `NativeMessageHandler::Cleanup` which
waits for all pending `NativeMessageHandler`
deletions to complete.

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

TEST=hard to distill this specific race into a test

Change-Id: Id6196f955ff7a874c07d3a11f766d74accbde96c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385780
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-09-18 21:07:59 +00:00
Vyacheslav Egorov e2efffa005 [vm] Simplify implementation of native ports
This reland commit 5a32d8bc7c with a fix
for thread leak (Issue #56717): when `ThreadPool` is shutting down
asynchronously the last worker should detach itself to prevent
leaking associated low-level data structures, because no thread will
join it.

A hang in service isolate shutdown (caused by an existing bug) was fixed by commit 157a0dc7f9.

This CL turns native ports into a thin abstraction over underlying
thread pool instead of building them as full fledged MessageHandler.

This allows to easily implement a variation of native ports which can
handle messages concurrently with the given degree of concurrency.
This type of port can be used to greatly simplify implementation of
IOService - which previously had to do its own concurrency management
on top of "single threaded" native ports. This capability is exposed
as `Dart_NewConcurrentNativePort` API.

The new implementation is in general much cleaner then the old one
with one exception: `Dart_CloseNativePort` API has unfortunate design
where underlying message handler is destroyed asynchronously and
`Dart_CloseNativePort` returns immediately without waiting for pending
tasks to complete. Implementing this on top of `ThreadPool` requires
some changes to thread pool implementation.

Issue https://github.com/dart-lang/sdk/issues/55844

Closes https://github.com/dart-lang/sdk/issues/56717

TEST=ci

Change-Id: Ic68bfb60757685afd75c80a70cdec66cc13c149b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385000
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-09-12 15:16:12 +00:00
Slava Egorov 120dac365d Revert "[vm] Simplify implementation of native ports"
This reverts commit 5a32d8bc7c.

Reason for revert: DartIsolateTest.CanCreateServiceIsolate flutter engine unit test hangs on Windows.

Original change's description:
> [vm] Simplify implementation of native ports
>
> This CL turns native ports into a thin abstraction over underlying
> thread pool instead of building them as full fledged MessageHandler.
>
> This allows to easily implement a variation of native ports which can
> handle messages concurrently with the given degree of concurrency.
> This type of port can be used to greatly simplify implementation of
> IOService - which previously had to do its own concurrency management
> on top of "single threaded" native ports. This capability is exposed
> as `Dart_NewConcurrentNativePort` API.
>
> The new implementation is in general much cleaner then the old one
> with one exception: `Dart_CloseNativePort` API has unfortunate design
> where underlying message handler is destroyed asynchronously and
> `Dart_CloseNativePort` returns immediately without waiting for pending
> tasks to complete. Implementing this on top of `ThreadPool` requires
> some changes to thread pool implementation.
>
> Issue https://github.com/dart-lang/sdk/issues/55844
>
> TEST=ci
>
> Change-Id: I062040ff233e93962ae93684e9b044d8facdaffc
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382163
> Commit-Queue: Slava Egorov <vegorov@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

Change-Id: I7de27793a54072e974bf1a9f17a07c12159a202d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384481
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2024-09-12 08:25:27 +00:00
Vyacheslav Egorov 5a32d8bc7c [vm] Simplify implementation of native ports
This CL turns native ports into a thin abstraction over underlying
thread pool instead of building them as full fledged MessageHandler.

This allows to easily implement a variation of native ports which can
handle messages concurrently with the given degree of concurrency.
This type of port can be used to greatly simplify implementation of
IOService - which previously had to do its own concurrency management
on top of "single threaded" native ports. This capability is exposed
as `Dart_NewConcurrentNativePort` API.

The new implementation is in general much cleaner then the old one
with one exception: `Dart_CloseNativePort` API has unfortunate design
where underlying message handler is destroyed asynchronously and
`Dart_CloseNativePort` returns immediately without waiting for pending
tasks to complete. Implementing this on top of `ThreadPool` requires
some changes to thread pool implementation.

Issue https://github.com/dart-lang/sdk/issues/55844

TEST=ci

Change-Id: I062040ff233e93962ae93684e9b044d8facdaffc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382163
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-09-11 13:38:24 +00:00
Alexander Aprelev f3d7a74181 [vm/shared] Snapshot initial values of shared fields.
BUG=https://github.com/dart-lang/sdk/issues/56016
BUG=https://github.com/dart-lang/sdk/issues/55991
TEST=shared_test in appjit

Change-Id: I94ee12355cea95ca1c2698ee77e7ceffe81e27e1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371944
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-06-20 17:08:10 +00:00
Jens Johansen 9b67562b4d Add 'coverage' flag, defaulting to true, but let the gn application_snapshot default it to false
Automatic set coverage when loading snapshot

TEST=Existing tests, manual inspection of reduction in sdk snapshot sizes (see data in comments in https://dart-review.googlesource.com/c/sdk/+/370501)

Change-Id: I044616144c2defeed252a6715eba1abcabffc86d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371700
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-06-18 09:10:00 +00:00
Ryan Macnak 8c1de038e0 [vm, compiler] Allow targeting TSAN or MSAN by passing a flag to gen_snapshot.
Add check that the snapshot and runtime agree on whether to use MSAN. We already have this check for TSAN.

TEST=vm/dart/sanitizer_compatibility_test
Bug: https://github.com/dart-lang/sdk/issues/55637
Bug: https://github.com/dart-lang/sdk/issues/55638
Change-Id: I320e6f55cd59209ce6e58a82ac205a87c8a60a84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365487
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2024-05-08 17:03:59 +00:00
Ben Konyi 802c80458e [ CLI ] Support --enable-asserts for aot-snapshot and exe compile modes
Fixes https://github.com/dart-lang/sdk/issues/53343

TEST=compile_test.dart

Change-Id: Ic99988fe253b8c6dd2a03121ba7d0a525633c7cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361960
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-04-09 17:58:02 +00:00
asiva 8e2acda7d6 [VM] Remove support for --no-sound-null-safety mode
This CL removes support for --no-sound-null-safety option, the VM will
only run sound null safety code.

First part of deleting support for legacy and unsound null safe code.

TEST=CI

Change-Id: I9dbed10a18ef102533d6af516ff5075297d17b74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357183
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2024-04-05 19:38:12 +00:00
Alexander Markov b9b341f4a7 [vm] Simplify and optimize method extractors
Previously, method extractors (getter functions which return
tear-offs) where implemented in the following way:

Method extractor body is an asm intrinsic which loads a few registers
and jumps to BuildMethodExtractor stubs.
BuildMethodExtractor stub loads more registers, calls AllocateClosure
stub and initializes a few fields of a closure (this stub also used
to call AllocateContext but it is no longer needed for tear-offs).
AllocateClosure allocates a closure object and initializes closure
fields.

Instead of doing 2 hops to the object allocation, method extractor
body now calls AllocateClosure stubs directly which initializes
all closure fields. This saves a jump and a handful of instructions
to load certain things on registers and set closure fields.

Assembler intrinsic for method extractor body and
architecture-specific BuildMethodExtractor stubs are now removed.

Also, as method extractors are really tiny, they are now always
inlined.

TEST=ci

Change-Id: Icfeed18414659a76c7d24d3f6f53a76c91e5bbd3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356302
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-03-11 15:56:33 +00:00
Tess Strickland 321c45e327 [vm] Update error message for incorrect extracted offsets.
The tool is now written in Dart.

TEST=ci

Change-Id: I343f57bfb008b9423ada22549b37da9c80258688
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354882
Auto-Submit: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2024-02-28 17:25:33 +00:00
Alexander Aprelev 34213ba605 [win/unwinding] Remove Windows7 handling of unwinding records API.
Bug: https://github.com/dart-lang/sdk/issues/54509
Change-Id: Ic88c864a1d9c0ef571576b4d39119ba3d0384135
TEST=ci
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/353783
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2024-02-23 04:13:39 +00:00
Ryan Macnak 78ff04c098 [vm] Shrink FinalizeBuiltinClasses.
gcc notes it exceeds the default variable tracking limit.

TEST=ci
Change-Id: If96455b91d2ab44a77e458701e5a615feae918a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/352984
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-02-21 22:27:47 +00:00
Ryan Macnak 48cbd9b322 [vm] Identify the vm isolate etc by construction not by name.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/54855
Change-Id: I31699c4343822e99a8fa275ba00dcdfa51cdd06b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/351220
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2024-02-13 23:32:01 +00:00
Ben Konyi d9797db9ea [ VM ] Inherit system isolate property on child isolate spawn
This prevents --pause-isolates-on-start and --pause-isolates-on-exit
from impacting isolates spawned from system isolates. This should be
revisited to determine if:

- Inheriting the system isolate property is actually what we want to do
  in general
- Isolate.spawn* APIs should instead include a parameter to specify an
  isolate as a system isolate

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

TEST=Manual testing

Change-Id: Ibacdea845db6344148c11bebf001e4cac3377a62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348460
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2024-02-06 23:38:53 +00:00