Commit Graph

2345 Commits

Author SHA1 Message Date
Ryan Macnak fbc25f3dff [vm, compiler] Avoid undefined behavior when tracking induction variables wraps around.
TEST=ubsan
Bug: https://github.com/dart-lang/sdk/issues/45511
Change-Id: Iaa5733dc048a811c87f479fa54fdb89bf64a0373
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193443
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-03-30 17:06:16 +00:00
Johnni Winther 13556d623f [cfe] Add DartType.toNonNull
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>
2021-03-30 10:25:28 +00:00
Alexander Aprelev 2ac0590f29 [vm/debugger] Refactor NotifyCompilation from per-isolate to per-isolate_group.
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>
2021-03-30 00:46:07 +00:00
Ryan Macnak 6a6e08b784 Reapply "[vm, compiler] Convert binary Smi ops to graph intrinsics."
Explicitly disable unboxed parameters for these functions, previously implicitly disabled by virtue of being ASM intrinsics.

TEST=ci
Change-Id: Ic810bb8400e081c5f99a49b5035031bc9edc4bf5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192044
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-03-25 21:54:44 +00:00
Alexander Markov 320ad6adb4 [vm/aot] Remove heuristic selection of checked Smi operations
TEST=existing tests

Change-Id: Id1fb01d6efa51e272636f54595393cebab3d45b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191760
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-03-25 19:18:47 +00:00
Ryan Macnak 2c371ff74e [vm, compiler] Respect --use_slow_path in CheckedSmiOp/Comparison.
TEST=ci
Change-Id: Ib2b1a9b067beb1cbeea2b12355e62a45396697f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192726
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-03-25 17:39:24 +00:00
Martin Kustermann 1453eebebc Reland "[vm/compiler] Always allow CSE of LoadStaticField & loosen assertion in AllowsCSE"
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>
2021-03-25 15:04:43 +00:00
Tess Strickland bf74cad477 [vm/compiler] Change when parents of local functions are retained.
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>
2021-03-25 13:47:03 +00:00
Martin Kustermann f41277178c Revert "[vm/compiler] Always allow CSE of LoadStaticField & loosen assertion in AllowsCSE"
This reverts commit ff1c9c9916.

Reason for revert: Most likely cause of failures in AOT, e.g.

    python tools/test.py -n dartkp-strong-linux-release-x64 co19/LanguageFeatures/nnbd/late_A06_t05

Original change's description:
> [vm/compiler] Always allow CSE of LoadStaticField & loosen assertion in AllowsCSE
>
> 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
>
> Change-Id: I547702586d980f5d02fde0e8d12b057ca4d8c363
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192740
> Commit-Queue: Martin Kustermann <kustermann@google.com>
> Reviewed-by: Vyacheslav Egorov <vegorov@google.com>

TBR=vegorov@google.com,kustermann@google.com

Change-Id: I921c6e8929bbc9f58392d6be6db599dddb8e4b4c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192922
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-03-24 14:45:13 +00:00
Martin Kustermann 6127386cfa [vm/compiler] Ensure allocate instructions have correctly pruned lazy deopt environment
Since allocation instructions can throw OOM exceptions, they require
deopt information. In general it's rather hard to test that this deopt
information is correct.

In order to test this, this CL makes those IR instructions support lazy
deopt and add tests that exercise this deopt sequence, thereby ensuring
the deoptimization environment is correct.

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

