Commit Graph

16488 Commits

Author SHA1 Message Date
Ryan Macnak 52f1a4ef54 [build] Too many deps!
- Break false dependency of non-VM platforms on VM platform
 - Break false dependency of bootstrap gen_kernel on VM platform
 - Extend precompile_tools to gen_kernel steps
 - Rename intermediate kernel files so JIT versus AOT is visible in ninjatracing

TEST=ci
Change-Id: I07011abe8303597af61d2b8c73e788b661482cc0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510060
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-06-08 14:27:51 -07:00
Ryan Macnak 7b62c1be57 Revert "Remove the JIT entitlement from gen_snapshot."
This reverts commit 8dd61ee24b.

Reason for revert: gen_snapshot still flakily setting executable permissions?

Original change's description:
> Remove the JIT entitlement from gen_snapshot.
>
> gen_snapshot doesn't need the instructions it's generating to actually be executable.
>
> TEST=ci
> Change-Id: I6c542d4a07f6e6659feb22f77aca3819d7d26c78
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509060
> Reviewed-by: Tess Strickland <sstrickl@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I91ed61d719a3d9eefa66b32b535079a07c92ab59
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/510080
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-06-08 14:05:04 -07:00
Ryan Macnak 9b8d908379 Speed up RISCV QEMU testing.
- Skip/delete some large tests.
 - Reduce some large tests.
 - Explicitly choose the CPU features, which seems to be disabling something expensive.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/63465
Cq-Include-Trybots: luci.dart.try:vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try
Change-Id: Ifa591d6600da3e20c9de4d123906a7747029df7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509200
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-06-08 13:27:27 -07:00
Ryan Macnak 8dd61ee24b Remove the JIT entitlement from gen_snapshot.
gen_snapshot doesn't need the instructions it's generating to actually be executable.

TEST=ci
Change-Id: I6c542d4a07f6e6659feb22f77aca3819d7d26c78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509060
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-06-08 08:13:39 -07:00
Alexander Markov 7df4ef0cf1 [modular_aot] Fix number of optional named parameters when reading function types from module snapshot
TEST=ci

Issue: https://github.com/dart-lang/sdk/issues/61635
Change-Id: Iaa38ca6c62f9899d2c3f0363c484dbe15e0a9859
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509523
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-06-08 07:36:51 -07:00
Alexander Markov 6b9aecbe5f [vm,aot] Fix parameter type checks in the implicit setters of covariant-by-class fields
Implicit setters of covariant fields (both covariant by declaration and
covariant by class aka generic-covariant-impl) need to perform a type
check of their argument.

It means that inferred type of the field cannot be used as inferred
type of parameter of such setter. This change removes such uses of
an inferred type of the field, which restores parameter type check
which was previously incorrectly optimized out.

TEST=runtime/tests/vm/dart/regress_63419_test.dart
Fixes https://github.com/dart-lang/sdk/issues/63419

Change-Id: Ie313dbaab51dff15d60ce4390e7e41bdc66ad59d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/509020
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2026-06-03 11:32:28 -07:00
Alexander Markov 021068bb3d [modular_aot] Serialization of UndefinedConstant in module snapshots
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/61635
Change-Id: I94509fe61830174eecaec6ccfaeb13c6d20c4c27
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508707
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2026-06-03 11:32:19 -07:00
Nourhan Hasan 80f770eb57 [vm/service]: Add _readNativeMemory RPC and OS::SafeReadMemory for safe native memory inspection
- Declare OS::SafeReadMemory in os.h
- Implement using pread64(/proc/self/mem) on Linux and Android
- Add _readNativeMemory VM Service RPC with pre-checks for null
  and address overflow

TEST=runtime/vm/service_test.cc

