This change removes code duplication between
LoadIndexedInstr::representation() and
StoreIndexedInstr::RequiredInputRepresentation(), multiplied by 4
target architectures.
This change also removes duplicated logic from FFI load and store
intrinsics.
TEST=ci
Change-Id: I9f10cc8c70288ecaea33a337a880c181ecbfcd6a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194281
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
This CL enables tree shaking of `Struct` sub classes by simulating the
native behavior in Dart code.
We call the struct constructors in let expressions where FFI trampolines
are created which allocate these struct objects in native code. This way
TFA is instructed about the native behavior. The VM recognizes these
constructor calls as dead code and removes them.
For more info see go/dart-ffi-struct-treeshaking.
Closes: https://github.com/dart-lang/sdk/issues/38721
This CL fixes the types on the generated #fromTypedDataBase constructors.
Also, this CL also cleans up the struct naming:
* _addressOf -> _typedDataBase
* _fromPointer -> _fromTypedDataBase
* #pointer -> #typedDataBase
These cleanups are not split into a separate CL to prevent updating
the .expect files multiple times.
Finally, this CL enables running a single transformer test through:
`dart pkg/vm/test/transformations/type_flow/transformer_test.dart name`
TEST=pkg/vm/testcases/transformations/type_flow/transformer/ffi_struct_constructors.dart
TEST=tests/ffi(_2)/function_callbacks_structs_by_value_generated_test.dart
TEST=tests/ffi(_2)/function_structs_by_value_generated_test.dart
Change-Id: I418d0d73bc86b234dfe5b7b04ae726c33d2b8aeb
Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-debug-arm64-try,vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,dart-sdk-linux-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193661
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Previously, FFI store could use kUnboxedUint32 for value being stored
via 8-bit or 16-bit StoreIndexed instruction. However, such
StoreIndexed instructions require kUnboxedIntPtr representation.
Due to the mismatch in the representations, SelectRepresentations
pass inserts a speculative (deoptimizing) IntConverter instruction,
which cases crash in AOT mode. Similar problem exists for FFI loads.
This change corrects representation when unboxing value in the body
of FFI store intrinsics and when boxing the value in FFI loads,
so representation of the value matches representation required by
StoreIndexed / returned by LoadIndexed.
TEST=ffi/regress_flutter79441_test
Fixes https://github.com/flutter/flutter/issues/79441
Change-Id: Ida144e8d2e7a69d6767c9d4447bb20e79d847d48
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193824
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Attempts to acquire safepoint lock while in SafepointOperationScope could result
in deadlocks if somebody else was holding that lock when they were forced to a safepoint.
Clean up few places where locks were acquired in SafepointOperationScope.
Introduce StoppedMutatorsScope and GroupDebugger::RunUnderReadLockIfNeeded that acquires
a lock only if it runs outside of StoppedMutatorsScope - to prevent such deadlocks.
Also fix tsan warning about data race around message_notify_callback by making it atomic.
TEST=tsan runs of debugger CI tests
Fixes https://github.com/dart-lang/sdk/issues/45527
Fixes https://github.com/dart-lang/sdk/issues/45549
Issue https://github.com/dart-lang/sdk/issues/36097
Change-Id: Ibb53d9ce760d869e044e17075aeebf20fc0016a5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193582
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Before value is stored into Float32List, it is converted to 32-bit
float using DoubleToFloat instruction. If allocation sinking
eliminated the allocation of Float32List but we need to deoptimize,
the list is materialized and elements are filled. In such case,
we shouldn't perform double->float conversion as it already happened.
This change also updates the assertion in DoubleToFloatInstr::Canonicalize
which verifies that DoubleToFloat instruction can be used only
in certain cases.
TEST=tests/language/vm/allocation_sinking_arrays_test.dart
Fixes https://github.com/dart-lang/sdk/issues/45547
Change-Id: I9a1bd28a9fc09bccad6aa3c91a7880abd002f7c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193831
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Dart code did not expect OSError as a return value from Socket_GetPort.
This CL ensures that Dart code handles OSError in addition to int gracefully as a result of Socket_GetPort call.
Fixes https://github.com/dart-lang/sdk/issues/45116
TEST=run dart ci socket tests on mac with transparent proxy running
Change-Id: I198d99107729ccefecd9a16b71474ccdbfc0039b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193221
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
OSThread::GetCurrentThreadId() is used in many places throughout
the vm, particularly in facilities that are used heavily, such as
SafepointRwLock. The high frequency of invocations means that the
runtime overhead of getting the current thread id has a significant
impact on the overall performance of the vm.
The current Fuchsia implemention of OSThread::GetCurrentThreadId()
makes a syscall to get the koid of the current thread's handle,
resulting in hundreds of nanoseconds of unnecessary overhead per
invocation.
This patch changes to using the thread's handle as the id, which is
guaranteed to be unique for the lifetime of the thread, unless it
is closed prematurely (nothing in the vm does this). This approach
is similar to what MUSL libc (the libc used by Fuchsia) does for
the same purpose and has significant mileage.
Bug: b/182183059
TEST=existing ci test suite; manually deployed into Fuchsia build.
Change-Id: I274a793a823a717c8dd206b396001c6acb897b9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193643
Reviewed-by: Chase Latta <chaselatta@google.com>
Commit-Queue: Chase Latta <chaselatta@google.com>
This change extends EqualityCompare IL instruction to handle case
when operands are nullable ints.
Unlike CheckedSmiComparison, EqualityCompare performs comparison
without making a dynamic call on a slow path. Dynamic call in
CheckedSmiComparison is a problem because it is not present in
the original program and not properly tracked in TFA and precompiler,
so precompiler is not able to drop Code objects (needed for
dynamic calls) reliably.
This change removes the remaining case when CheckedSmiComparison
instruction was used. The cleanup will follow in a separate CL.
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/32166
Issue: https://github.com/dart-lang/sdk/issues/44852
Change-Id: I8114a2616becf632462d4cb3bfc255691f24e1ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193447
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Function type parameters in occurring in constants were using an offset
based on the context in which the constant first occurred. This meant
that function type parameters occurring in a generic context would have
a different offset that those occurring in a non-generic context.
The loading of .dill in ast_from_binary would read all constants outside
the context and would therefore get the indices wrong on generic
function types.
This CL changes the encoding of these type parameters to always use
a fresh context.
Closes#45415
TEST=pkg/front_end/testcases/generic_metadata/from_dill/main.dart
Change-Id: Ifdaedb4581f1e022c908fc58a58ceac3d7b0900e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193481
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Add helper on DartType to compute the `NonNull` of a type and use this
instead of `withDeclaredNullability(Nullability.nonNullable).
Includes a fix in the computation of NonNull of FutureOr.
TEST=existing
Change-Id: I3399cbf89c7d3f3e90f1315b01f40957e798a1b1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193400
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Keep list of all per-isolate BreakpointLocations on isolate_group so all of them
can be traversed by isolate group when function is compiled and
GroupDebugger::NotifyCompilation() is invoked.
This also fixes data race around line_number lazy-initialization.
Issue https://github.com/dart-lang/sdk/issues/36097
TEST=existing ci test suite
Change-Id: I821b49a56cdc28da8d0c0c97e7d850995285c48a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193380
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
BreakpointLocation represents source code location, which can
correspond to multiple Functions(in case of some mixin method
mixed-in in several classes, for example).
BreakpointLocation is connected to a Function via CodeBreakpoint.
CodeBreakpoint represents some point in the generated Code in some
Function. BreakpointLocation connects to multiple
CodeBreakpoints - one per Function that source code location was
generated into.
This CL removes Function reference stored directly in BreakpointLocation
as it is misleading.
This CL also removes some source-code-related attributes(uri/token_pos)
stored in CodeBreakpoint. If CodeBreakpoint code needs that information
it can find it in BreakpointLocation it references.
This should help with further refactoring to support BreakpointLocation
that map to multiple scripts
TEST=ci
Change-Id: I41b82fddc5018ef7df61c9d3a3c4aee657cee528
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192946
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Loosening of assertion:
There is no guarantee that a static-final field has been initialized by
the time a function is compiled (in optimized mode) that uses such a
field.
We should therefore loosen the ASSERT to not require the field to be
initialized and rather allows CSE
Enabling of CSE:
In the past we had separate InitStaticField and LoadStaticField. The
load itself had no side-effects and could therefore be moved
arbitrarily. Though we couldn't allow it to be moved before it's
InitStaticField. This dependency was not explicitly made and we
therefore disabled CSE / LICM if the actual field was not initialized
(or field may be reset) - see [0].
Though after merging of InitStaticField and LoadStaticField in [1] there
is no longer a need for tracking any dependencies: The side-effects
of InitStaticField are now reported by LoadStaticField.
=> We can therefore always allow CSE of LoadStaticFieldinstr and
any code motion would respect side-effects of the instruction.
[0] https://codereview.chromium.org/1497783002
[1] https://dart-review.googlesource.com/c/sdk/+/148283
TEST=Fixes flaky test.
Closes https://github.com/dart-lang/sdk/issues/45133
Closes https://github.com/dart-lang/sdk/issues/45446
Change-Id: I4a699e9b1dc9dfec9a91208ed78ed0a0c41f5cad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192924
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Now they are only retained if one of the following is true:
* The parent is Future.wait or Future.timeout.
* The local function is a generated body of an async/async*/sync*
function.
* Symbolic stack traces are enabled.
When a local closure's parent is dropped, the parent name will
be printed as `<optimized out>` in places like exceptions.
Changes in Flutter gallery in release-sizeopt mode:
* ARM7: ROData -1.41%, Isolate snapshot -2.35%, Total snapshot -0.54%,
Isolate heap -1.38%, Total heap -1.38%
* ARM8: ROData -1.55%, Isolate snapshot -2.34%, Total snapshot -0.65%,
Isolate heap -1.41%, Total heap -1.41%
TEST=Existing tests on CI.
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try, vm-kernel-precomp-dwarf-linux-product-x64-try
Change-Id: I9d05f9e0e30e9f428eff16a15b0f1eeb974419c8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190023
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>