Commit Graph

647 Commits

Author SHA1 Message Date
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
Ryan Macnak 4cf27cc968 [vm, compiler] Fix assert assembling add/subs with extended register.
This is not symmetric with add/sub, accepting ZR instead of CSP.

TEST=vm/cc/Assembler_CmpExtReg, dartfuzz
Bug: https://github.com/dart-lang/sdk/issues/60092
Change-Id: Icc24f7883a113eac504fd8fc29c0d6f781cb7657
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408901
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-02-10 15:16:50 -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
Alexander Markov f2d70cec04 [vm,arm64] Fix AddImmediate in case of CSP
Use extended register variant of add instruction when Rd or Rn
register is CSP (SP). Also fix assertion which was incorrectly
testing that Rd cannot be CSP if extended register operand is used
(actually it cannot be ZR).

TEST=vm/cc/Assembler_Drop
Fixes https://github.com/dart-lang/sdk/issues/46433

Change-Id: I542dd7bc0661b3195fa466e43cd65998c1c4ac81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408141
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-02-05 12:32:39 -08:00
Daco Harkes 5984cc8c24 [vm] Verify transitions in generated code
The transitions in C++ have asserts which run in debug mode to validate
that the transitions are happening in the right order.

The transitions in the generated code had no equivalent. This CL
introduces the equivalent for the generated code.

The transitions to generated code are misnamed currently. They come
from either VM or Native, not only Native. For example the FFI
callbacks and call return sequence can already transition from native
into the VM when entering the safepoint.

These checks don't catch the invalid FFI callbacks.
Bug: https://github.com/dart-lang/sdk/issues/60021
These are caught when looking up the FFI metadata:
https://dart-review.googlesource.com/c/sdk/+/407023

This CL omits to implement the check in ia32, since ia32 is scheduled
for removal.

The check is only enabled in debug mode. The asserts for the C++ are
also only run in debug mode. And enabling this check in release for
AOT regresses the parent CL benchmark by ~30% on Mac Arm64.

TEST=test/ffi

Change-Id: Ieaf1e43533baae294af37b2e171b68bd314fdbe0
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-mac-release-x64-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-arm64-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-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-arm64-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-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/407021
Reviewed-by: Liam Appelbe <liama@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-02-04 03:36:29 -08:00
Lasse R.H. Nielsen b99b43a657 Tweak some X64 assembler instructions to save bytes.
Changes `xorpd(r,r)` and `xorq(r, r)` to `xorps(r,r)` and `xorl(r, r)`, which saves one (REX prefix) byte and still clears the register. (At least if the register is in the first 8, otherwise a REX byte is needed just to name the register. Still better to let the compiler worry about that than hardwiring a 64-bit `q` or `pd` operation.)

Changes `andq` to `AndImmediate` which recognizes that a 32-bit or smaller immediate only needs an `andl` (again potentially saving a REX prefix).

Simplifies the code for clamping an Uint8Clamped value to have fewer branches. (If we know the value is not in the 0..255 range, two instructions can convert all negative values to zero, and all positive values to a value with the lower 8 bit set: `(~v)>>63`.)

Simplifies the code for "is infinite" to use one less 64-bit immediate (by multiplying by 2 to shift out the sign, rather than masking it out using a 63-bit mask.)




Tested: No new behavior, only optimization. Covered by existing tests.
Change-Id: I94e66c2ff39f0a207649f657e4da1ed43e4e819e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385741
Commit-Queue: Lasse Nielsen <lrn@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-01-07 06:43:29 -08:00
Ryan Macnak 88dc829f74 [vm] Fix clobbered THR/R14 in StoreReleaseLoadAcquire[1204] tests.
Also adjust expected disassembly.

TEST=ci
Cq-Include-Trybots: luci.dart.try:vm-tsan-linux-release-x64-try,vm-linux-debug-x64-try,vm-linux-release-x64-try
Change-Id: I3949145b04c84d48d98fd1629ca98b7cce617410
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397440
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-11-25 21:42:39 +00:00
Alexander Aprelev cac375a58f Revert "[vm] Fix clobbered THR/R14 in StoreReleaseLoadAcquire[1204] tests."
This reverts commit e08ce93ade.

Reason for revert: broken bot