Cq-Include-Trybots: dart/try:vm-asan-linux-release-x64-try,vm-asan-mac-release-arm64-try,vm-asan-win-release-x64-try,vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-linux-debug-arm64-try,vm-linux-debug-ia32-try,vm-linux-debug-simriscv32-try,vm-linux-debug-simriscv64-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-linux-release-simarm-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-tsan-linux-release-x64-try,vm-tsan-mac-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-ubsan-mac-release-arm64-try,vm-ubsan-win-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try
Change-Id: Id15a82bf478bc4822c08d7fdf0a5c8bfd71a1fe0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505781
Auto-Submit: Nourhan Hasan <nourhan.m.hasan@gmail.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2026-06-02 23:09:24 -07:00
Ryan Macnak 546bf07f7d [vm] Remove transitions for removing VM isolate.
TEST=ci
Change-Id: I65c315e9efc3cd7b8b47d2c167681986278644da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/502780
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-06-02 10:28:10 -07:00
Tess Strickland 4b0a4e0a75 [vm,dyn_modules] Fix vm/cc/Profiler tests for dynamic modules.
The only actual change required to the profiler service is appropriately
retrieving the source position for interpreted frames during processing.

Otherwise, most of the tests just need small changes to account for the
slightly different stack trace generated by interpreted code when
walking the stack as code instead of functions:

* Interpreted code calls the runtime entry DRT_AllocateObject directly
  for slow-path allocation instead of via the AllocateObjectSlow stub.

* The current name for bytecode frames when walked as code starts with
  "[Bytecode]" instead of "[Unoptimized]".

The test vm/cc/Profiler_GetSourceReport is skipped since:

* It tests compiled code-specific features like classifying source
  positions.

* Inserting fake samples for interpreted functions is messier since
  many PC offsets may map to the same source position.

The other skipped tests are specific to inlining and/or optimized
compiled code, so there's no point in running them on interpreted code.

TEST=vm/cc/Profiler

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try
Change-Id: I3e73f42b2562eb6e3e73fe8d5c3f14389039ee04
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507082
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2026-06-02 04:50:53 -07:00
Tess Strickland 7558e63725 [vm,dyn_modules] Change handling of source positions for async returns.
The debugger assumes a null suspend state variable in an asynchronous
function means that the function is still in the prologue prior
to setting up the suspend state. However, the interpreter clears the
suspend state variable before returning, and the debugger needs to be
able to pause before returning when single stepping, so earlier a hack
was added to the debugger that detects being at the direct call of the
async return method and/or the return instruction with a null suspend
state variable.

However, there's a much simpler way of ensuring the debugger pauses
before returning: just emit the source position for the return prior to
clearing the suspend state variable. This also ensures that the debugger
still has access to the function's suspend state when pausing before
the return, instead of waiting until it has been cleared and thus is no
longer accessible.

TEST=ci (should not change the result of any current tests)

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try
Change-Id: I401cceb169d8692ac379cdc5a531e07cafbe9a65
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/500740
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2026-06-02 04:28:41 -07:00
Ryan Macnak e59fa2e4a2 [vm] Remove dead read-only heap code.
This was part of the VM isolate.

TEST=ci
Change-Id: I831e984025c5d4d17607e8a36222bdef70bf66b8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/508240
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-06-01 13:19:29 -07:00
Tess Strickland 34c4e4799d [vm,dyn_modules] Ensure coverage arrays during source reporting.
The original iteration of adding coverage arrays originally eagerly
allocated coverage arrays for bytecode methods with recorded coverage.

Now that these coverage arrays are lazily allocated,
Function::GetCoverageArray() needs to ensure that the appropriate
coverage array has been allocated.  Otherwise, no misses within the
function are recorded in cases where no RecordCoverage instruction in
the method has yet been executed.

TEST=vm/cc/SourceReport_Coverage_UnusedClass_ForceCompile
     pkg/vm_service/test/branch_coverage_test
     pkg/vm_service/test/coverage_async_test
     pkg/vm_service/test/coverage_closure_call_after_optimization_test
     pkg/vm_service/test/coverage_closure_call_test
     pkg/vm_service/test/coverage_instance_call_after_optimization_test
     pkg/vm_service/test/coverage_static_call_after_optimization_test

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try
Change-Id: Iff4ddaf583d0f9583bc415142bdee52c046a6712
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507440
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2026-06-01 10:35:58 -07:00
Ryan Macnak 7d6c973ed9 [build] Remove the last absolute paths from RBE builds.
Extend --check-clean (enabled on bots) to verify build commands don't include absolute paths.

