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>
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>
`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>
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>
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>
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>
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>
* 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>
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>
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>
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>
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>
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>
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>
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>
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>
`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>
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>