TEST=New vm/dart_2/isolates/deopt/*_test.

Change-Id: I6a02dcf5a0c47636f1f0aa4cd8cc0d2b4f032ca0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192687
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-03-24 12:48:29 +00:00
Martin Kustermann 6a585a2089 [vm/compiler] Assign deopt id to all allocation instructions
An allocation can - in the slow path - go to runtime which can cause a
pre-allocated OutOfMemory exception to be thrown. It therefore requires
correct deopt information.

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

TEST=Existing test suite. A follow-up CL will add actual deoptimization tests for those instructions.

Change-Id: Iaf44904b82ec021919352483f58e9e8fed473955
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192685
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2021-03-24 11:55:44 +00:00
Martin Kustermann bdb77e4f3d [vm/compiler] Mark all allocation IR instructions as potentially throwing
Allocation instructions can end up going to runtime - and in rare cases
- throw a pre-allocated OutOfMemory exception. We have to mark
allocation IR instructions therefore as potentially throwing.

We make this CL separately from follow-up related changes, to see
possible effects on benchmarks.

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

TEST=Existing tests. Will add validation of correct deopt environment in future CL.

Change-Id: Ic3ed5c277c222f8432f5f72da18d32182e566dac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192683
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2021-03-24 11:48:49 +00:00
Martin Kustermann ff1c9c9916 [vm/compiler] Always allow CSE of LoadStaticField & loosen assertion in AllowsCSE
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

Change-Id: I547702586d980f5d02fde0e8d12b057ca4d8c363
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192740
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-03-24 11:47:39 +00:00
Martin Kustermann 2fa31c9dbd [vm/compiler] Explicitly use near jumps in InstantiateTypeArgumentsInstr
This addresses a small performance regression introduced in a
refactoring (see [0]).

[0] https://dart-review.googlesource.com/c/sdk/+/192185

TEST=Existing test suite.

Change-Id: Ib4a7374d7172ce8a87ac608b2a0afa38cfd89a4e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192741
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2021-03-24 04:42:53 +00:00
Martin Kustermann deb946745c [vm/compiler] Correctly prune environment for lazy-deopt in IR instructions
This ensures the following IR instructions use a correctly pruned
lazy-deopt environment:

  * AssertBoolInstr
  * AssertSubtypeInstr
  * InstantiateTypeInstr
  * InstantiateTypeArgumentsInstr

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

TEST=New vm/dart_2/isolates/deopt/*_test.

Change-Id: I3d44909f0933c5df109d69e0a61f2d9d7dcc1247
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192184
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-03-23 14:03:56 +00:00
Martin Kustermann dec7b4f5b6 [vm/compiler] Avoid pruning deopt environments during SSA construction
Generally speaking, the optimizing compiler should be able to use
(deopt-id, deopt-environ) of any IR instruction and use it as an eager
deopt target (e.g. optimizing compiler might insert TestCidsInstr
with eager (deopt-id, deopt-environ) from AssertAssignable).

Currently we prune the environment eagerly during SSA construction for
some instructions This pruning breaks the above mechanism, since the
deopt-environ isn't usable as eager deopt target. (It is effectively
changing the environment on the IR instruction to be a lazy-deopt
environment).

This CL makes the [Environment] represent both the eager deopt target as
well as the lazy deopt target. It distinguishes the two by remembering
how many slots the eager deopt target needs to be pruned to come to the
lazy deopt target. The SSA construction will populate this information.

Effectively we move the deopt env pruning from SSA construction to the
place when we need it (e.g. inlining, emitting after-call metadata).

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

TEST=Refactoring of existing code.

Change-Id: I6c2a117b33f35764e556372484e4beaa294b708d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192141
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-03-23 12:22:16 +00:00
Tess Strickland e7d3a6027c [vm] Create more Function helper methods for code clarity.
Creates HasParent() as a predicate for Function objects with a non-null
parent function and makes IsLocalFunction() specific to local closures
(i.e. explicit closures with non-null parent functions).

Creates HasSavedArgumentsDescriptor() as a predicate to determine when
saved_args_desc() can be used, to avoid the caller having to do explicit
predicate checks for each dispatcher type that contains one.

Also simplifies Function::PrintName, creates different suffixes for a
SyncGenClosureMaker and its associateed SyncGenClosure, adds suffixes
for skipping more than one generated body when printing the parent name,
and changes ArgumentsDescriptor::PrintTo to match the compact syntax
Function::PrintName used for signifying the arguments descriptor for
certain dispatchers.

TEST=pkg/vm_snapshot_analysis/test/instruction_sizes_test

Cq-Include-Trybots: luci.dart.try:app-kernel-linux-release-x64-try,vm-kernel-precomp-linux-release-x64-try,pkg-linux-release-try
Change-Id: I0ac1226d1ffe1d81743b5c6788da170d5a4010c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191560
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2021-03-23 12:21:26 +00:00
Ryan Macnak 5bfb36daa3 [vm, compiler] Use leaf calls for exp and log.
We already do this for the other functions in dart:math.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/45414
Change-Id: Ic1fb1c7cdbbf39eaa4af645219874408988b740b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192522
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-03-22 23:14:25 +00:00
Vyacheslav Egorov d82ecdfe01 [vm] Fix GCC build
TEST=tools/gn.py --no-clang -m release -a x64, ninja -C out/ReleaseX64

Change-Id: I923ae50de25e8936507c665091d57870a33f7fa1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192306
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-03-22 15:08:04 +00:00
Alexander Aprelev dd9b00f7b9 [vm/concurrency/debugger] Fix lock acquisition to avoid deadlocks.
TEST=break_on_function_many_child_isolates_test flaky failures on debug build

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

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

Change-Id: I075318878f1e4b0f3f921377b0281b785274621e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192060
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-03-19 22:20:18 +00:00
Alexander Aprelev 2c5b320b14 [vm/concurrency/debugger] Fix pool patching synchronization for lightweight isolates breakpoints.
TEST=service/break_on_function_many_child_isolates_test

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

Change-Id: I15b9d9db938042c89f21700876bf75d932f044a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191781
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2021-03-19 20:24:48 +00:00
Daco Harkes 77dc74bcd5 [vm/ffi] Support packed Structs
Closes: https://github.com/dart-lang/sdk/issues/38158

This CL implements unaligned access for float/double on arm32, but does
not expose it in an API. Rather it only uses these loads/stores inside
the getters and setters of packed structs.
Bug: https://github.com/dart-lang/sdk/issues/45009

Besides unaligned access for float/double, this CL is mostly a CFE
change. The only VM change is reading the packing in the
`_FfiStructLayout` annotation.

The implementation of using the packing in the VM, and analyzer changes
have landed separately in earlier CLs.

tools/test.py ffi ffi_2
TEST=tests/ffi(_2)/(.*)by_value_(*.)_test.dart

Change-Id: Ic3106ecc626d2e30674a49bf03f65ae12d2b3502
Cq-Include-Trybots: luci.dart.try:dart-sdk-linux-try,dart-sdk-mac-try,dart-sdk-win-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-mac-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-nnbd-mac-release-x64-try,vm-kernel-nnbd-win-debug-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-msan-linux-release-x64-try,vm-kernel-precomp-msan-linux-release-x64-try,vm-kernel-precomp-android-release-arm_x64-try,analyzer-analysis-server-linux-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/186143
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2021-03-19 15:34:42 +00:00
Daco Harkes e7acc69507 [vm/ffi] Support packed Structs backend - part 2
With packed structs, the x64 non-Windows ABI only put structs in CPU/FPU
registers when all it fields happen to be aligned. The previous CL did
not check the alignment of nested structs and structs in inline arrays
based on their offset in an outer struct.

Follow up of: https://dart-review.googlesource.com/c/sdk/+/186142.
Split off: https://dart-review.googlesource.com/c/sdk/+/186143.

Bug: https://github.com/dart-lang/sdk/issues/38158

tools/build.py run_ffi_unit_tests && tools/test.py ffi_unit
TEST=runtime/vm/compiler/ffi/native_type_test.cc
These tests are exercised on vm-precomp-ffi-qemu-linux-release-arm-try.

Change-Id: Ic64bdef2c13ac737dbf58864911f043fc7a3d831
Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191720
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2021-03-19 15:34:42 +00:00
Martin Kustermann caa31f55be [vm/compiler] Make codegen of InstantiateTypeArgumentsInstr sharable
Simplifies work for adding deopt info to this IR instruction.

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

TEST=Existing test suite.

Change-Id: Ia0936647f8f025397131b6d89764885a79cba9c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192185
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-03-19 15:04:37 +00:00
Tess Strickland d504084f42 [vm] Fix uses of NullIsAssignableTo at runtime.
NullIsAssignableTo only takes the type to check for nullability.
However, while a type parameter may itself be non-nullable, its
instantiation with a nullable type is nullable.

Thus, this CL adds type instantiation before runtime uses of
NullIsAssignableTo in Function::DoArgumentTypesMatch.

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

TEST=vm/dart/regress_45270

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-simarm_x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-nnbd-linux-release-ia32-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-linux-release-simarm64-try
Change-Id: Iaefffe9ab6d4d3ad889c4962489b2153d2bbaee1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190443
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2021-03-19 12:29:27 +00:00
Alexander Markov c665bac02d [vm/compiler] Follow-up to SupportsUnboxedInt64 cleanup
This is a follow-up to https://dart-review.googlesource.com/c/sdk/+/191761.
That change removed FlowGraphCompiler::SupportsUnboxedInt64() which is
always true, but incorrectly changed

  return (compiler::target::kSmiBits >= 32) ||
         FlowGraphCompiler::SupportsUnboxedInt64();

to

  return (compiler::target::kSmiBits >= 32);

in CanUnboxInt32(). That resulted in a performance regression on
golem benchmarks as certain methods were not inlined.

This change cleans up CanUnboxInt32() as it is also always true.

TEST=Manually verified one of the benchmarks on IA32.

Change-Id: I9fd72f3adc27e2e31340559cf79df1701bd98da7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192062
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2021-03-19 03:56:14 +00:00
Martin Kustermann dbd2c76e22 [vm/compiler] Remove InstanceOf runtime call from IL instruction, call stub instead
Having pushed arguments inside generated code makes deopt environments
incorrect, so we'll move all runtime calls out of IL instructions into
stubs.

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

TEST=Existing test suite.

Change-Id: I843ba1ba626c3d704d75d4a7088752100ddfb906
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191900
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2021-03-19 03:53:24 +00:00
Ryan Macnak 19e5899a02 [vm] Switch most non-Instances to compressed pointers.
The following are not compressed: Code, ObjectPool, Context, CallSiteData and subclasses.

Code::instructions_ is uncompressible because the VM doesn't control the address of Instructions when they are loaded via dynamic library.

Loads from the ObjectPool are a frequent occurrence in generated code, and shrinking ObjectPool entries would be offset by longer code sequences to decompress them. Also, some ObjectPool entries contain uncompressible pointers to C functions.

Context is not compressed based on reports from earlier work on compressed pointers that compressing them is disproporately bad for performance. The earlier work used a different, more-expensive compression scheme, so we should reinvestigate this.

CallSiteData et al. are on the hot path for unoptimized code but make up a comparatively small portion of the heap size.

TEST=ci
Change-Id: I9a425fa4e12113c9fd0b51999525d32a7e589a90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190600
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2021-03-18 22:52:04 +00:00
Ryan Macnak c5eaf317b6 Revert "[vm, compiler] Convert binary Smi ops to graph intrinsics."
This reverts commit 051ec30ff0.

Reason for revert: Failures on ARM32 AOT

Original change's description:
> [vm, compiler] Convert binary Smi ops to graph intrinsics.
>
> Keep left shift as an ASM intrinsic because it includes fallbacks to Mint operations on 32-bit architectures that graph intrinsics aren't good at expressing.
>
> This should be close to neutral on performance, but removes a fair amount of redundant code.
>
> TEST=ci
> Change-Id: Ic9c7d3b2d015ebf31972163a58c6bc9a27bad4ca
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/187164
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

TBR=rmacnak@google.com,alexmarkov@google.com

Change-Id: I2a08df5b4aa0269a6237a3d967729c155c88a1c7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192061
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-03-18 22:11:56 +00:00
Ryan Macnak 051ec30ff0 [vm, compiler] Convert binary Smi ops to graph intrinsics.
Keep left shift as an ASM intrinsic because it includes fallbacks to Mint operations on 32-bit architectures that graph intrinsics aren't good at expressing.

This should be close to neutral on performance, but removes a fair amount of redundant code.

TEST=ci
Change-Id: Ic9c7d3b2d015ebf31972163a58c6bc9a27bad4ca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/187164
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-03-18 20:33:34 +00:00
Ryan Macnak 08295a8cb3 [vm, compiler] Consider T{_IntegerImplementation} as equivalent to T{int} for optimization purposes.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/45297
Change-Id: Ic6a8956ad6344058c480e20018e876f5aae4c610
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191662
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-03-18 17:59:03 +00:00
Alexander Markov 817582a155 [vm/compiler] Cleanup --no-unbox_mints flag and SupportsUnboxedInt64()
Unboxed int64 are supported on all architectures which Dart VM supports.
The only was to disable support for unboxed int64 is to use
--no-unbox_mints flag, which is not used and not tested.
This change cleans up this flag and corresponding compiler predicates.

TEST=ci

Change-Id: Ib667319eaf87f0ded8bf9d9505272a3693a9e63e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191761
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-03-18 17:49:28 +00:00
Daco Harkes fbaf439b75 [vm/ffi] Fix ScopeBuilder uninitialized read
Closes: https://github.com/dart-lang/sdk/issues/45362

TEST=MSAN build

Change-Id: Ic51eba97b94656e75261001134e75db2fd2e352d
Cq-Include-Trybots: luci.dart.try:vm-kernel-msan-linux-release-x64-try,vm-kernel-precomp-msan-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191882
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-03-18 12:37:48 +00:00
Ryan Macnak 2e56467afb [vm, compiler] Unpredicate boolean loads on x64.
This reverts part of c9e10c931c, which Golem reports as negative for Xeon.

Generate dist8 branches for these cases.

TEST=ci
Change-Id: I77432e478c0d3a46868a530a2d75036994c8809e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191469
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-03-17 22:59:07 +00:00
Alexander Markov bed0589676 [vm] Fix access to parameters in async closure body inside field initializer
For async closure parsed_function_ could be an outer function
which is unrelated to the closure. So, ScopeBuilder should not
attempt to mark parameters of parsed_function_ with
set_is_forced_stack() if it sees kSyncYielding FunctionNode.
Parameter variables might not be even allocated if
async closure is used inside an instance field initializer
and parsed_function_ is a constructor.

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

Change-Id: I1b0082cb0e217039c43f19b35d77190493069edc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191325
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-03-17 19:17:05 +00:00
Martin Kustermann df439941e4 [vm/compiler] Change various allocation fast paths to check for --use-slow-path and --no-inline-alloc
This will allow future tests to force allocations to go to runtime. This
will be used to test deoptimization on allocation slow paths.

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

TEST=Existing test suite.

Change-Id: I0d552c2b313147ce08c5fbb22761a400388abe7b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191043
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2021-03-17 14:49:42 +00:00
Martin Kustermann 26f0eba03b [vm/compiler] Make AssertSubtypeInstr always call stub - including on ia32
This simplifies the code and makes it easier for later work
related to lazy-deopt of the instruction when returning from
runtime call.

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

TEST=Existing test suite.

Change-Id: I056baac434532d3ed034ba488252ed0ff77eb488
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191041
Reviewed-by: Tess Strickland <sstrickl@google.com>
2021-03-17 13:16:49 +00:00
Martin Kustermann 0834f9b7ac [vm/compiler] Move runtime call out of InstantiateTypeInstr to stub
This simplifies the code and makes it easier for later work
related to lazy-deopt of the instruction when returning from
runtime call.

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

TEST=Existing test suite.

Change-Id: I72e72554bdc306a9490a1460927d1dd650bfbe7d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191040
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2021-03-17 13:08:01 +00:00
Martin Kustermann 1055db533c [vm/compiler] Add infer range to Utf8ScanInstr
This tells the compiler that boxing the result of Utf8ScanInstr will
always fit in a Smi and the boxing instruction can therefore never go to
runtime (and e.g. cause a lazy-deopt).

Noticed as part of https://github.com/dart-lang/sdk/issues/45213

TEST=Existing test suite.

Change-Id: I30712ec50378c7e0f70e1a5d95a2390b4f5d8ebc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190481
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2021-03-17 11:17:41 +00:00
Martin Kustermann 1ca7593c44 [vm/compiler] Mark various additional IR instructions as kNoGC
Some IR instructions (e.g. RawStoreField) can never deopt by-design. Some
instructions are calling runtime entries but those are leaf calls (e.g.
InvokeMathCFunction). Some are synthetic IR instructions that never
actually emit code (e.g. Constraint). Some IR instructions cannot deopt
due to inputs (e.g. Boxing instructions whose value is guaranteed to fit
into Smi).

Part of https://dart-review.googlesource.com/c/sdk/+/190481

TEST=Existing test suite.

Change-Id: I770b7d094ef36221d357157c736710476fd6bfb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190482
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-03-17 11:13:01 +00:00
Regis Crelier 33cabf4313 [VM/runtime] Allow generic function types as type arguments in the VM.
Type parameter scopes were not set properly when loading bounds with generic function types from kernel file.
The trail to avoid infinite recursion while comparing type parameter bounds was not used properly.

Fixes https://github.com/dart-lang/sdk/issues/45313
Fixes https://github.com/dart-lang/sdk/issues/45322
Fixes https://github.com/dart-lang/sdk/issues/44930

TEST=regression tests added

Change-Id: I096b7d8c22aa5b3a3a9e12a59b1417388ff5171f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191465
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-03-17 00:16:41 +00:00
Ryan Macnak c9ba99ae6d [vm, compiler] Make the difference between the CompileTypes for int and _IntegerImplementation visible when printing IL.
TEST=ci
Change-Id: I17f6a79e3642a809a57f7d240c3894a093429a81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191460
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2021-03-16 21:57:01 +00:00
Tess Strickland 901fed103b [vm] Use the cached number of parent type args in FunctionType.
Also ensure the number of parent type arguments is appropriately
adjusted in the returned FunctionType when partially instantiating
a FunctionType, and that free parent type arguments are _not_
included in types built while reading constants.

Since the number of parent type arguments is now cached there, we
no longer need to also cache them in ClosureData. We can also remove
the parent walking in Function::NumParentTypeArguments().

Previously, a FunctionType where the component types did not use
parent type parameters was considered instantiated. This CL changes
it so that FunctionType with free parent type parameters are never
considered instantiated. This is necessary because otherwise,
when instantiating the parent type parameters, a FunctionType that
does not use its parent type parameters will be used unchanged
instead of creating a copy with fewer parent type parameters.

Because of this, places where IsInstantiated was used to simply
check for generic parent functions (namely, for implicit closure
creation) has been appropriately weakened to check
!HasGenericParent() instead.

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
Change-Id: Ifb4a0a1273d8d01908cdf4ffc3c4c28a1c33ffa0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190021
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2021-03-16 15:04:51 +00:00
Ryan Macnak c9e10c931c [vm, compiler] Predicate boolean loads.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/29908
Change-Id: I5a5c57a8a79dbe4f2ee5303a4b9436bd36e8d7be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189921
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-03-15 20:53:04 +00:00
Alexander Markov 16beb34813 [vm/aot] Remove special cases of dynamic function lookups from precompiler
Flutter gallery AOT snapshot size
release: no change;
release-sizeopt: arm -0.24%, arm64 -0.25%.

TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/44852
Change-Id: I847bfc311552bb4e80222e0040b50b4766a18dbe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190783
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-03-15 17:53:23 +00:00
Vyacheslav Egorov d42de4ed06 [vm] Crash on impossible GDT null errors
This CL adds code to detect situations when we hit
null error through GDT call with non-null receiver.

We achieve this by making receiver's cid part of the
GDT calling convention and checking this cid
in runtime entry responsible for throwing the null
error.

This CL is an attempt to narrow down b/179632636
and collapse various impossible crash reports
into a single native crash cluster by crashing VM
instead of throwing a null error.

TEST=tested manually

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try
Change-Id: If2ed4646c4c0f403016266e4e83e296a7b234cb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191141
Auto-Submit: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-03-15 15:35:10 +00:00
Tess Strickland dc62c9c3c2 [vm/compiler] Write retained reasons JSON to a file.
Instead of being part of the --trace-precompiler output, there is
is a new flag --write-retained-reasons-to=<path>.

To allow for non-functions to have reasons for retention, the
JSON objects in the array now have one additional field:

* type: a string, the C++ type of the Dart object.

This CL also wraps all the machinery in a RetainedReasonsWriter
class instead of putting it in the Precompiler interface.

TEST=vm/dart{,2}/use_trace_precompiler_flag

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
Change-Id: Ifa40ac64fdcbdad5114499425c7f8b08e327fa76
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190525
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-03-15 08:37:40 +00:00
Alexander Markov 11d6203130 [vm/aot] Fix retaining of exception types and auxiliary functions
There are two fixes:

1) If a function was compiled but not retained, precompiler
should still trace through types used in exception handlers.

2) Certain auxiliary functions such as implicit closure functions
and field initializers were added to 'possibly_retained_functions_'
set but were not traced through AddTypesOf and were not added to
'functions_to_retain_' set.

Flutter gallery AOT snapshot size
release - no changes
release-sizeopt arm +0.13%, arm64 +0.14%

TEST=ci
Fixes https://github.com/dart-lang/sdk/issues/45179
Issue https://github.com/dart-lang/sdk/issues/44852

Change-Id: Ide9a7e82a7bb9098dc90bc41a76e527e7a5cb603
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190781
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2021-03-13 00:30:38 +00:00
Vyacheslav Egorov 4e027fae97 [vm/compiler] Force unboxing of int phis on 64-bit platforms
More specifically on 64-bit platforms, when other heuristic fail:

- in AOT mode unbox all int typed phis.
- in JIT mode unbox all non-Smi int typed phis i.e. mixed
  Mint/Smi phis.

This brings treatment of int phis closer to how we treat other
boxed phis.

This considerably improves AOT code quality for loops which
our current conservative heuristic does not currently hit,
for example:

  void foo(int start, int end) {
    for (var i = start; i < end; i++) {
    }
  }

Code like this would use a boxed Phi previously which does not make
sense.

In JIT mode to really benefit from aggressive unboxing we
might need to shift from over-reliance on Smi operations, e.g.
when phi is unboxed we want to cascade that through and unbox
operations which are performed on it transitively. This requires
much more sophisticated algorithm and is outside of scope for this
change.

In AOT we in general treat all arithmetic operations as operations
over 64-bit int values so unboxing phis makes more sense.

As a result of this change we see small improvement in code size:

  flutter_gallery_app_so_gzip_size -0.2392%

TEST=ci


Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-release-x64-try
Change-Id: Iae9a16f353e53f649da4e665d2812ad47099a674
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/187860
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-03-11 22:20:51 +00:00
Ryan Macnak 8db0a975c1 [vm] Allow garbage in the upper-half of compressed Smis.
Allows removing a branch when decompressing pointers and removing fixup sign-extension after Smi ops that use 32-bit ops to detect overflow. Increases the code size of indexed and stores for some widths due to addressing mode limitations.

TEST=ci
Change-Id: Ia48353cccbbc586dd0d2e055a843c65e37c63a30
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185660
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2021-03-11 19:39:01 +00:00