The non-RBE GCC and MSVC builds still have absolute paths. GCC doesn't have -ffile-compilation-dir so it uses -fdebug-prefix-map, which is not fixable. The MSVC build has absolute path in the toolchain wrappers, which might be fixable.

TEST=ci
Change-Id: I3b984aaab7aefa7ff527f0a039ca42281224a09d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506505
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-06-01 08:46:47 -07:00
Alexander Aprelev 5b0285866d Revert "Reland "[vm] Recognize int.trailingZeroBitCount/oneBitCount as graph-inlinable""
This reverts commit 415b040d6f.

Reason for revert: breaks riscv https://github.com/dart-lang/sdk/issues/63479

Original change's description:
> Reland "[vm] Recognize int.trailingZeroBitCount/oneBitCount as graph-inlinable"
>
> The previous attempt was reverted because it broke unoptimized JIT
> on ARM 32. This reland force-optimizes the two getters.
>
> Stacks on top of the int.{trailingZeroBitCount,oneBitCount} API CL
> (commit 754239b077). Both getters route through OTHER_RECOGNIZED_LIST
> when a hardware fast path is available; otherwise the newly added
> Dart bodies inline at call sites via vm:prefer-inline. The C++
> natives are removed.
>
> Backend codegen
> ---------------
> ARM64:     NEON CNT + UADDLV (popcount); RBIT + CLZ (ctz).
> ARM:       NEON CNT + VPADDL chain (popcount); RBIT + CLZ on the
>            register pair (ctz).
> x64:       popcntq when TargetCPUFeatures::popcnt_supported();
>            LoadImmediate(64) + rep_bsfq for ctz (decodes as tzcnt
>            on BMI1+, preserves dest on zero otherwise).
> RISC-V 64: cpop / ctz when RV_baseline includes Zbb.
>
> Per-arch availability is encapsulated in
> UnaryInt64OpInstr::IsSupported(Token::Kind).
>
> Apple M-series ARM64, AOT (us/iter, lower is better):
>   cardinality.swar              371
>   cardinality.accelerated       154    (2.4x)
>   forEachSetBit.swar          19031
>   forEachSetBit.accelerated    4988    (3.8x)
>   select.swar                   199
>   select.accelerated             77    (2.6x)
>   complementCardinality.swar    399
>   complementCardinality.accel   152    (2.6x)
>
> Work towards https://github.com/dart-lang/sdk/issues/6486 (popcount
> and ctz intrinsification).
>
> Work towards https://github.com/dart-lang/sdk/issues/1053 (efficient
> BitSet implementation).
>
> Fixes https://github.com/dart-lang/sdk/issues/52673
> Fixes https://github.com/dart-lang/sdk/issues/38346
> Fixes https://github.com/dart-lang/sdk/issues/63436
> Issue https://github.com/dart-lang/sdk/issues/10212
> Issue https://github.com/dart-lang/sdk/issues/5798
> TEST=tests/corelib/int_bit_count_test
>
> Cq-Include-Trybots: luci.dart.try:vm-linux-release-simarm-try,vm-ffi-qemu-linux-release-arm-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-simarm_x64-try,dart-sdk-linux-riscv64-try
> Change-Id: Ib812cbaec6e371b9720df7a543411f78e524cac1
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506060
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com>
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Commit-Queue: Martin Kustermann <kustermann@google.com>

Cq-Include-Trybots: luci.dart.try:vm-linux-release-simarm-try,vm-ffi-qemu-linux-release-arm-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-simarm_x64-try,dart-sdk-linux-riscv64-try
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: Iaf11d03d394fa615098bed8fcdea38ba40c7e45f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507520
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Kevin Moore <kevmoo@google.com>
2026-05-29 10:29:33 -07:00
Alexander Aprelev 02b30d5275 [vm/shared] Implement Isolate pinToCurrentThread, isPinnedToCurrentThread.
TEST=threading_pinning_test