Original change's description:
> [vm] Fix clobbered THR/R14 in StoreReleaseLoadAcquire[1204] tests.
>
> TEST=ci
> Change-Id: I8297d630b47c422b420d3d3bc8d2a6876d446eaf
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397421
> Commit-Queue: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Alexander Aprelev <aam@google.com>

Change-Id: Ib7ffbc3fb6ac59918636d75e302f0a09095e5b2d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397402
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2024-11-25 20:48:29 +00:00
Ryan Macnak e08ce93ade [vm] Fix clobbered THR/R14 in StoreReleaseLoadAcquire[1204] tests.
TEST=ci
Change-Id: I8297d630b47c422b420d3d3bc8d2a6876d446eaf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397421
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-11-25 20:30:09 +00:00
Ryan Macnak e3987ed32f [vm] Add the RISC-V Zfa extension.
TEST=ci, local qemu
Change-Id: Ifede459753ed76b3b01f09d0c0cff1c8b09bba04
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394567
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-11-13 00:57:46 +00:00
Ryan Macnak 21a1c6ce61 [vm] Add the RISC-V Zabha extension.
TEST=ci, local qemu
Change-Id: Ie00951246c3b5eaa8ce8a038b60eea100b24fd6e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394664
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-11-13 00:31:18 +00:00
Ryan Macnak 9b668be16f [vm] Add the RISC-V Zcb extension.
TEST=ci, local qemu
Change-Id: Ic9d7a1019e389a25817390dbb2f2f41daab579a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394621
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-11-12 23:50:04 +00:00
Ryan Macnak e8417935da [vm] Add the RISC-V Zicond extension.
TEST=ci, local qemu
Change-Id: I0d367b762d989b3f9bae0937c7670b175d111453
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394620
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-11-12 23:14:37 +00:00
Ryan Macnak 0a238b3828 [vm] Update to C++20.
- There is no C20, so that stays at C17
 - Math between different enum types disallowed, use explicit cast
 - operator++ removed from volatile types
 - stream print for wchar_t removed

TEST=build
Bug: https://github.com/dart-lang/sdk/issues/42074
Change-Id: Ie552b0bf24f8ac8991336c61fd4bd4913da42909
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393622
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-11-12 20:28:50 +00:00
Ryan Macnak 598de0a21e [vm] MSAN ARM64 fixes.
- Fix early exit from MemoryCopyInstr bypassing MsanUnpoison
 - Fix missing MsanUnpoison for unrolled case
 - Fix flakey failure from safepointing clobbering MsanUnpoisonParam

TEST=msan
Bug: https://github.com/dart-lang/sdk/issues/55783
Bug: https://github.com/dart-lang/sdk/issues/55794
Change-Id: Ifbf440fa8741d426643414c530c8876543451697
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394580
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-11-11 20:41:51 +00:00
Alexander Markov 0ca1ff2281 [vm/compiler] Support int32, uint32 unboxed representations in comparisons
TEST=runtime/tests/vm/dart/multiple_uint32_comparisons_il_test.dart
Fixes https://github.com/dart-lang/sdk/issues/56839

Change-Id: Ib4e0372e8def991d34b6b045d3acf62839296443
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393905
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-11-11 14:17:09 +00:00
Ryan Macnak f972499915 [vm, compiler] Generate smaller far branches on RISC-V.
TEST=ci
Change-Id: I860596aafd8b11a36f0c1090759fe22e0beb81ea
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392462
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-11-06 19:44:04 +00:00
Ryan Macnak f6f8134ef2 [vm, compiler] Fix compressed instructions for larger shift values.
TEST=ci
Change-Id: I7b49c7479cce80f91c068cf6f82d8bb4d19d45e9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393605
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-11-06 17:25:56 +00:00
Ryan Macnak b0e3448240 [vm, compiler] Fix LR/SC assembler tests.
Compare 4242ff536f.

TEST=ci
Change-Id: I3cc69504c380af02fa3869e73beef4112a60accb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393381
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-11-04 18:26:02 +00:00
Ryan Macnak f359a4367e [vm, compiler] Improve TestImmediate on RISC-V for higher single-bit tests.
Shifting the interesting bit to the sign bit is shorter than loading a large immediate.

