Commit Graph

463 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 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
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 e07f7eddd8 [vm] Remove dead regexp code.
TEST=ci
Change-Id: I976bcb7bf24f4a8134d5c1c5e20e8f98dc85cfbf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499082
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-04-29 08:10:43 -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
Ryan Macnak b7a36e1c0f [vm] Fix deadlocks in shared field initialization.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/62392
Change-Id: Id34b7f47c8f03c4cd0fb6555912279ee03303f23
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/474565
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-01-21 10:59:51 -08:00
Ryan Macnak 894a5fa7d5 [vm, mac] Disable TSAN during profiler sample collection.
The suspended thread might hold a TSAN-internal lock to a location that will be read by the sampling thread, which would cause a dead lock.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/62332
Change-Id: I0ac6a05c25067749b52ed83b14f80ab1850013a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471321
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-01-07 12:47:21 -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
Ryan Macnak 2a446270a4 [vm] Add missing save of shadow call stack in DartEntryScope.
Thread::saved_shadow_call_stack_ has the value for the top-most Dart entry, and needs to be saved and restored for nested Dart entries.

TEST=fuchsia
Change-Id: Id035bec7e798458fdfcf85678a7246d5f7eef850
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464603
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-11-26 10:44:51 -08:00
Slava Egorov 2282387a5b [vm] Fix profiler in PRODUCT mode.
* Make sure to start and stop profiler as mutator pauses and resumes.
* Allow profiler to call Code::GetPrologOffset without crashing
* Make sure to emit mapping with id 0 into the perfetto output if
  necessary, otherwise Perfetto UI can't load the profile

The last item seems a bug in Perfetto UI because 0 is supposed
to mean "value not set".

TEST=tested by running _perf_witness tests

Change-Id: I57578ba3efafd2aaf83c2c41b0e0b1f36a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459744
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-11-21 05:34:55 -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 7d7f461ad9 [vm] Improve packing of Thread.
Fix dart_stream_ and service_extension_stream_ appearing after the end-of-accessed-from-generated-code comment.

TEST=ci
Change-Id: I8f10d32b082125d7ed090cd118089309022c0f3e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459700
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-11-10 13:04:31 -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 73c29770fa [vm] More workarounds for false-positives in the profiler due to TSAN not understanding thread_suspend.
TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/61509
Change-Id: I4e8e2d949f4df88bb401dbe5997b59491988c05a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450102
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-09-17 11:03:00 -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 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
Ryan Macnak 51f12ffce3 [vm] Fix cross-word arm.
There seems to be a packing difference between arm and simarm_x64.

TEST=ci
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-android-debug-arm_x64-try,vm-aot-android-release-arm_x64-try
Change-Id: I2141adfb67301995f994a3de419e4316f855e4c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442505
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-07-28 19:11:11 -07:00
Ryan Macnak 5ef1c080be [vm] Rearrange some members of Thread to keep offsets within RISC-V I-type range.
TEST=ci
Cq-Include-Trybots: luci.dart.try:vm-linux-debug-simriscv32-try,vm-linux-debug-simriscv64-try,vm-aot-linux-debug-simriscv32-try,vm-aot-linux-debug-simriscv64-try
Change-Id: Ifbdb22a4454b7a6fefa44a62e4f69ea36adb1e1d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442563
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-07-28 14:52: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 e252d458e5 [vm/shared] Fix check for presence of dart mutator stack.
For GC purposes dart mutator thread could be identified by task kind, or if gc task is occupying the thread, by presence of scheduled isolate or (in case of isolategroup-shared thread) by presence of top_exit_frame.

Fixes dartbug.com/60705
TEST=ci

Change-Id: I09d212caf06e92a36efe1e5d397e5bb89846ced2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427981
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-12 07:49:30 -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
Ryan Macnak fa35265af2 [vm, gc] Fix race between BlockForSafepoint and TryStealActiveMutator.
This race can result in the stolen bit becoming cleared and the same thread stolen from multiple tests.

TEST=vm/dart/isolates/many_isolates_blocked_at_process_run_sync_test
Change-Id: I737458ff48e9d01ddfe4e5a016ef57e4cbdbf292
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425740
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-04-30 16:02:59 -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
Ryan Macnak e480c74d01 [vm] Fix corruption of null and following objects during OOM.
Array::New[Uninitialized] don't expect to get null from Object::Allocate. Using longjmp seems more robust than adding checks everywhere.