Change-Id: I9a80543a06dbf51c070fed5c0e64eeba247497de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497126
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2026-05-29 07:58:23 -07:00
Modestas Valauskas 415b040d6f Reland "[vm] Recognize int.trailingZeroBitCount/oneBitCount as graph-inlinable"
The previous attempt was reverted because it broke unoptimized JIT
on ARM 32. This reland force-optimizes the two getters.

Stacks on top of the int.{trailingZeroBitCount,oneBitCount} API CL
(commit 754239b077). Both getters route through OTHER_RECOGNIZED_LIST
when a hardware fast path is available; otherwise the newly added
Dart bodies inline at call sites via vm:prefer-inline. The C++
natives are removed.

Backend codegen
---------------
ARM64:     NEON CNT + UADDLV (popcount); RBIT + CLZ (ctz).
ARM:       NEON CNT + VPADDL chain (popcount); RBIT + CLZ on the
           register pair (ctz).
x64:       popcntq when TargetCPUFeatures::popcnt_supported();
           LoadImmediate(64) + rep_bsfq for ctz (decodes as tzcnt
           on BMI1+, preserves dest on zero otherwise).
RISC-V 64: cpop / ctz when RV_baseline includes Zbb.

Per-arch availability is encapsulated in
UnaryInt64OpInstr::IsSupported(Token::Kind).

Apple M-series ARM64, AOT (us/iter, lower is better):
  cardinality.swar              371
  cardinality.accelerated       154    (2.4x)
  forEachSetBit.swar          19031
  forEachSetBit.accelerated    4988    (3.8x)
  select.swar                   199
  select.accelerated             77    (2.6x)
  complementCardinality.swar    399
  complementCardinality.accel   152    (2.6x)

Work towards https://github.com/dart-lang/sdk/issues/6486 (popcount
and ctz intrinsification).

Work towards https://github.com/dart-lang/sdk/issues/1053 (efficient
BitSet implementation).

Fixes https://github.com/dart-lang/sdk/issues/52673
Fixes https://github.com/dart-lang/sdk/issues/38346
Fixes https://github.com/dart-lang/sdk/issues/63436
Issue https://github.com/dart-lang/sdk/issues/10212
Issue https://github.com/dart-lang/sdk/issues/5798
TEST=tests/corelib/int_bit_count_test

Cq-Include-Trybots: luci.dart.try:vm-linux-release-simarm-try,vm-ffi-qemu-linux-release-arm-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-simarm_x64-try,dart-sdk-linux-riscv64-try
Change-Id: Ib812cbaec6e371b9720df7a543411f78e524cac1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506060
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2026-05-29 06:01:17 -07:00
Modestas Valauskas 062123bcf5 [vm] Remove unused Integer_parse native
The Integer_parse VM native has no Dart-side caller. int.parse is
implemented entirely in Dart in
sdk/lib/_internal/vm_shared/lib/integers_patch.dart (_tryParseSmi
and _parseRadix). Removes the native entry and drops a stale
reference in the comment on the shared ParseInteger helper, which
is still used by Integer_fromEnvironment.

TEST=ci

Change-Id: I8d034e3081c09357094abc6415fc709e3edbea07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/507322
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2026-05-29 03:37:25 -07:00
Modestas Valauskas c26cececd3 [vm/compiler] Mark BlockEntryInstr Predecessor* overrides as final.
Add `final` to PredecessorAt and PredecessorCount on the six concrete
BlockEntryInstr subclasses (GraphEntry, JoinEntry, TargetEntry,
FunctionEntry, OsrEntry, CatchBlockEntry), so the compiler can
devirtualize the calls.

Measured on a naive 49 KLOC generated lexer with --huge_method_cutoff
gates lifted and with synchronous compilation: JIT compile drops from
~30.6s to ~27.4s (about 10%).

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

TEST=ci