TEST=ci
Change-Id: Ibd3dadf3885b554643e4606e8cbf83fcc6ba3d30
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/392463
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-10-30 16:40:18 +00:00
Ryan Macnak 949eb447a4 [vm, gc] Add write-write fence after initializing object headers, or defer marking new-space objects in an active TLAB.
On architectures with a weak memory model, there is the possibility that the concurrent marker can see the publishing store of a new object before it sees the initializing store of that object's header. On an M1, the barrier to prevent reordering these stores is fairly cheap, so we emit this barrier on Mac/iOS ARM64. Otherwise, this barrier is very expensive (or at least expensive for some hardware within the ABI), so instead we avoid the race by deferring marking of objects inside an active TLAB.

Disable TSAN instrumentation on the marker setting the mark bit, as TSAN does not understand fences.

TEST=ooo arm64 machines
Bug: https://github.com/dart-lang/sdk/issues/56845
Change-Id: I0676661a7cf941fdc6b451e516d890c26826bb3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389265
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2024-10-28 22:41:39 +00:00
Ryan Macnak e25601e129 [vm, compiler] Use bit-manipulation extensions when targeting Android or Fuchsia RISC-V.
Use Zbb instructions when available for ClampedUint8List stores.
Use Zba instructions when available for IntConverter zero extensions.
Fix LslImmediate(kUnsignedFourBytes) when Zba is enabled.

TEST=locally switch to RV64GCB
Change-Id: If9fc0ac3fd2c5248785322f949e2003024e5152a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385640
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-28 17:08:39 +00:00
Ryan Macnak 889e5795bb [vm, compiler] Use immediate forms for BinaryUint32Op.
dart2js.aot.arm64  28757440 -> 28691320 (-66k)
dart2js.aot.x64    28311232 -> 28310536 (-1k)
dart2js.aot.rv64   27971912 -> 27955200 (-16k)
dart2js.aot.arm32  27793504 -> 27775936 (-17k)

TEST=vm/dart/uint32_op_imm_test
Change-Id: I25e486ea1ab3b20369c0c5a5fafae5d1ea53b1c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388120
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-09 16:47:48 +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
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 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 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 a3b7c9fb5a [dart2bytecode, vm/interpreter] Small fixes
* Use AllocateClosure instruction for closure instantiations in order
  to initialize closure entry point.

* Fix null handling in operator== to be before argument type checks.

* Add _InvocationMirror._withType to dynamic interface as it is
  implicitly used by noSuchMethod forwarders.

* Fix AssertAssignable for null objects.

TEST=language tests in vm-aot-dyn-linux-debug-x64 configuration

Change-Id: I7b1a037d4fde4d22ed32969e0f099b31ea4432ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382500
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-08-29 14:28:40 +00:00
Tess Strickland 4aa25330d9 [gardening] Fix LoadIndexed native code gen on X64/IA32.
Assembler::AddressCanHoldConstantIndex, which is used by
MakeLocationSummary to determine whether to keep the index constant or
to allocate a register for it, performs the check:

  const int64_t disp =
      index * index_scale +
      (is_external ? 0 : target::Instance::DataOffsetFor(cid) - kHeapObjectTag);
  return Utils::IsInt(32, disp);

However, in Assembler::ElementAddressForIntIndex, used by EmitNativeCode to
produce an appropriate Address for the constant index, the code performs
a slightly different check:

  const int64_t disp = static_cast<int64_t>(index) * index_scale +
                       target::Instance::DataOffsetFor(cid);
  ASSERT(Utils::IsInt(32, disp));
  return FieldAddress(array, static_cast<int32_t>(disp));

Thus, if a constant index produces the displacement kMaxInt32 + 1,
MakeLocationSummary will appropriately keep the index as a constant, but
the ASSERT in ElementAddressForIntIndex will trigger.

Modify ElementAddressForIntIndex in the X64 and IA32 assemblers so that
the same displacement is checked in both places.

TEST=vm/cc/IRTest_Regress_56588

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

Change-Id: I504d6f92230540d74409a99b64b444acdb9c85f7
Cq-Include-Trybots: luci.dart.try:vm-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/382801
Auto-Submit: Tess Strickland <sstrickl@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2024-08-29 12:47:28 +00:00
Alexander Markov 8fbca8ba67 [vm] Initial implementation of dynamic modules in the VM/AOT
TEST=Manually tested dynamic modules