TEST=vm/dart/gc/scavenger_abort_test
Bug: https://github.com/dart-lang/sdk/issues/60552
Change-Id: I2750427c41751f8306d5c8dc28afaf052b6e9d74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422902
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-04-16 16:17:13 -07:00
Vyacheslav Egorov 8085a97a63 [vm] Fix JumpToFrame execution state transition
Instead of handling FFI related execution state and safepoint
in assembly handle it in runtime code.

The transition needs to be done before JumpToFrame unwinds
stack because unwinding destroys exit frame and this can't
be done at safepoint as GC might be traversing the stack.

An incorrect order of operation was manifesting as crashes in
GC when one isolate in a group was encountering a lot of
exceptions thrown from an FFI call and another isolate is
triggering GCs.

To catch this in the future added a bit of validation to
ExitSafepoint runtime call which triggers when --use-slow-path
is enabled. Though after refactoring this code does not
trigger this code path anymore because it was completely
removed - but it is better than nothing.

This CL also removes a lot of unnecessary complexity which
was associated with handling this transition in the stub
itself.

TEST=ffi/vmspecific_handle_test

Bug: b/408377905
Cq-Include-Trybots: dart/try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-asan-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-msan-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-ubsan-linux-release-x64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-mac-debug-simarm64_arm64-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Change-Id: Ia073cb6bb9e1b5a0ea8514c7e048cee6019b84d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/420324
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2025-04-07 05:22:56 -07:00
Alexander Aprelev e0dc78bbf6 [vm/oom] If unable to create OOM stack trace, report OOM without stack trace.
Fixes flaky out_of_memory tests failures.

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

Change-Id: I5c9192c6cc25660e83f6c03d4293360c353b02d1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419583
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-04-02 13:09:52 -07:00
Ryan Macnak 101516eb18 [vm] Allow reload during FFI and native calls.
TEST=many_isolates_blocked_* under reload stress testing
Bug: https://github.com/dart-lang/sdk/issues/60098
Change-Id: Ifb9838735e1846236e30820d7d957e3a51fd9e99
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410960
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-03-12 12:33:50 -07:00
Ryan Macnak 18c0848513 [test] Directly check for blocked mutator instead of a somewhat related state.
TEST=ffi/vmspecific_callback_functions
Change-Id: I45564b22d3c6a0d6a4300f6821a0bfa492cbee4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/414824
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-03-11 16:12:33 -07:00
Ryan Macnak 530fff90c0 [vm, simarm64] Handle exceptions during FFI callbacks.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/60204
Change-Id: If746fe07a10c9c71d228ca9591f398054635fea2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/413900
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-03-10 10:14:15 -07:00
Alexander Markov ebb7e1061c [vm] Use _setjmp instead of setjmp on MacOS/iOS
setjmp is extremely expensive on MacOS/iOS as it always saves
signal mask.

Introduce DART_SETJMP / DART_LONGJMP macros to use _setjmp instead of
setjmp on MacOS/iOS.

DeltaBlue on Mac/arm64 on the interpreter:
179585.3 us -> 58347.9 us. (3x faster)

TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/60205

Change-Id: I2122f2eb4d5de66ae2ef904a7034af1ed09f1d07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412320
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-02-26 14:01:44 -08:00
Ryan Macnak cb59df7acf [vm, ffi] Better handle errors that are not unhandled exceptions during FFI callbacks.
Before this change, an error reaching an FFI callback would attempt to execute the normal invocation stub from the beginning in the FFI callback's frame, which quickly crashes. After this change, the runtime recognizes this marker use of the invocation stub and returns to the FFI callback function instead.

TEST=ffi/unwind
Bug: https://github.com/dart-lang/sdk/issues/39487
Change-Id: I477cfcfc236e6cf518ebfe52860ba49e466ebf8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409562
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-02-19 09:40:34 -08:00
Alexander Markov ce600d0f50 [vm] Fix TSAN data race when accessing Thread::top_
This is a possible fix for the following benign TSAN error:

WARNING: ThreadSanitizer: data race (pid=40436)
  Read of size 8 at 0x7b7c000bfa48 by thread T6 (mutexes: write M0):
    #0 dart::Page::object_end() const out/ReleaseTSANX64/../../runtime/vm/heap/page.h (dart+0x25ade83)
    #1 dart::Page::used() const out/ReleaseTSANX64/../../runtime/vm/heap/page.h:107:34 (dart+0x25ade83)
    #2 dart::SemiSpace::used_in_words() const out/ReleaseTSANX64/../../runtime/vm/heap/scavenger.h:46:18 (dart+0x25ade83)
    #3 dart::Scavenger::UsedInWords() const out/ReleaseTSANX64/../../runtime/vm/heap/scavenger.h:157:17 (dart+0x25ade83)
    #4 dart::GetProcessMemoryUsageHelper(dart::JSONStream*)::$_0::operator()(dart::IsolateGroup*) const out/ReleaseTSANX64/../../runtime/vm/service.cc:4729:50 (dart+0x25ade83)

  Previous write of size 8 at 0x7b7c000bfa48 by thread T9:
    #0 dart::Thread::set_top(unsigned long) out/ReleaseTSANX64/../../runtime/vm/thread.h:698:34 (dart+0x2622071)
    #1 dart::Scavenger::TryAllocateFromTLAB(dart::Thread*, long) out/ReleaseTSANX64/../../runtime/vm/heap/scavenger.h:256:13 (dart+0x2622071)
    #2 dart::Scavenger::TryAllocate(dart::Thread*, long) out/ReleaseTSANX64/../../runtime/vm/heap/scavenger.h:139:12 (dart+0x2622071)
    #3 dart::Heap::AllocateNew(dart::Thread*, long) out/ReleaseTSANX64/../../runtime/vm/heap/heap.cc:84:27 (dart+0x2622071)
    #4 dart::Heap::Allocate(dart::Thread*, long, dart::Heap::Space) out/ReleaseTSANX64/../../runtime/vm/heap/heap.h:87:16 (dart+0x2416cab)

TEST=ci

Change-Id: Id9077cff2c1143adf999b2b26c941701d63cd844
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409180
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-02-11 09:39:20 -08:00
Ryan Macnak 2a08770912 [vm] If waiting for an active mutator slot for too long, steal a slot from a thread at a native safepoint.
The thread whose slot was stolen will take the slow path attempting to exit its safepoint and wait to reacquire an active mutator slot.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/54687
Change-Id: I49c4c12b38d38d7afa4df6b346c2a464f75ef6e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/406404
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-02-10 09:38:42 -08:00
Ryan Macnak 76c2573985 [vm, isolates] Fix deletion of handles when not entered into an isolate group.
Handles may only be allocated/updated/deleted by a thread whose execution state prevents GC from running.

TEST=tsan
Change-Id: Id2853e30d326642acc572dbd1c03345aaefd0f45
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398606
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-12-03 23:24:48 +00:00
Ryan Macnak 130ae2a802 [vm, isolates] Avoid three-way deadlock during isolate exit, take 2.
Give up the tasks lock before interrupting to finalize marking.

TEST=ci, tsan, rr chaos mode
Bug: https://github.com/dart-lang/sdk/issues/59574
Change-Id: I9f4ca977354b3860897654790fceb8f0e2e25aab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398580
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-12-03 20:33:49 +00:00
Ryan Macnak 85c339cc49 [vm, isolates] Set Isolate::mutator_thread_ under the thread registry lock.
Fixes data race with read in Isolate::ScheduleInterrupts.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/59649
Change-Id: I89dc54160f9c63ef5bdd9704a24e6eaeee1b3f4a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398543
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-12-03 20:18:20 +00:00
Alexander Markov 1225b45bc7 [dart2bytecode, vm/interpreter] Async exceptions
TEST=ci (vm-aot-dyn-linux-debug-x64)

Change-Id: I9d5bb0f7f2544e41078ec9aeb75bce6224087976
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383706
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-09-09 13:44:04 +00:00
Ryan Macnak 8ab9c0a9cf Reland "[vm, gc] Run parallel GC tasks on mutator threads blocked for the safepoint instead of new thread pool workers."
Set thread execution state to VM before running safepoint tasks.

TEST=vm/cc/Splay_WeakPersistentHandle
Bug: https://github.com/dart-lang/sdk/issues/55713
Change-Id: I0318a33449772d1fc3b4248e66a5360b316eca39
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382220
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-09-03 23:14:49 +00:00
Alexander Markov ce571036e1 [vm] Cleanup legacy AssertBoolean checks
With sound null safety front-end guarantees that all logical
expressions have a non-nullable bool type, so legacy AssertBoolean
checks are no longer needed and can be removed.

TEST=ci