Change-Id: Ia2ef2761646a4c94748bcd7dfe0591262d93cd69
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505401
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com>
2026-05-29 01:08:04 -07:00
Alexander Aprelev 527d529493 [vm/shared] Implement Isolate runEventLoopSync.
TEST=ffi/threading_runeventloop_test

Change-Id: I2061d10d14bcdd589a4a9893f122620f8d0a4e7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/497100
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-05-28 11:38:29 -07:00
Ryan Macnak e991ffd37b [vm] Fix HashBytes to work with unaligned inputs.
TEST=ubsan
Bug: https://github.com/dart-lang/sdk/issues/63452
Change-Id: I112b26c08b5ae186dc5264d99edbed9e6e60368d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506660
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-05-27 12:55:21 -07:00
Alexander Aprelev 488ba69e41 [vm/shared] Introduce isolate event loop handling dart api.
Implement api methods to create and shutdown isolates from IsolateGroup-bound callbacks (normally invoked from native code), run dart code on such isolates.
The rest of the api is not implemented yet.

TEST=tests/ffi/threading_test.dart
BUG=https://github.com/dart-lang/sdk/issues/62407
CoreLibraryReviewExempt: vm-only change to isolate library
Change-Id: I0271ead8ba011dfe9d7953769415d6a88a962854
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486522
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2026-05-27 11:31:11 -07:00
Tess Strickland 7cd8fda37e [vm] Use Uint32Arrays for coverage arrays.
Also load/store canonical hashes in the heap for non-empty TypedData
instances in the same manner as canonical hashes for Arrays.

TEST=ci (refactoring only)

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try
Change-Id: I54274b558fa9f0c8e304198b18cb3f0e9c3e0dfb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504600
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2026-05-27 08:18:27 -07:00
Ryan Macnak 0ff42aac19 [vm] Fix poor hash performance of CodeSet.
Observed this taking ~2% of debug gen_snapshot time.

TEST=ci
Change-Id: I657148904fe2b5a8f3dfbd006c3d1327aa3866ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506261
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-05-27 07:21:32 -07:00
Johnni Winther a04691a8a8 [kernel][Contexts] Serialize new local variables
This adds serialization of the new local variables, VariableStatement and VariableDeclaration. This prepares for replacing LegacyVariable with the new variables in all backends.

TEST=existing

Change-Id: I9bbebfbfd372042d6b7027f0fabd24c165699832
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506240
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2026-05-27 00:41:34 -07:00
Alexander Aprelev 276cace231 [vm/mac] Fix WorkSet name confusion on flutter mac.
On mac with two WorkSet classes, WorkSet destructor from lib/isolate.cc is invoked instead of WorkSet destructor from vm/object.cc. This results in consistent assertion failures on flutter dart-debug builds on mac.

Might help with https://github.com/flutter/flutter/issues/186134

TEST=flutter test with dart-debug build

Change-Id: I9a0a0c9d02ee013da900807b8726df26a3660cc7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505661
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2026-05-26 11:21:44 -07:00
Ryan Macnak e04d2179a1 [vm] Fix quadratic cost of SNAPSHOT_BACKTRACE.
Observed this taking ~16% of debug gen_snapshot time.
Observed this taking ~52% of debug AppJIT training time.

TEST=ci
Change-Id: I945e4f3a8794e607e1402150a10f0d328fa1e677
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506260
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-05-26 09:40:40 -07:00
Modestas Valauskas c5d547fdb8 [vm/compiler] Preset far_branch_level for huge JIT-optimized functions.
When the unoptimized code of a function exceeds 1 MB, start its
optimized compile with far_branch_level=1 instead of 0. Without this,
the assembler fails on out-of-range conditional branches at level=0,
longjmps out of the optimizing pipeline, and the whole pipeline reruns
at level=1 from scratch.

Measured on a naive 49 KLOC generated lexer with --huge_method_cutoff
gates lifted: JIT compile drops from ~26.6s to ~13.2s (about 50%).

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

TEST=ci