Change-Id: Icb2616e414167bd1fbd10f01dea64c57dbdeeac7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/380281
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-08-15 14:09:52 +00:00
Ryan Macnak c074f0375c [vm, compiler] Fix Undefined Behavior accessing the wrong bit in ARM64 disassembler.
TEST=ubsan
Change-Id: I9d4a3f22889e9728f84c6b08826e5db48311688a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375781
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2024-07-16 18:21:02 +00:00
Alexander Aprelev 4138277ee6 [vm/shared] Introduce 'vm:shared' pragma.
Decorating a field with 'vm:shared' pragma makes values in this field accessible to all isolates in an isolate group.

Introduce `channel` to the `Version` class so that the pragma can only be enabled on main and dev channels.

TEST=shared_test, shared_fail_without_flag_test
BUG=https://github.com/dart-lang/sdk/issues/55991

Change-Id: I843c9f0d2ffc9f2ced7ddc4006bb6f9ca4e2ddf4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370064
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2024-06-14 23:24:19 +00:00
Tess Strickland 324ba0c11f [vm/compiler] Extend Assembler::AddScaled to take a base register.
Add an additional base argument to Assembler::AddScaled so it now
computes:
  dest <- base + (index << scale) + offset

If base is kNoRegister (or ZR when available), then it emits
instructions optimized for computing:
  dest <- (index << scale) + offset
(i.e., its previous implementation)

Add AddScaled to AssemblerBase to ensure the same interface across all
architectures.

Rework the backend of CalculateElementAddress to use AddScaled
appropriately, which unifies it across architectures.

TEST=ci (refactoring)

Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-simriscv64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-linux-debug-simriscv64-try,vm-mac-debug-arm64-try,vm-aot-mac-release-arm64-try
Change-Id: I33c8f99604b68360f10b79050bd66ceb9d65ac9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/370504
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-06-11 08:33:29 +00:00
Ryan Macnak 6694cae4d7 [vm, gc] Incremental compaction, take 3.
- Use atomics to mark remembered cards in the write barrier stub.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/52513
Bug: https://github.com/dart-lang/sdk/issues/55754
Change-Id: I1f78c6b680a6ae9170613ba328a244335a6343e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368480
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-05-30 21:01:39 +00:00
Ryan Macnak 16f3ad9078 [vm, compiler] Assert against unpredictable forms of load/store exclusive on ARM.
Make ARM64 disassembly closer to the standard form.

TEST=ci
Change-Id: I459093abe049835c6597b80c8020566054a12b48
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368824
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-05-30 20:09:29 +00:00
Tess Strickland 5aca47f3f3 [gardening] Remove erroneous ASSERT in AddressCanHoldConstantIndex.
The ASSERT checks that there will be no overflow in computing the byte
offset from the index. However, any instruction that uses this method is
preceded by a bounds check of the index, and an index that would cause
the byte offset calculation to overflow is guaranteed to fail the bounds
check. Thus, this is dead code that will never be executed at runtime
and it is okay to emit code to perform the erroneous offset calculation.

TEST=vm/dart/regress_55864

Fixes: https://github.com/dart-lang/sdk/issues/55864
Change-Id: If4126e412368b8307be3c787ccb6bd451764c73f
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-simarm_x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/368563
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-05-30 10:09:46 +00:00
Ryan Macnak 1a9acb9171 [vm, ffi] Make callbacks profiler-safe.
Delay changing Thread::vm_tag on callback entry and restore the tag early on callback return so that the profiler doesn't see the "running Dart" tag unless it can also see the fake return address marking the entry frame.

TEST=ffi/async_void_function_callbacks, ffi/function_callbacks_subtype, ffi/function_callbacks, ffi/isolate_local_function_callbacks
Bug: https://github.com/dart-lang/sdk/issues/52814
Change-Id: I40d80ec7c44063d078db0e211565e2d127c6b81e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367460
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-05-28 21:16:41 +00:00
Daco Harkes b732c96e8a Revert "[vm, gc] Incremental compaction, take 2."
This reverts commit 9077bf991f.

Reason for revert: CBuild and TGP crashes in random Dart code which
look a lot like arbitrary memory corruption.

Original change's description:
> [vm, gc] Incremental compaction, take 2.
>
> - Fix missing store buffer flush when --marker_tasks=0.
> - Fix passing untagged pointer to store barrier check on ARM/ARM64 (6bc417dd17).
> - Fix passing uninitialized header to store barrier check on ARM64/RISCV (1447193053).
>
> TEST=ci
> Bug: https://github.com/dart-lang/sdk/issues/52513
> Bug: https://github.com/dart-lang/sdk/issues/55754
> Change-Id: Id2aa95b6d776b82d83464cde0d00e6f3b29b7b77
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367202
> Commit-Queue: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Alexander Aprelev <aam@google.com>