Change-Id: If952da7bd0ac83c43de3e5d98845c5e5d8d29f6a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382744
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-08-29 16:45:00 +00:00
Tess Strickland d3c165d7b5 Reland "[vm] Improvements in the BitField API."
This is a reland of commit bfc1a44527

Change how the partial specializations for AtomicBitFieldContainer
are written so that Visual Studio properly chooses them instead of
the base BitField template when appropriate.

TEST=Windows ARM64 CI trybots

Original change's description:
> [vm] Improvements in the BitField API.
>
> If no position is specified, then the bitfield starts at bit 0.
>
> The default size for bool BitFields is 1 instead of the remaining
> bits in the container.
>
> If the size of the value type is smaller than the remaining bits
> in the container, then the size of the value type is used as
> the default size instead.
>
> If a signed value is used in a non-sign-extended BitField, only
> the magnitude of the value is stored, not the sign bit. This means
> the actual size of the bitfield may be one less than the requested
> size in this case.
>
> If the requested size of the bitfield is larger than the size of the
> value type, a compile-time error is thrown. (For signed types, the
> requested size is allowed to be the size of the entire value, even if
> only the magnitude bits are stored.)
>
> Rework uses of BitFields to avoid using separate constants for
> bit positions/sizes except for macro-defined bitfields (which now
> are universally bool, and so size 1).
>
> TEST=vm/cc/BitFields_Defaults
>
> Change-Id: I40711c929d2e5165ce40823772beb49e8cfdb820
> Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-aot-linux-release-simarm_x64-try
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381644
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Tess Strickland <sstrickl@google.com>

Change-Id: I5e3a9e3e2a80d5689a23a0603f8f81fac1576cd3
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-aot-linux-release-simarm_x64-try,vm-win-debug-x64c-try,vm-win-release-x64-try,vm-aot-win-release-x64-try,vm-win-release-arm64-try,vm-aot-win-release-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382383
Auto-Submit: Tess Strickland <sstrickl@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2024-08-27 19:03:02 +00:00
Tess Strickland 66eca4abfd Revert "[vm] Improvements in the BitField API."
This reverts commit bfc1a44527.

Reason for revert: Broke Windows build.

Original change's description:
> [vm] Improvements in the BitField API.
>
> If no position is specified, then the bitfield starts at bit 0.
>
> The default size for bool BitFields is 1 instead of the remaining
> bits in the container.
>
> If the size of the value type is smaller than the remaining bits
> in the container, then the size of the value type is used as
> the default size instead.
>
> If a signed value is used in a non-sign-extended BitField, only
> the magnitude of the value is stored, not the sign bit. This means
> the actual size of the bitfield may be one less than the requested
> size in this case.
>
> If the requested size of the bitfield is larger than the size of the
> value type, a compile-time error is thrown. (For signed types, the
> requested size is allowed to be the size of the entire value, even if
> only the magnitude bits are stored.)
>
> Rework uses of BitFields to avoid using separate constants for
> bit positions/sizes except for macro-defined bitfields (which now
> are universally bool, and so size 1).
>
> TEST=vm/cc/BitFields_Defaults
>
> Change-Id: I40711c929d2e5165ce40823772beb49e8cfdb820
> Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-aot-linux-release-simarm_x64-try
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381644
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Tess Strickland <sstrickl@google.com>

Change-Id: I13bf2218ecc47a42f3a6091821037b51b56618fb
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-aot-linux-release-simarm_x64-try
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382380
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-08-27 10:16:48 +00:00
Tess Strickland bfc1a44527 [vm] Improvements in the BitField API.
If no position is specified, then the bitfield starts at bit 0.

The default size for bool BitFields is 1 instead of the remaining
bits in the container.

If the size of the value type is smaller than the remaining bits
in the container, then the size of the value type is used as
the default size instead.

If a signed value is used in a non-sign-extended BitField, only
the magnitude of the value is stored, not the sign bit. This means
the actual size of the bitfield may be one less than the requested
size in this case.

If the requested size of the bitfield is larger than the size of the
value type, a compile-time error is thrown. (For signed types, the
requested size is allowed to be the size of the entire value, even if
only the magnitude bits are stored.)

Rework uses of BitFields to avoid using separate constants for
bit positions/sizes except for macro-defined bitfields (which now
are universally bool, and so size 1).

TEST=vm/cc/BitFields_Defaults

Change-Id: I40711c929d2e5165ce40823772beb49e8cfdb820
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-aot-linux-release-simarm_x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381644
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-08-27 09:28:51 +00:00