Change-Id: I2608a23ef899603a46b401b71be7322b7a8dd44b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506120
Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2026-05-26 08:10:15 -07:00
Ryan Macnak 58ea063ca8 [vm, compiler] Fix high hash collision rate in a large run of sequential double values.
TEST=many_double_literals_test
Change-Id: Ieddaa44ddc0cc67eb8913a62daab44b5579123a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506140
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-05-26 06:42:00 -07:00
Modestas Valauskas 0a2f2ceacf [vm/compiler] Stop ConstantPropagator phi join at NonConstant.
Short-circuit the per-predecessor Join loop in
ConstantPropagator::VisitPhi once the running join has reached top.

Measured on a naive 49 KLOC generated lexer with --huge_method_cutoff
gates lifted: AOT compile drops from ~21s to ~11s (about 47%).

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

TEST=ci

Change-Id: I3103253bdba93252d4b7abcb25819a52f75b2058
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505402
Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2026-05-26 00:56:04 -07:00
Alexander Aprelev 8765d80177 Revert "[vm] Recognize int.trailingZeroBitCount/oneBitCount as graph-inlinable"
This reverts commit 0bef837817.

Reason for revert: simarm, xarm bot failures https://github.com/dart-lang/sdk/issues/63436

Original change's description:
> [vm] Recognize int.trailingZeroBitCount/oneBitCount as graph-inlinable
>
> Stacks on top of the int.{trailingZeroBitCount,oneBitCount} API CL
> (commit 754239b077). Both getters route through OTHER_RECOGNIZED_LIST
> when a hardware fast path is available; otherwise the newly added
> Dart bodies inline at call sites via vm:prefer-inline. The C++
> natives are removed.
>
> Backend codegen
> ---------------
> ARM64:     NEON CNT + UADDLV (popcount); RBIT + CLZ (ctz).
> ARM:       NEON CNT + VPADDL chain (popcount); RBIT + CLZ on the
>            register pair (ctz).
> x64:       popcntq when TargetCPUFeatures::popcnt_supported();
>            LoadImmediate(64) + rep_bsfq for ctz (decodes as tzcnt
>            on BMI1+, preserves dest on zero otherwise).
> RISC-V 64: cpop / ctz when RV_baseline includes Zbb.
>
> Per-arch availability is encapsulated in
> UnaryInt64OpInstr::IsSupported(Token::Kind).
>
> Apple M-series ARM64, AOT (us/iter, lower is better):
>   cardinality.swar              371
>   cardinality.accelerated       154    (2.4x)
>   forEachSetBit.swar          19031
>   forEachSetBit.accelerated    4988    (3.8x)
>   select.swar                   199
>   select.accelerated             77    (2.6x)
>   complementCardinality.swar    399
>   complementCardinality.accel   152    (2.6x)
>
> Work towards https://github.com/dart-lang/sdk/issues/6486 (popcount
> and ctz intrinsification).
>
> Work towards https://github.com/dart-lang/sdk/issues/1053 (efficient
> BitSet implementation).
>
> Fixes https://github.com/dart-lang/sdk/issues/52673
> Fixes https://github.com/dart-lang/sdk/issues/38346
> Issue https://github.com/dart-lang/sdk/issues/10212
> Issue https://github.com/dart-lang/sdk/issues/5798
> TEST=tests/corelib/int_bit_count_test
>
> Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-simarm_x64-try,dart-sdk-linux-riscv64-try
> Change-Id: I9c2c4225fd63d54e190398a0fb6649366317dd17
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504221
> Commit-Queue: Slava Egorov <vegorov@google.com>
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com>

Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-simarm_x64-try,dart-sdk-linux-riscv64-try
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I4eaca9e25a919ba494f2e7e9819f1ea7d5a13078
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505941
Auto-Submit: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Bot-Commit: rubber-stamper@appspot.gserviceaccount.com <rubber-stamper@appspot.gserviceaccount.com>
2026-05-22 14:22:30 -07:00
Alexander Markov d7d723327f [modular_aot] Serialization of type parameter declarations in module snapshots
TEST=ci