Bug: https://github.com/dart-lang/sdk/issues/52513
Bug: https://github.com/dart-lang/sdk/issues/55754
Change-Id: I1d70d33c65fe6bf7089b8c1422d59f9146ae7ebf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367962
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-05-23 19:00:50 +00:00
Ryan Macnak 9077bf991f [vm, gc] Incremental compaction, take 2.
- Fix missing store buffer flush when --marker_tasks=0.
- Fix passing untagged pointer to store barrier check on ARM/ARM64 (6bc417dd17).
- Fix passing uninitialized header to store barrier check on ARM64/RISCV (1447193053).

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/52513
Bug: https://github.com/dart-lang/sdk/issues/55754
Change-Id: Id2aa95b6d776b82d83464cde0d00e6f3b29b7b77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367202
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-05-21 16:33:00 +00:00
Ryan Macnak 42ec219908 Revert "[vm, gc] Incremental compaction."
This reverts commit bc0f02e4c8.

Reason for revert: https://github.com/dart-lang/sdk/issues/55754

Original change's description:
> [vm, gc] Incremental compaction.
>
> At the beginning of a major GC cycle, select some mostly-empty pages to be evacuated. Mark the pages and the objects on these pages. Apply a write barrier for stores creating old -> evacuation candidate pointers, and discover any such pointers that already exist during marking.
>
> At the end of a major GC cycle, evacuate objects from these pages. Forward pointers of objects in the remembered set and new-space. Free the evacuated pages.
>
> This compaction is incremental in the sense that creating the remembered set is interleaved with mutator execution. The evacuation step, however, is stop-the-world.
>
> Write-barrier elimination for x.slot = x is removed. Write-barrier elimination for x.slot = constant is removed in the JIT, kept for AOT but snapshot pages are marked as never-evacuate.
>
> TEST=ci
> Bug: https://github.com/dart-lang/sdk/issues/52513
> Change-Id: Icbc29ef7cb662ef8759b8c1d7a63b7af60766281
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357760
> Reviewed-by: Alexander Aprelev <aam@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

Bug: https://github.com/dart-lang/sdk/issues/52513
Change-Id: I565ad6c0fca283d33f605c10f181bc0a59e7d2b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366965
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
Auto-Submit: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-05-17 18:03:42 +00:00
Ryan Macnak bc0f02e4c8 [vm, gc] Incremental compaction.
At the beginning of a major GC cycle, select some mostly-empty pages to be evacuated. Mark the pages and the objects on these pages. Apply a write barrier for stores creating old -> evacuation candidate pointers, and discover any such pointers that already exist during marking.

At the end of a major GC cycle, evacuate objects from these pages. Forward pointers of objects in the remembered set and new-space. Free the evacuated pages.

This compaction is incremental in the sense that creating the remembered set is interleaved with mutator execution. The evacuation step, however, is stop-the-world.

Write-barrier elimination for x.slot = x is removed. Write-barrier elimination for x.slot = constant is removed in the JIT, kept for AOT but snapshot pages are marked as never-evacuate.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/52513
Change-Id: Icbc29ef7cb662ef8759b8c1d7a63b7af60766281
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357760
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-05-16 23:26:08 +00:00
Ryan Macnak d45304cd6f [vm] Add support for the Zalasr extension.
TEST=ci
Change-Id: Ic1a98751ac6b46310e420b44f487720f0dc237c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366162
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-05-14 16:40:59 +00:00
Ryan Macnak aac993f867 [vm] Remove RV_Zbc from RV_B.
The B Standard Extension has been ratified as Zba + Zbb + Zbs.

TEST=ci
Change-Id: Ifad5d68104e8f98e49a34e5a5ae76fa13c377b38
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365988
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-05-13 21:39:22 +00:00
Ryan Macnak 8c1de038e0 [vm, compiler] Allow targeting TSAN or MSAN by passing a flag to gen_snapshot.
Add check that the snapshot and runtime agree on whether to use MSAN. We already have this check for TSAN.

