Commit Graph

21778 Commits

Author SHA1 Message Date
Ryan Macnak 262b759e06 [vm] Place regexp sources in their own directory.
This makes it easier to see their cost in binary size tools.

TEST=ci
Change-Id: I6079ad9fb9b7c9450bb8d255e9a794a38ec9ae62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388641
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-08 17:28:49 +00:00
Derek Xu bdff12304d [VM/Debugger] Delete a TODO
I didn't mean to commit this TODO, it was just a reminder I left as I was working on a CL.

TEST=CI

Change-Id: I5e3f7592bd4d7d92f85b92ef44c6adf26465c772
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388380
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2024-10-08 17:23:43 +00:00
Vyacheslav Egorov 284e9e91c8 [vm] Allocation profiling via uprobes
This CL adds basic infrastructure and tooling to perform allocation
profiling using uprobes.

See runtime/tools/profiling/README.md for more details.

TEST=manually tested, requires root access

Cq-Include-Trybots: luci.dart.try:vm-aot-mac-release-arm64-try
Change-Id: Id68d181740dbf227a12d8cdba84b11a9518e75a7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382405
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-10-08 13:56:45 +00:00
Tess Strickland 2b1e82b4fe [gardening] Satisfy UBSAN for possibly negative left shifts.
TEST=vm/cc/Assembler_LslImmediate on ubsan trybots