Issue: https://github.com/dart-lang/sdk/issues/61635
Change-Id: Ia5646ec6e2133a2232ffbbdb4926d94296bcd690
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505522
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-05-22 10:10:19 -07:00
Modestas Valauskas 0bef837817 [vm] Recognize int.trailingZeroBitCount/oneBitCount as graph-inlinable
Stacks on top of the int.{trailingZeroBitCount,oneBitCount} API CL
(commit 754239b077). Both getters route through OTHER_RECOGNIZED_LIST
when a hardware fast path is available; otherwise the newly added
Dart bodies inline at call sites via vm:prefer-inline. The C++
natives are removed.

Backend codegen
---------------
ARM64:     NEON CNT + UADDLV (popcount); RBIT + CLZ (ctz).
ARM:       NEON CNT + VPADDL chain (popcount); RBIT + CLZ on the
           register pair (ctz).
x64:       popcntq when TargetCPUFeatures::popcnt_supported();
           LoadImmediate(64) + rep_bsfq for ctz (decodes as tzcnt
           on BMI1+, preserves dest on zero otherwise).
RISC-V 64: cpop / ctz when RV_baseline includes Zbb.

Per-arch availability is encapsulated in
UnaryInt64OpInstr::IsSupported(Token::Kind).

Apple M-series ARM64, AOT (us/iter, lower is better):
  cardinality.swar              371
  cardinality.accelerated       154    (2.4x)
  forEachSetBit.swar          19031
  forEachSetBit.accelerated    4988    (3.8x)
  select.swar                   199
  select.accelerated             77    (2.6x)
  complementCardinality.swar    399
  complementCardinality.accel   152    (2.6x)

Work towards https://github.com/dart-lang/sdk/issues/6486 (popcount
and ctz intrinsification).

Work towards https://github.com/dart-lang/sdk/issues/1053 (efficient
BitSet implementation).

Fixes https://github.com/dart-lang/sdk/issues/52673
Fixes https://github.com/dart-lang/sdk/issues/38346
Issue https://github.com/dart-lang/sdk/issues/10212
Issue https://github.com/dart-lang/sdk/issues/5798
TEST=tests/corelib/int_bit_count_test

Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-simarm_x64-try,dart-sdk-linux-riscv64-try
Change-Id: I9c2c4225fd63d54e190398a0fb6649366317dd17
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504221
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com>
2026-05-22 05:58:10 -07:00
Modestas Valauskas 1d61eecafa [vm/compiler] Dedup blocks in WBE worklist.
Generalize DefinitionWorklist into a Worklist<T, E> template and use a
new BlockEntryWorklist (keyed by preorder_number) to drive the WBE
dataflow. The bitvector-backed membership set prevents the same block
from being enqueued many times, which is what caused compile time to
blow up on large generated programs.

Measured on a naive 49 KLOC generated lexer with --huge_method_cutoff
gates lifted and with synchronous compilation: AOT compile drops from
~42s to ~19s.

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

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

TEST=ci

Change-Id: I56c5dc40f534e4b28fe6b608a3b7f49e14957ef7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505461
Commit-Queue: Martin Kustermann <kustermann@google.com>
Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-05-22 03:53:47 -07:00
Ryan Macnak 2f2a523818 Fix gcc 16 build.
TEST=local build
Bug: https://github.com/dart-lang/sdk/issues/63406
Change-Id: I20c2806e569211ef7d32e95961179dbf2aba15a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/505181
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-05-20 19:36:12 -07:00
Alexander Markov c93a1c2bc3 [vm,aot] Restore generation of TTS for type arguments passed to factory constructors
This is a follow-up to https://dart-review.googlesource.com/c/sdk/+/501762.

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

Change-Id: I85386738c203a7fb27171bf904723106b764288e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504680
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-05-20 15:11:47 -07:00
Alexander Aprelev 58047e7d94 [vm/native_api] Ensure isolate is not available for duration of native port operations.
Follow-up to 5a98fe5564.

TEST=ci