TEST=vm/dart/sanitizer_compatibility_test
Bug: https://github.com/dart-lang/sdk/issues/55637
Bug: https://github.com/dart-lang/sdk/issues/55638
Change-Id: I320e6f55cd59209ce6e58a82ac205a87c8a60a84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365487
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2024-05-08 17:03:59 +00:00
Vyacheslav Egorov 2a2781edff [vm] Add vm:align-loops pragma
This pragma forces compiler to align loop headers within the
function by architecture specific boundary: 32 bytes on X64
and ARM64 (with the exception of Apple Silicon, which explicitly
discourages aligning branch targets in the optimization manual).

Current implementation is rather naive and does not do any
attempt to decide whether aligning is actually profitable
based on loop body itself.

I have found this pragma to be helpful both to stabilize
benchmark results and achieve better performance
for tight loops on Intel hardware.

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

TEST=vm/dart/align_loops_test

Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-arm64-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-product-arm64-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-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,vm-aot-win-debug-x64c-try,vm-aot-win-product-x64-try,vm-aot-win-release-arm64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-simriscv64-try,vm-aot-dwarf-linux-product-x64-try,vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try
Change-Id: Ic22fb90d85e7fdebeeaa3908a43328c59436ab58
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/364121
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2024-04-24 08:52:18 +00:00
Ryan Macnak 2d0e514583 Update clang to 0f61051f541a5b8cfce25c84262dfdbadb9ca688.
Account for new -Werror,-Wcast-function-type-mismatch.

Re-run clang-format.

TEST=ci
Change-Id: I70d30548cf2e2f86b3d654962f0e73561b6e6de2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363722
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-04-19 19:46:47 +00:00
Daco Harkes f98a2138b7 [vm] Run clang-format on code base
When uploading CLs, the presubmit checks verify that the lines in the
diff are formatted correctly according to `git cl format runtime`.

However, when `buildtools/<os>-<arch>/clang/bin/clang-format` is
updated, it does not force reformatting of files that would be
reformatted.

This leads to two issues:
* Inconsistent style within the code base and within a single file.
* Spurious reformatting in CLs when (1) clang-format is used on the
  whole file, or (2) the diff lines overlap.

`clang-format` doesn't change that frequently, so in general this is
not a large issue, but I've seen a bit too many "spurious formatting,
please revert" comments on CLs recently.

This CL formats the runtime to be in line with the current pinned
`clang-format`:

```
$ find runtime/ -iname *.h -o -iname *.cc | xargs buildtools/mac-arm64/clang/bin/clang-format -i
```

`git cl format` (which only formats changed lines, and does so with
`clang-format`) seems to not agree with itself, or clang-format, or
cpplint in a handful of places. This CL adds `// clang-format off`
for these. (See previous patchsets for the specific instances.)

TEST=A variety of bots including GCC, MacOS and Windows.

Change-Id: I470892e898971899fda14bb3b8f2c8efefd67686
Cq-Include-Trybots: luci.dart.try:vm-gcc-linux-try,vm-ffi-qemu-linux-release-riscv64-try,vm-ffi-qemu-linux-release-arm-try,vm-aot-win-debug-x64-try,vm-win-debug-x64c-try,vm-mac-debug-x64-try,vm-mac-debug-arm64-try,vm-aot-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362780
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2024-04-17 19:14:41 +00:00
Ryan Macnak 7b2c672c8a [vm] Short-circuit disassembly instead of disassembling into the no-op log.
Avoids a bunch of work in the kernel and service isolates when running with --disassemble and the default --isolate-log-filter.

TEST=vm/dart/disassemble_determinism_test
Bug: https://github.com/dart-lang/sdk/issues/55421
Change-Id: Ic5da9b83ffaa3949074561aad8654ee11c041051
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362164
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-04-10 23:09:37 +00:00
Daco Harkes 2e1a56f264 [vm/msan] Fix MemCopyInstr instrumentation
The MemoryCopyInstr on x64 in MSAN mode when forward copying was
unpoisoning at the wrong pointer. The `rep mov` changes the
destination register.

Now we unpoison _before_ the `rep mov` if it's a forward copy, and
_after_ the `rep mov` for backwards copies. This way the destination
register contains the start of the memory in both cases.

TEST=tests/ffi/msan_test.dart

b/266213262
Change-Id: I37688802e63797f650a8242b6ba8b884813ebbd0
Cq-Include-Trybots: luci.dart.try:vm-msan-linux-release-x64-try,vm-aot-msan-linux-release-x64-try,vm-linux-debug-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/361420
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2024-04-08 10:40:23 +00:00