Fixes: https://github.com/dart-lang/sdk/issues/56860
Cq-Include-Trybots: luci.dart.try:vm-ubsan-linux-release-x64-try,vm-ubsan-linux-release-arm64-try,vm-aot-ubsan-linux-release-x64-try
Change-Id: Iad1332d638af633373bbb588ea554e6a0da71c93
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388840
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-10-08 09:47:59 +00:00
Martin Kustermann f3bce39727 [tools] Hide cursor while drawing prompt in heapsnapshot analysis tool to avoid flickering cursor
Change-Id: I544bfd16a1fc5f4bbb243d66d73526995037e9bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388821
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-10-08 08:24:12 +00:00
Ryan Macnak 2142d8e148 Search in more locations for the system's root certificates.
TEST=access pub under wolfi
Bug: https://github.com/dart-lang/sdk/issues/56734
Change-Id: Ie2033d3551966180dfdf3eff1b5ef39ac0b79ce7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388080
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-07 23:33:09 +00:00
Ryan Macnak 26ce00d68c [tools] Add binary size tool.
Compared to (Chromium's) third_party/binary_size, this tool better simplifies paths and can handle `dart:` and `package:` "paths".

Cf. e32d98cd06.

Change-Id: I9e757d9ba8422024584586899481279f7fd6542d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387840
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-07 22:32:26 +00:00
Ryan Macnak 0ab55451f4 [vm] Cleanup reload debugging code.
TEST=ci
Change-Id: I840fc1a614186e0f330f4b2313a6706452af6998
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388665
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-07 22:29:49 +00:00
Ryan Macnak fa75e88591 [vm] Avoid massive vtables for IL instructions.
Implement type checks for leaf IL instructions using the instruction tag
 instead of per-type virtual functions, which scale quadratically with the number of IL instructions.

out/ReleaseX64/exe.stripped/gen_snapshot 7601248 -> 6890640 (-9.3%)

TEST=ci
Change-Id: I3d9c84c67e6ab0f3020ebb02068451e6f1c150f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388043
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-07 22:14:29 +00:00
Vyacheslav Egorov d345fbadd4 [tools] Fix heapsnapshot console crashes
`Console.cursorPosition` can return null when you are typing too
fast because it is implemented by sending an escape code to
the terminal and reading what it responds. This response is
naturally intermingled with normal input and the implementation
does nothing to guard against that.

We do not really need to know the cursor position though
we are simply interested in keeping cursor on the same row.
But this can be achieved by sending _horizontal position absolute_
which only changes column rather than _cursor position_
which sets both row and column.

R=kustermann@google.com

TEST=manually tested

Change-Id: Ie1a064e37b90bc4529ac4f5c1259642ad5680ca6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388340
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-10-07 10:53:42 +00:00
Daco Harkes 9a6503b500 [vm/ffi] Add embedder API for resolving asset ids
Extends the `NativeAssetsApi` with a `dlopen` that takes an asset id
instead of an asset path. This enables the embedder (instead of the
vm) to resolve the asset id to asset path.

Additionally, the `NativeAssetsApi` gets an `available_assets`
callback to report which asset ids are available if asset resolution
failed. (Otherwise, users would lose this important part of the error
message on failed resolution.)

We postpone migrating the Dart standalone embedder to this API: https://dart-review.googlesource.com/c/sdk/+/388160. That CL verifies
this new API and it's implementation. Without that CL this new API is
hard to test. So, no further tests are added here.

Tests that verify the old behavior for the standalone embedder:

TEST=tests/ffi/native_assets/*
TEST=pkg/dartdev/test/native_assets/*

Bug: https://github.com/flutter/flutter/issues/154425
Change-Id: I04d0fb45dc5663e63d91b21a6f5764929f10aaff
Cq-Include-Trybots: dart/try:vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,pkg-linux-debug-try,pkg-linux-release-arm64-try,pkg-mac-release-try,pkg-mac-release-arm64-try,pkg-win-release-try,pkg-win-release-arm64-try,vm-aot-asan-linux-release-x64-try,vm-asan-linux-release-x64-try,vm-aot-msan-linux-release-x64-try,vm-msan-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388161
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2024-10-04 14:17:21 +00:00
Tess Strickland b9ac6de902 [vm/compiler] Add requested change to ARM7 ArithmeticShiftRightImmediate.
This is a change to address the last comment in
https://dart-review.googlesource.com/c/sdk/+/386180, which got
accidentally submitted without it.

TEST=ci

Change-Id: I8c7b12370d282d01b3fe8b2543ec7242461aaccd
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-simarm_x64-try,vm-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388008
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-10-04 11:10:45 +00:00
Tess Strickland b23584eaa0 [vm/compiler] Add reg, reg, imm forms for lsl/asr/and assembler macros.
For non-x86 architectures, these forms directly translate to a
single instruction when possible. On x86 architectures,
XImmediate(dst, src, imm) where X is in {Lsl, ArithmeticShiftRight, And}
can be translated to:

  MoveRegister(dst, src);
  XImmediate(dst, imm);

in the general case since MoveRegister(dst, src) is a no-op if dst and
src are the same.

Also add versions of these assembler macros that take an OperandSize
and handle 32-bit OperandSizes appropriately on 64-bit architectures.

Ensure the implementation for LslImmediate and
ArithmeticShiftRightImmediate emits no instructions if shift == 0,
dst == src, and OperandSizeInBits(sz) == kBitsPerWord on all
architectures.

-----

Other changes:

Fix ConstantExpression::EmitMoveToLocation on ARM64 to match
other architectures, which allow any word-sized or less unboxed
integer representation.

Fill out ExtendValue on RISCV for previously unimplemented
OperandSizes, using the Zba and Zbb extensions when possible.

-----

TEST=vm/cc/Assembler_AndImmediate vm/cc/Assembler_LslImmediate
     vm/cc/Assembler_ArithmeticShiftRightImmediate

Separated out of https://dart-review.googlesource.com/c/sdk/+/378706
for easier debugging/reviewing.

Change-Id: I721f1334784f7011a958ea8af29f0e56c620726c
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try,vm-aot-linux-product-x64-try,vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-simarm_x64-try,vm-linux-debug-x64-try,vm-mac-debug-arm64-try,vm-mac-release-arm64-try,vm-linux-debug-ia32-try,vm-aot-android-release-arm64c-try,vm-ffi-android-debug-arm64c-try,vm-aot-linux-debug-x64c-try,vm-linux-debug-x64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386180
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-10-04 10:07:51 +00:00
Ryan Macnak 783cd7fc25 [vm] Include version information in DW_AT_producer.
This follows gcc and clang's behavior.

TEST=readelf
Change-Id: Ic009d9439d1e233afda035d0dfd2592c590c0ce2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387821
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-02 19:39:00 +00:00
Ryan Macnak 07e7ec4978 [vm] Include line numbers in DWARF abstract functions.
Tools such as nm expect source positions here and won't try to find the first position in the line number table.

TEST=vm/dart/dwarf_nm_line_numbers_test
Change-Id: I0505b03eea22a75220b4454aaa9c0cde4e9fb698
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387780
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-02 18:08:11 +00:00
Alexander Markov bea3f74a54 [vm, aot] Improve canonicalization of branch comparisons
Canonicalization

  v1 <- comparison(...)
  Branch if (StrictCompare(===, v1, true))
=>
  Branch if (comparison(...)

was not applied if comparison has unmatched representations.
However, checking for unmatched representations matters only
if comparison is speculative (in JIT mode).

Fixing this canonicalization rule improves range analysis in AOT.
As a result, range analysis can eliminate bounds check in a loop when
iterating over list using its iterator.

Also, add useful tracing to bounds check elimination code
under --trace_range_analysis.

In addition, BranchInstr::SpeculativeModeOfInput is fixed -
it should delegate to its comparison instead of returning
kGuardInputs default in order to support non-speculative
comparisons folded into branch.

Also, EqualityCompare canonicalization is now applied to
BranchInstr comparison, in order to keep optimizations which
were applied when EqualityCompare was not folded into
branches.

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

Change-Id: Ib69294d7ccf30b63dd3ff7ae5a47c0a238824952
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387622
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-10-02 15:41:20 +00:00
Ryan Macnak c7f9914497 [vm, reload] Use a more stable hash code for implicit closure functions.
The old hash code used the absolute token position, which made the hash code of a closure change for any insertions or deletions above it in the same file.

TEST=vm/cc/IsolateReload_ClosureHashStablity
Bug: https://github.com/flutter/flutter/issues/153536
Change-Id: I75da3f0cdca1862637179467ec23cf20b9878d8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387602
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-01 19:35:51 +00:00
Daco Harkes 8f23dad9d5 [vm] Remove duplicated HashMap test
TEST=removing duplicated test

Change-Id: I6c0c02166d024d1569ab18cade26de232454395e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387240
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2024-09-30 10:23:45 +00:00
Daco Harkes 0da6318273 [vm] Remove old TODO
TEST=no changes

Change-Id: Ie3fd8be0d419f4db14580cb4e082a2217cdb4190
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387241
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
2024-09-30 10:21:57 +00:00
Ben Konyi 873d709c46 [ VM ] Disable DDS for gen_snapshot_include_resolved_urls_test
This test is already slow on SIMARM configurations, spawning DDS in
SIMARM is also slow and can cause the test to timeout (e.g. on vm-aot-linux-debug-simarm_x64).

Related to https://dart-review.googlesource.com/c/sdk/+/385121

Change-Id: Icfa31d8d56efe3480d8223ef4c852322e0d652da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387201
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Derek Xu <derekx@google.com>
2024-09-27 15:37:08 +00:00
Alexander Markov d84b374683 [vm] Improve bounds check elimination in range analysis
* Infer range for CheckArrayBound and GenericCheckBound instructions.
* Extend Constraint instruction to non-Smi values bounded by list
  length.
* Unwrap UnboxInt64 during canonicalization of range boundaries.
* Use symbolic range for UnboxInt64 of list length.

As a result, bounds check can be eliminated in a loop over a growable
list:
```
  for (int i = 0; i < a.length; ++i) {
    final value = a[i];
    ...
  }
```

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

Change-Id: Ic56df18f6fbf26abf91d6ecbff24d68678dccb60
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386522
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-09-27 13:28:59 +00:00
Ben Konyi 12d9f40961 Reapply "[ CLI ] Don't disable DDS when --disable-dart-dev is provided"
This reverts commit 9f5246e8c6.

TEST=Existing tests

Change-Id: I658290f248d8b26c05f24b7125c3ba71de318bf9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385121
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2024-09-26 15:29:05 +00:00
Ryan Macnak 1c48e59c51 [vm, reload] Reverse expectations of IsolateReload_LibraryLookup.
This test expects that a library no longer being reachable along the import graph causes the library to be removed from the isolate's library list. The incremental kernel files used during reload don't really have a way to express this. The expected semantics also are a bit unsatisfactory. If a library is "deleted" this way, there may still be instances from library floating around, and re-importing the library would be treated like the addition of a new, unreleated library instead of modified the old library kept alive by those instances. Also, if an island of "deleted" libraries have static calls among themselves, those calls stop working because reresolving their targets fails because the "deleted" libraries aren't in the top-level namespace. The mistake of a global namespace continues to inflict damage.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/56785
Change-Id: I743f74d59fd9f017276a118531a58c85ac142ad0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386821
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-09-25 18:29:23 +00:00
Derek Xu 6121c396ee [VM/Service] Expose Service ID zone APIs in service.md and package:vm_service
TEST=pkg/vm_service/test/id_zones_test.dart, CI

Issue: https://github.com/dart-lang/sdk/issues/55869
CoreLibraryReviewExempt: This CL does not include any core library API
changes, only VM Service implementation changes in
sdk/lib/vmservice/running_isolates.dart.
Change-Id: Id63180fd08a88865064435b056fa3269835cd476
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/381400
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2024-09-25 17:28:44 +00:00
Alexander Markov c0e5b7e75d [vm] Correct typo in a comment
Follow-up to https://github.com/dart-lang/sdk/commit/ab19361e87a0248ade1e883f638542163f9100d1#r147196426

TEST=ci

Change-Id: Ic1c67737d5e69f063a4f62fa8c514c0b2d985e98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386682
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-09-25 16:53:52 +00:00
Alexander Markov ab19361e87 [vm] Masquerade VM internal types more consistently
VM has been hiding certain internal implementation types by
converting them to user-visible types in Object.runtimeType.

However, types of record fields were not converted,
which caused inconsistent hashCode of record types.

This change fixes this bug by applying the same type conversion to
types of record fields.

TEST=tests/language/records/type_equality_and_hash_code_test.dart
Fixes https://github.com/dart-lang/sdk/issues/56771

Change-Id: Ie02e76368de0026620d6ab278f49c14e06fd6eda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386542
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-09-25 13:46:40 +00:00
Ryan Macnak 0c3606f0ec [vm] Systematically check for failure to start thread.
Improve error message to include the intended thread name and strerror.

TEST=ci
Change-Id: Iba61a40b312f6574e8e352d51a0c3de535f6a0c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386361
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-09-24 22:41:40 +00:00
Alexander Markov 7667df56fd [gardening] Fix regress_56756_il_test on vm-aot-optimization-level-linux-release-x64
Adjust IL test to avoid much more agressive inlining on
vm-aot-optimization-level-linux-release-x64 bot.

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

Change-Id: I225049a93990c80773ff640e4a4a6fb9aad0c0fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386540
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
2024-09-24 15:04:18 +00:00
Jens Johansen 3932452322 [VM] Allow pragma to remove bounds checks for String.codeUnitAt
Follow-up to https://dart-review.googlesource.com/c/sdk/+/384540
allowing the removal of bounds checks for `String.codeUnitAt` if the
method it is called from is annotated with
`@pragma('vm:unsafe:no-bounds-checks')`.

Done by the inliner providing the calling function to the flow graph
builder and GenericCheckBound instruction utilizing this information.

TEST=Existing tests; added runtime/tests/vm/dart/no_bound_check_il_test.dart

Change-Id: Ic6144b0b8400ec6532fb58cd5fd9b3dcdb9a2ff9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385201
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2024-09-24 10:14:49 +00:00
Ryan Macnak 4de0c76294 [vm, gc] Refactor common setup code for safepoint tasks.
TEST=ci
Change-Id: I48239d109330f163307f4849ebc4139f95f524ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385620
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-09-24 00:39:48 +00:00
Ryan Macnak 2a96956cd3 Roll Clang to 3928edecfbd116d56bbe7411365d50bb567380a1.
Re-run clang-format.

TEST=ci
Change-Id: If40a619e32a17ae95c5ee39e36ef0effd07e90b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385363
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-09-23 23:36:48 +00:00
Ryan Macnak 5fb260ecb7 [vm, reload] Rehash constants again after become.
The become operation might have "merged" some constants, creating duplicating entries in a canonical table that will cause trouble for later reloads.

TEST=vm/cc/IsolateReload_EnumDeleteMultiple
Bug: https://github.com/dart-lang/sdk/issues/56583
Change-Id: I62171f2dd36e1d9294203ae998dc05a6941f77a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386321
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-09-23 23:25:50 +00:00
Ryan Macnak 9880444fd5 [vm, gc] Parallelize the stop-the-world phase of sweeping.
TEST=ci
Change-Id: I6dd09944c5dbe424b24e70f5c85d982c3c8874a7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385364
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-09-23 23:03:51 +00:00
Ryan Macnak c3b2672a19 [vm, compiler] Make use of the zero register for unboxed stores too.
dart2js.aot.rv64 19942240 -> 19925848 (-16k)

TEST=ci
Change-Id: If3d0792e28dbfa5a4183ef4363f155f7c068db47
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385660
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-09-23 21:51:31 +00:00
Alexander Markov 36054eeeaf [vm, aot] Fix inferred range of LoadClassId for nullable inputs
CompileType has a separate is_nullable() property, so
testing nullability of Dart type obtained via ToAbstractType() is not
sufficient.

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

Change-Id: Ifac09889dcd97d0b203f784a94e5b9085f3be8c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386360
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
2024-09-23 20:08:58 +00:00
Vyacheslav Egorov 34fa3c1fb5 [vm] Improve same-as-first constraint handling
All other moves generated by the register allocator to satisfy
constraints were using `PrefersRegister` for the source, but
`SameAsFirstInput` was using `Any`. This lead to situations
where hot code inside a loop would repeatedly reload a constant.
To avoid these situations switch `SameAsFirstInput` to use
`PrefersRegister` when the use occurs inside a loop.

Additionally introduce an extension of `SameAsFirstInput`:
`SameAsFirstOrSecondInput`. This new constraint allows register
allocator to reorder first and second inputs if the second one
is no longer alive after the instruction. This allows register
allocator to avoid unnecessary move.

`SameAsFirstOrSecondInput` can be used as an output constraint
for commutative binary operations on X64

Additionally this CL adds a nascent infrastructure for writing
unit tests against register allocator. See `linearscan_test.cc`.

This CL improves code quality for tight loops with binary
double operations written with constants on the left, for example:


    loop {
      doubleA = C * doubleB
    }

Before this CL `C` would be reloaded into a register immediately
before multiplication, but after this CL it will be kept in
register (if register pressure allows).

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

TEST=LinearScan_TestSameAsFirstOrSecond*

Change-Id: Id8e8242a8d1c1d1b8958076f10257e21e4a00aae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385001
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-09-20 14:47:49 +00:00
Vyacheslav Egorov bb59b5c72c [vm] Fix Instance::IdentityHashCode for strings
This method should return the same value
as `String::Hash` to not be misaligned
with how `identityHashCode()` is implemented.

On 64bit platforms we also use the same
location in the object header to store
identity hash and string hash so these two
can't be misaligned.

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

TEST=vm/cc/String,vm/dart/regress_56749
R=rmacnak@google.com

Change-Id: I221cc8ad85f7ffb7f7d2bcdd0f4341c3ecf25663
Fixed: 56749
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385860
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2024-09-18 22:30:19 +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 abf1d96d17 [vm/x64] Improve byte indexed stores
On X64 you can use `movb` instruction with any register, so there
is no need to require a fixed register. This improves the quality
of register allocation decisions around such stores.

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

TEST=ci

Change-Id: Id4d977853fec4a7900cb33c3062257735505ab8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384703
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Auto-Submit: Slava Egorov <vegorov@google.com>
2024-09-13 05:55:57 +00:00
Vyacheslav Egorov 3eef6652bf [vm] Fix performance tuning related pragmas
Make these pragmas apply to the function body even when
function is inlined into a caller.

* CheckStackOverflow is dropped directly in the flow graph builder;
* CheckBound is dropped when appending it if the caller is
marked with corresponding pragma.

These pragmas no longer have non-local effect and apply only
to the function which is marked with the pragma.

TEST=vm/cc/{CheckStackOverflowElimination_NoInterruptsPragma,BoundsCheckElimination_Pragma}

Change-Id: I9f4f9a5934d563049fe8e15e33c0432f0883ae3f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384540
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-09-12 19:57:45 +00:00
Vyacheslav Egorov 008b3b2e5e [vm] Avoid false dependency after CVTSI2S(S|D)
These instructions only write to the lower part
of the XMM register and leave upper bits intact.
This creates a false dependency of the subsequent
operations on these upper bits and leads to
stalls.

To avoid this problem we use XORPS to eagerly
break the dependency.

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

TEST=ci

Change-Id: I66892674e934e9357b4d124cbc64ecaee3a1fd6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384764
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-09-12 16:29:11 +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
Alexander Markov 24eafd67d3 [vm/interpreter] Fix return value and type arguments in constructor tear-offs
TEST=ci

Change-Id: Ibe1ede1bc1c4e044285ee3b3f75ca138d7596e8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384682
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-09-12 15:15:08 +00:00
Vyacheslav Egorov 157a0dc7f9 [vm/service] Shutdown service isolate if its main errored
If main function throws an error it might leave service isolate
in an inconsitent state and it does make sense to keep the isolate running
we might even dead lock trying to shut it down later (e.g. it might have failed
to create native port).

Flutter engine has a unit test which beings startup sequence for service
isolate and then quickly shutdowns VM - in this case vmservice main throws
and error trying to create native port. If we mark service isolate as
running at this state we will end up deadlocking in shutdown sequence
because main thread can't send exit message to the service isolate (as
we failed to create a port).

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

TEST=flutter engine unit test DartIsolateTest.CanCreateServiceIsolate

Change-Id: Ia0dc089cd31f93022708ff647950febd25eb3d7c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384482
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-09-12 12:18:02 +00:00
Vyacheslav Egorov 4ba2764a9b [vm] Avoid field guard on Compound._typedDataBase
`KernelLoader::FinishClassLoading` was leaving guarded state of this
field in an inconsistent state: it was setting guarded cid to
`kDynamicCid`, but not setting guarded length to `kNoFixedLength`.

As a result in JIT mode we would generate stale length guards
for these fields and these guards would inhibit allocation
sinking.

This CL fixes this.

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

TEST=vm/cc/Ffi_StructSinking
R=dacoharkes@google.com

Change-Id: I2eae6447555a7c1dfa25591e51815936aa3dbaf3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384842
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2024-09-12 09:18:20 +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
Ben Konyi 9f5246e8c6 Revert "[ CLI ] Don't disable DDS when --disable-dart-dev is provided"
This reverts commit 81b9957bdd.

Reason for revert: Breaking multiple configurations.

Original change's description:
> [ CLI ] Don't disable DDS when --disable-dart-dev is provided
>
> Fixes https://github.com/dart-lang/sdk/issues/56605
> Fixes https://github.com/dart-lang/sdk/issues/54841
>
> TEST=N/A
>
> Change-Id: I6a13afe5f51fe67d2366c6d87ae74473651e24c8
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383780
> Commit-Queue: Ben Konyi <bkonyi@google.com>
> Auto-Submit: Ben Konyi <bkonyi@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Phil Quitslund <pquitslund@google.com>

Change-Id: I5c6cb302d8160f19bad437341cdcd80bcc08d921
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384881
Reviewed-by: Siva Annamalai <asiva@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Derek Xu <derekx@google.com>
Auto-Submit: Ben Konyi <bkonyi@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2024-09-12 01:15:27 +00:00
Ben Konyi 6f1887a1f2 [ DDS ] Fix tests broken by https://dart-review.googlesource.com/c/sdk/+/383780
TEST=N/A

Change-Id: I50e12596ebb7dc687e4c3d408104e450c3e91c3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384900
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-09-11 21:08:58 +00:00
Ben Konyi 81b9957bdd [ CLI ] Don't disable DDS when --disable-dart-dev is provided
Fixes https://github.com/dart-lang/sdk/issues/56605
Fixes https://github.com/dart-lang/sdk/issues/54841

TEST=N/A

Change-Id: I6a13afe5f51fe67d2366c6d87ae74473651e24c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/383780
Commit-Queue: Ben Konyi <bkonyi@google.com>
Auto-Submit: Ben Konyi <bkonyi@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Phil Quitslund <pquitslund@google.com>
2024-09-11 18:01:25 +00:00
Alexander Markov ef19c7e948 [vm] Throw error if library is already loaded when loading a dynamic module
TEST=DART_CONFIGURATION=DebugX64 out/DebugX64/dart-sdk/bin/dart pkg/dynamic_modules/test/runner/main.dart -r aot --verbose

Change-Id: I4a7e59e9bb6472fc615c2fc9d9af10bf03945adb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/384325
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-09-11 14:18:06 +00:00