Change-Id: I62269b713968f0d0e436d86b7d7b481fc5b52cc5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501620
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2026-05-20 08:40:17 -07:00
Ryan Macnak b2911c0bf1 Fix GCC build.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/63406
Change-Id: I3bb3963fcc182777c5d2c0e062ae4bbf3c5aae75
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504800
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-05-20 08:21:30 -07:00
Tess Strickland 2b9e597980 [vm] Fix CanonicalizeHash for TypedData.
Previously, the loop threw away the calculated hash value, so the
finalized hash was only the combined hash from the length plus last
byte.

Fix this, and also use 32-bit chunks as much as possible to reduce the
number of iterations for larger typed data objects.

TEST=ci

Change-Id: I0c033701232f1a1299356cab0b09079f9f86c026
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504980
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2026-05-20 06:38:42 -07:00
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
Tess Strickland 58e0b77bd6 [vm,dyn_modules] Fix source reports for enhanced enums with bytecode.
Coverage information for enhanced enums should not include initializer
functions for enum elements or the values field, so skip over these when
the enum is defined in bytecode.

TEST=vm/cc/SourceReport_Coverage_IssueCov386_EnhancedEnums

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try
Change-Id: I1dba3c87fdfcc39762bba5f0c35cfd061ec76371
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504240
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2026-05-20 06:04:16 -07:00
Ryan Macnak 6a9b9b331c [vm, compiler] Fix calculation to find the beginning of the FFI callback stub on ARM32.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/63402
Change-Id: I4aff8d6dca9aa71fd68275fd495b7dba2e119df5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/504401
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2026-05-19 09:06:20 -07:00
Tess Strickland 52cfd29cbb [vm,dynamic_modules] Add RecordCoverage instruction.
The RecordCoverage instruction has an A/E encoding. The A argument
is the type of coverage being recorded, whereas the E argument is
the logical index into the coverage array for updating whether that
source position has been hit.

Also adds new metadata to the bytecode component for the coverage
arrays associated with bytecode containing RecordCoverage instructions
and a new runtime entry for lazily allocate the coverage array for
an interpreted function when needed.

The type of coverage is encoded in the RecordCoverage instruction,
despite being redundant with the information in the coverage array, so that checking whether that type of coverage is currently enabled at
runtime doesn't require either accessing the coverage array (which may
be lazily allocated), forcing allocation of the coverage array just to
discover that type of coverage is currently disabled, or reading the
serialized bytecode component to avoid that forced allocation.

------

Other changes:

Source reporting now treats unexecuted interpreted functions when
not forcing compilation as if they were uncompiled native functions,
so that the source report from running the same code gives the same
result whether using the interpreter or the native compiler.

Bytecode closures are no longer skipped in source reports. Previously
any closure without a context scope was skipped, but bytecode closures
don't have those.

TEST=vm/cc/SourceReport_Coverage

Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try
Change-Id: I7557e5dd4c98331c7ca2f5c867dd5f6d03e9d756
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/501520
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2026-05-19 04:27:39 -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
Alexander Markov 9f3a2222fa [modular_aot] Fix reading nullability of types from module snapshots
TEST=ci

Issue: https://github.com/dart-lang/sdk/issues/61635
Change-Id: Id2b0504cf4b02ee8a2086e18901f182f2730ba5f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503960
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-05-18 08:19:41 -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
Alexander Markov 45503a1a3e [modular_aot] Instance method closurization
TEST=ci

Issue: https://github.com/dart-lang/sdk/issues/61635
Change-Id: I5e8993936b55c7cb8b581c64fd7ce8a38c9f9ee8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/503682
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2026-05-18 08:03:55 -07:00
Alexander Markov ccbcd76265 [modular_aot] Records
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/61635
Change-Id: Ie6ba4148ca9193b5b28de3d90efa7bb55427ef53
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/498660
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2026-05-18 08:03:32 -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
Eric Seidel a6a403c0b9 [vm, simarm64] Extract CalleeRegisterVerifier class
Closes https://github.com/dart-lang/sdk/pull/63012

GitOrigin-RevId: 56b29e0480f66e41ddd15e24249a5be75aed13ca
Change-Id: I55ed703a366aefd3b273acd74a6c99c91ed38759
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/491682
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-05-13 11:42:35 -07:00