Commit Graph

268 Commits

Author SHA1 Message Date
Ivan Inozemtsev a5ff656da1 Revert "[vm] Switch datastream Write/WriteUnsigned to (S)LEB128."
This reverts commit 80102c981b.

Reason for revert: b/186359854

Original change's description:
> [vm] Switch datastream Write/WriteUnsigned to (S)LEB128.
>
> This reduces the number of variable-length integer encodings in our
> database from 2 to 1, and chooses the more standard one.
>
> TEST=Existing tests, in particular any that involve snapshots.
>
> Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-msan-linux-release-x64-try,vm-kernel-precomp-ubsan-linux-release-x64-try,vm-kernel-precomp-tsan-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-simarm64c-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try
> Change-Id: Ia700158ac873ad32ac28c1027a669895961bc715
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196321
> Commit-Queue: Tess Strickland <sstrickl@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

# Not skipping CQ checks because original CL landed > 1 day ago.

Change-Id: Idf32bdd879cf8bb7407f6dae764312140ad6eeb2
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-msan-linux-release-x64-try,vm-kernel-precomp-ubsan-linux-release-x64-try,vm-kernel-precomp-tsan-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-simarm64c-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196920
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>
2021-04-26 07:52:47 +00:00
Tess Strickland 80102c981b [vm] Switch datastream Write/WriteUnsigned to (S)LEB128.
This reduces the number of variable-length integer encodings in our
database from 2 to 1, and chooses the more standard one.

TEST=Existing tests, in particular any that involve snapshots.

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-msan-linux-release-x64-try,vm-kernel-precomp-ubsan-linux-release-x64-try,vm-kernel-precomp-tsan-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-simarm64c-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try
Change-Id: Ia700158ac873ad32ac28c1027a669895961bc715
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196321
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-04-23 07:35:41 +00:00
Ryan Macnak 571908fbec [vm, compiler] Make UnboxedConstant more like Constant.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/45555
Change-Id: Ib396b0281d4e138cc252baacaac18e42057d7bb6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194502
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-04-21 22:45:31 +00:00
Alexander Markov f4a9cad199 [vm/compiler] Cleanup code duplication around Representation of array elements in LoadIndexed and StoreIndexed
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>
2021-04-07 20:43:58 +00:00
Alexander Markov 2a14259fd0 [vm/compiler] Cleanup CheckedSmi* instructions
This is a final cleanup of CheckedSmiOpInstr and
CheckedSmiComparisonInstr instructions.

Their uses were removed in the following changes:

  https://dart-review.googlesource.com/c/sdk/+/191761
  https://dart-review.googlesource.com/c/sdk/+/191760
  https://dart-review.googlesource.com/c/sdk/+/193447

TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/44852
Change-Id: Ica52ab9e2fcabab1913228818642a27a8d842f92
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193449
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2021-03-31 22:10:42 +00:00
Alexander Markov 4bf6de784c [vm/compiler] Null-aware EqualityCompare instruction
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>
2021-03-31 18:48:42 +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 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 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
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 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 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
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
Ryan Macnak d1605bc5c5 [vm, compiler] Don't touch memory in AssertBoolean and BooleanNegate.
AssertBoolean may assume its input is nullable bool. BooleanNegate may assume its input is non-nullable bool. Use fixed alignment bits to distinguish true, false and null.

TEST=ci
Change-Id: Ife694e66c1225d943881c2325cd67f18575a47e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189240
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-03-09 20:27:00 +00:00
Alexander Markov 7f8001218b [vm] Support unsigned shift operator int.>>>
TEST=runtime/tests/vm/dart/unsigned_shift_right_test.dart and other
tests for >>>.

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

Change-Id: I7f0a9e1e486be06576c5d9bff3659b0aa6d68c23
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/184921
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2021-02-24 00:14:57 +00:00
Ryan Macnak b1c09ecd8f [vm] Make naming more consistent when converting between handles, tagged and untagged pointers.
Currently we have things called XPtr which are not what you get from ptr().

Old world:
handle->raw() returns RawObject* (tagged)
raw_obj->ptr() returns RawObject* (untagged)

After 6fe15f6df9:
handle->raw() returns ObjectPtr
obj_ptr->ptr() returns ObjectLayout*

New world:
handle->ptr() returns ObjectPtr
obj_ptr->untag() returns UntaggedObject*

TEST=ci
Change-Id: I6c7f34014cf20737607caaf84979838300d12df2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149367
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-01-15 23:32:02 +00:00
Alexander Markov 8c2ab1d04f [vm/compiler/arm] Fix register constraint for Float32x4ToFloat64x2
S-register operand used in VCVTDS instructions cannot be allocated to
an arbitrary Q-register and needs to be constrained (otherwise an
invalid instruction is generated).

TEST=runtime/tests/vm/dart/regress_42067_test

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

Change-Id: I46b5ff3c75a50361eccebb1c74878bfb3c35d301
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/178162
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-01-08 23:00:23 +00:00
Martin Kustermann 0f76981bb1 [vm/concurrency] Change references to class_table/object_store/heap from Isolate to IsolateGroup
As part of making the compiler and other subsystems independent
of `Isolate` we have to move various state from `Isolate` to
`IsolateGroup`.

The class_table and object_store were already moved to `IsolateGroup`.

This CL only replaces usages of `Isolate::{object_store,class_table}`
with the equivalent in `IsolateGroup`.

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

TEST=Pure refactoring - relying on existing test coverage.

Change-Id: I34a0682d715b054d6c5faff077a513980f59a348
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/177126
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2021-01-06 15:22:11 +00:00
Martin Kustermann 897b1a2121 [vm/concurrency] Move osr/field-guard related state from Isolate to IsolateGroup
As part of making the compiler independent of `Isolate` we have to move
various state from `Isolate` to `IsolateGroup`.

This CL moves osr/field-guard related state.

TEST=Pure refactoring - relying on existing test coverage.

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

Change-Id: Id943891476f892f64f2a74952681270d012a4693
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/177125
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2021-01-06 13:32:10 +00:00
Tess Strickland 100e12b6cd [vm/compiler] Copy inlined IDs with token positions.
When creating new instructions that inherit a token position that
represents a source location from another instruction, the inheriting
instruction must also have the same inlining ID in order for the source
position represented by the token position to be looked up in the
correct script.

Force this by wrapping both in a single InstructionSource struct which
is taken by instructions which take token positions instead of just a
token position. That way, it's more work to manually transfer the token
position separately from the inlining ID of the instruction than doing
the right thing of transfering both at once.

To ensure this information is kept consistent, we pass InstructionSource
structs through the FlowGraphCompiler all the way down to the
CodeSourceMapBuilder.

This CL also makes the following changes:

* Cache the upper bound of source positions in scripts and use it to add
  a check for if a given real token position is valid for the script
  without iterating over the line starts data for each token position.

* Start inlining intervals appropriately when adding descriptor and
  null check information to the code source map.

Code size changes are minimal on Flutter gallery in release mode
(<0.05% decrease).

TEST=Existing tests on trybots, with manual checking with
--check-token-positions that previous errors are now removed.

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

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-release-x64-try,vm-kernel-nnbd-linux-release-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-linux-product-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-linux-release-simarm64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-ia32-try
Change-Id: I23ced262cb4e9fe9d81356f409e7e8d220d63ee0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173967
Reviewed-by: Régis Crelier <regis@google.com>
2020-12-18 00:42:14 +00:00
Daco Harkes 3e7cda8a4e [vm/ffi] Support passing structs by value
This CL adds passing structs by value in FFI trampolines.
Nested structs and inline arrays are future work.
C defines passing empty structs as undefined behavior, so that is not
supported in this CL.

Suggested review order:
1) commit message
2) ffi/marshaller (decisions for what is done in IL and what in MC)
3) frontend/kernel_to_il (IL construction)
4) backend/il (MC generation from IL)
5) rest in VM

Overall architecture is that structs are split up into word-size chunks
in IL when this is possible: 1 definition in IL per chunk, 1 Location in
IL per chunk, and 1 NativeLocation for the backend per chunk.
In some cases it is not possible or less convenient to split into
chunks. In these cases TypedDataBase objects are stored into and loaded
from directly in machine code.
The various cases:
- FFI call arguments which are not passed as pointers: pass individual
  chunks to FFI call which already have the right location.
- FFI call arguments which are passed as pointers: Pass in TypedDataBase
  to FFI call, allocate space on the stack, and make a copy on the stack
  and pass the copies' address to the callee.
- FFI call return value: pass in TypedData to FFI call, and copy result
  in machine code.
- FFI callback arguments which are not passed as pointers: IL definition
  for each chunk, and populate a new TypedData with those chunks.
- FFI callback arguments which are passed as pointer: IL definition for
  the pointer, and copying of contents in IL.
- FFI return value when location is pointer: Copy data to callee result
  location in IL.
- FFI return value when location is not a pointer: Copy data in machine
  code to the right registers.

Some other notes about the implementation:
- Due to Store/LoadIndexed loading doubles from float arrays, we use
  a int32 instead and use the BitCastInstr.
- Linux ia32 uses `ret 4` when returning structs by value. This requires
  special casing in the FFI callback trampolines to either use `ret` or
  `ret 4` when returning.
- The 1 IL definition, 1 Location, and 1 NativeLocation approach does
  not remove the need for special casing PairLocations in the machine
  code generation because they are 1 Location belonging to 1 definition.

Because of the amount of corner cases in the calling conventions that
need to be covered, the tests are generated, rather than hand-written.

ABIs tested on CQ: x64 (Linux, MacOS, Windows), ia32 (Linux, Windows),
arm (Android softFP, Linux hardFP), arm64 Android.
ABIs tested locally through Flutter: ia32 Android (emulator), x64 iOS
(simulator), arm64 iOS.
ABIs not tested: arm iOS.
TEST=runtime/bin/ffi_test/ffi_test_functions_generated.cc
TEST=runtime/bin/ffi_test/ffi_test_functions.cc
TEST=tests/{ffi,ffi_2}/function_structs_by_value_generated_test.dart
TEST=tests/{ffi,ffi_2}/function_callbacks_structs_by_value_generated_tes
TEST=tests/{ffi,ffi_2}/function_callbacks_structs_by_value_test.dart
TEST=tests/{ffi,ffi_2}/vmspecific_static_checks_test.dart

Closes https://github.com/dart-lang/sdk/issues/36730.

Change-Id: I474d3a4ee1faadbe767ddadd1b696e24d8dc364c
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/+/140290
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-14 16:22:48 +00:00
Vyacheslav Egorov 4b5c267dbd [vm/compiler] Support frameless functions
This CL allows register allocator to mark functions as frameless
in AOT bare instructions mode if they don't contain calls (with an
exception for write barrier related calls), don't require
spills and don't use optional or named parameters.

Calls to Write Barrier helper stubs introduce some complexity
on ARM/ARM64, where we need to take into account that return
address needs to be explicitly spilled from LR register. To keep
the code size balance (frame setup vs manual LR spilling on WB
slow path) we allow one instruction with a write barrier
per frameless function.

Flutter Gallery snapshot becomes 800KB smaller (3% reduction), but
APK size for some reason increases by .1%. On a large internal
application effect is much smaller (60K - 0.16% reduction).

Flutter Gallery is disproportionally affected by the change due to
abnormal amount of small getters originating from localizations:
each localized phrase becomes a getter returning a constant on a
localization specific class.

TEST=tested through normal test suite

Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-ffi-android-release-arm64-try,vm-ffi-android-release-arm-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-android-release-arm64-try
Change-Id: I86cb45a57567ee654ead388957ac4e561634ef9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175304
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-10 15:51:27 +00:00
Vyacheslav Egorov 5f490fabf7 [vm/compiler] Track LR state in ARM/ARM64 backends
Assembler now always knows whether LR contains return address
or can be safely cloberred.

TEST=tested through normal test suite

Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-ffi-android-release-arm64-try,vm-ffi-android-release-arm-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-android-release-arm64-try
Change-Id: I0b436509389cfd29ee413fd28930fb2d6b07616e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174468
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-10 15:51:27 +00:00
Daco Harkes 15dfcca89f [vm/ffi] Enable FFI on Fuchsia
This CL enables dart:ffi on Fuchsia.

It has the necessary VM changes for x64 and arm64.
- Allocate VM callback trampoline memory pages with RX.
- Do not use x18 on arm64.
- Save x18 on arm64 in Thread to be able to restore it on exceptions.

We do not have a bot testing this
https://github.com/dart-lang/sdk/issues/38752.
The bot only tests the build, it does not run the emulator.

Manual build and test steps x64 Fuchsia emulator:
```
tools/build.py --os=fuchsia -m debug fuchsia_ffi_test_package
xvfb-run third_party/fuchsia/sdk/linux/bin/femu.sh --image qemu-x64 -N --headless
third_party/fuchsia/sdk/linux/bin/fserve.sh --bucket fuchsia-sdk --image qemu-x64 --device-name step-atom-yard-juicy
third_party/fuchsia/sdk/linux/bin/fpublish.sh out/DebugFuchsiaX64/gen/dart_ffi_test_debug/dart_ffi_test_debug.far
third_party/fuchsia/sdk/linux/bin/fssh.sh --device-name step-atom-yard-juicy run fuchsia-pkg://fuchsia.com/dart_ffi_test_debug#meta/dart.cmx --ignore-unrecognized-flags --packages=/pkg/data/.packages --disable-dart-dev /pkg/data/tests/ffi/all_positive.dart
```

Manual build and test steps arm64 Fuchsia emulator:
```
tools/build.py --no-start-goma --os=fuchsia -m debug -a arm64 fuchsia_ffi_test_package
xvfb-run third_party/fuchsia/sdk/linux/bin/femu.sh --image qemu-arm64 -N --headless --experiment-arm64
third_party/fuchsia/sdk/linux/bin/fserve.sh --bucket fuchsia-sdk --image qemu-arm64 --device-name step-atom-yard-juicy
third_party/fuchsia/sdk/linux/bin/fpublish.sh out/DebugFuchsiaARM64/gen/dart_ffi_test_debug/dart_ffi_test_debug.far
third_party/fuchsia/sdk/linux/bin/fssh.sh --device-name step-atom-yard-juicy run fuchsia-pkg://fuchsia.com/dart_ffi_test_debug#meta/dart.cmx --ignore-unrecognized-flags --packages=/pkg/data/.packages --disable-dart-dev /pkg/data/tests/ffi/all_positive.dart
```
Note that running on the arm64 emulator takes over an hour.
This has been tested on an Estelle device.

TEST=Manual test steps above.

The AOT mode has seen an initial test in g3 by rolling gen_snapshot and
the flutter runner.

Arm64 x18 treatment along the lines of
https://dart-review.googlesource.com/c/sdk/+/119481:
- FfiCallInstr, does not modify x18 at all. We do not have to do
  anything special when having a C++ frame on top of a Dart frame.
- NativeEntryInstr and NativeReturnInstr, saves and restores x18 with
  PushNativeCalleeSavedRegisters && PopNativeCalleeSavedRegisters. Also
  save to the thread field in both places. That way the JumpToFrame stub
  can load from the thread field.

Closes: https://github.com/dart-lang/sdk/issues/44434
Change-Id: Ide29369c878fed5909a0d6f7d4c3f7508e179f25
Cq-Include-Trybots: luci.dart.try:vm-fuchsia-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173273
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-10 12:15:17 +00:00
Tess Strickland 3b9b77964d Reland "[vm/compiler] Move AssertAssignables out of closure bodies."
This is a reland of 42c76fd910

Main issue was due to the parameter order of the invoke field dispatcher
not matching the argument order described by its saved arguments
descriptor. There's no reason for it not to, so now it does.

Also fixes some issues with stack trace tests that failed due to
increased deduplication of closures by forbidding deduplication for
those tests.

TEST=Run on trybots of all architectures as well as flutter engine
trybot, new test added for downstream issues seen after initial landing.

Original change's description:
> [vm/compiler] Move AssertAssignables out of closure bodies.
>
> This CL moves the final set of checks out of closure bodies and into
> dynamic closure call dispatchers.  It also adds stubs for checking top
> types and null assignability for types only known at runtime.
>
> Fixes https://github.com/dart-lang/sdk/issues/40813 .
>
> Changes in Flutter gallery in release mode:
>
> * arm7: -3.05% total, +0.99% vmisolate, -0.89% isolate,
>         -1.20% readonly, -4.43% instructions
> * arm8: -3.20% total, +0.99% vmisolate, -0.88% isolate,
>         -1.18% readonly, -5.05% instructions
>
> TEST=Run on trybots of all architectures, includes test adjustments where needed.
>
> Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try
> Change-Id: Ifb136c64339be76a642ecbb4fda26b6ce8f871f9
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166622
> Commit-Queue: Tess Strickland <sstrickl@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Reviewed-by: Régis Crelier <regis@google.com>

Change-Id: Ic5ec59cf355f7779bb82db798d97d762ba1e5556
Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-linux-product-x64-try,flutter-engine-linux-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172644
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-11-18 22:42:31 +00:00
Tess Strickland 7555f5fe63 Revert "[vm/compiler] Move AssertAssignables out of closure bodies."
This reverts commit 42c76fd910.

Reason for revert: Failures in flutter/google3. Initial hypothesis is related to product mode and instruction deduplication.

Original change's description:
> [vm/compiler] Move AssertAssignables out of closure bodies.
>
> This CL moves the final set of checks out of closure bodies and into
> dynamic closure call dispatchers.  It also adds stubs for checking top
> types and null assignability for types only known at runtime.
>
> Fixes https://github.com/dart-lang/sdk/issues/40813 .
>
> Changes in Flutter gallery in release mode:
>
> * arm7: -3.05% total, +0.99% vmisolate, -0.89% isolate,
>         -1.20% readonly, -4.43% instructions
> * arm8: -3.20% total, +0.99% vmisolate, -0.88% isolate,
>         -1.18% readonly, -5.05% instructions
>
> TEST=Run on trybots of all architectures, includes test adjustments where needed.
>
> Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try
> Change-Id: Ifb136c64339be76a642ecbb4fda26b6ce8f871f9
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166622
> Commit-Queue: Tess Strickland <sstrickl@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Reviewed-by: Régis Crelier <regis@google.com>

TBR=kustermann@google.com,regis@google.com,sstrickl@google.com

Change-Id: Iaf79acddcf18fb3699a894950b31515d6f759349
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172643
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2020-11-18 08:17:21 +00:00
Tess Strickland 42c76fd910 [vm/compiler] Move AssertAssignables out of closure bodies.
This CL moves the final set of checks out of closure bodies and into
dynamic closure call dispatchers.  It also adds stubs for checking top
types and null assignability for types only known at runtime.

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

Changes in Flutter gallery in release mode:

* arm7: -3.05% total, +0.99% vmisolate, -0.89% isolate,
        -1.20% readonly, -4.43% instructions
* arm8: -3.20% total, +0.99% vmisolate, -0.88% isolate,
        -1.18% readonly, -5.05% instructions

TEST=Run on trybots of all architectures, includes test adjustments where needed.

Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try
Change-Id: Ifb136c64339be76a642ecbb4fda26b6ce8f871f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166622
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2020-11-17 22:05:18 +00:00
Tess Strickland e7a2fbe692 [vm/compiler] Unify TTS implementations across architectures.
The only architecture-specific part of type testing stubs (TTS) is which
registers get saved/restored across SubtypeTestCache stub calls in the
slow TTS implementation, which is now a register mask constant in the
TypeTestABI struct.

This CL also:

* Creates a single definition of OperandSize in assembler_base.h. Moves
  OperandSize into the compiler namespace.  assembler_base.h. Renames
  constants common to all architectures to neutral names (e.g., kWord =>
  kFourBytes), since "word" has different meanings across architectures.

* Creates a new JumpDistance enum for kNearJump/kFarJump in
  AssemblerBase and replace existing bool uses with the constants.

* Adds JumpDistance arguments to some of the generalized Assembler
  methods so they aren't forced to use far jumps on IA32/X64. These
  added JumpDistance arguments are ignored on ARM architectures.

* Adds a new generalized Assembler::LoadIndexedPayload method for
  loading indexed objects out of post-header variable-length payloads.

* Moved the OperandSize argument for LoadForOffset and similar methods
  on 32-bit ARM from being the first argument to being the second to
  last argument just to match other architectures, and to allow it to
  have a default value of kFourBytes.

TEST=Run on trybots of all architectures.

Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try
Change-Id: Ia930613e96db4d1ab324c5a355dca8994d2a77f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172160
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-11-17 15:09:47 +00:00
Alexander Markov c0ebcb9f1b [vm/compiler/nnbd] Add slow path for loads of late fields without initializer
When loading a late field without initializer, we check if it was not
initialized and throw an exception. This change adds slow path (shared
if supported) for throwing LateInitializationError instead of calling
an initializer which would throw an exception. This improves register
allocation around accesses to such late fields.

In addition, this CL removes duplicated code for generating shared
stubs.

Size of Flutter gallery snapshot on armv8 -0.45%
(gzip -0.34%, brotli -0.41%)

Null-safe version of ParticleSystemUpdate benchmark on x64
JIT +9-17%, AOT +3-4%.

Change-Id: Ia12c1efec0871a2fd7acc6db75f255853af52d0f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168993
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-10-26 18:55:26 +00:00
Tess Strickland d9685d1c4c [vm/compiler] Move type argument type checks out of closure bodies.
These checks are now performed in the dynamic closure call dispatcher.
To avoid having to create type argument vectors (TAVs) for default type
arguments at runtime, we cache a compile-time created TAV in the
ClosureData for the closure function which is retrieved by the
dispatcher when needed.

We also keep an associated packed field of information that can also be
determined at compile time:

* Whether the cached TAV needs instantiation or can share its
  instantiator or function type arguments.

* The number of parent type parameters.

The former allows the generated IL to keep the invariant that the
InstantiateTypeArguments instruction (and the runtime entry it calls) is
only used for uninstantiated TAVs.

Also changes the destination name to an Value input for the
AssertSubtype instruction and adds handling for non-constant types and
names in that instruction's backend.

Additional changes:

* Adds new slots for ClosureData, Function, and TypeArguments.

* Adds a new kUnboxedUint8 representation (needed for
  TypeParameterLayout::flags_, which is of type uint8_t).

  * Extends LoadField to handle uint8_t unboxed native fields.

  * Adds BoxUint8 for boxing unboxed uint8_t values.

Code size impact on Flutter gallery in release mode:

* arm7: total +0.08%, vmisolate: +0.56%, isolate: +0.42%,
        readonly: -0.04%, instructions: -0.03%

* arm8: total +0.12%, vmisolate: +0.56%, isolate: +0.42%,
        readonly: -0.002%, instructions: +0.03%

Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-ia32-try,vm-kernel-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try
Bug: https://github.com/dart-lang/sdk/issues/40813
Change-Id: I5a7de27a17e3119e27752bd0d10e1c6bc1b52a16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/158844
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2020-10-26 18:48:18 +00:00
Daco Harkes 9d36be8868 [vm/ffi] Make callback SaveArguments platform agnostic
Separated out from:
https://dart-review.googlesource.com/c/sdk/+/140290/18.
Issue: https://github.com/dart-lang/sdk/issues/36730.

Change-Id: I71a749ffe946c74033f7f047486f32746e93d79f
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-linux-debug-ia32-try,vm-kernel-linux-debug-x64-try,vm-kernel-mac-debug-x64-try,vm-kernel-win-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166849
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-10-12 21:12:22 +00:00
Tess Strickland 02f5faa288 [vm/compiler] Prepare InstantiateTypeArguments for dynamic type args.
Current users of InstantiateTypeArguments have the uninstantiated type
arguments available at compile time. After upcoming work on #40813,
there are cases where the generated code needs to instantiate type
arguments that are only available at runtime.

This work changes the uninstantiated type arguments for the
InstantiateTypeArguments instruction to a runtime Value pointer instead
of a compile time TypeArguments reference. The changes beyond that are
limited to only what is needed to get current uses working, with ASSERTs
checking that current invariants still hold. The rest of the changes
needed for dynamic uninstantiated type arguments will come later.

Bug: https://github.com/dart-lang/sdk/issues/40813
Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-release-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try
Change-Id: Iafe836cfd8744d3e835e60112a4f099e631f4782
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162183
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2020-09-14 15:28:19 +00:00
Martin Kustermann 1c7731db60 [vm/compiler] Always use type testing stubs for AssertAssignable
As a preparation for being able to dynamically call TTS on any type object we ensure that
also in the non-dynamic AssertAssignables we always use TTS.

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

Change-Id: Ia7a2aa98eff940e4ead28f6158f13c084ecb3818
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162008
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2020-09-09 16:57:19 +00:00
Vyacheslav Egorov ab591454c5 [vm/arm64] Fix optional parameters overflow
Functions with too many optional positional parameters were causing
an assertion failure in ARM64 backend because LoadIndexedUnsafe
we not taking large offsets into account.

ARM64 only gives 9 bits for encoding a negative offset while
ARM32 gave 12+1 bits for these offsets.

Closes https://github.com/flutter/flutter/issues/64526

R=kustermann@google.com

Change-Id: Ia49fd237f3fa8465b01f6dc4aabceef40c2fc256
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/160066
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-08-25 11:34:40 +00:00
Tess Strickland 1914b0d7c0 [vm/compiler] Unify slot rep != kTagged handling across architectures.
Unify the order of checks in both LoadFieldInstr::MakeLocationSummary()
and LoadFieldInstr::EmitNativeCode() so that all architectures first
check the slot representation, then for unboxed fields when optimizing,
then for potential unboxed fields.

Add kUnboxedInt64 handling to IA32, so that all architectures support
the same set of unboxed slot representations.

For 32-bit architectures, use RepresentationUtils::ValueSize to
determine when to use single registers vs. pairs of registers for
unboxed integers.

Move (and dedup) any asserts in LoadFieldInstr::EmitNativeCode() into
LoadFieldInstr::MakeLocationSummary(), since the latter is always called
first, making the ASSERTs fail as soon as possible, and there's no need
to re-check the duplicated ASSERTS.

Change-Id: Ia0f8fddd5a3cda036f9e4c51e3e9a374be121e7f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159667
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2020-08-25 09:40:49 +00:00
Tess Strickland e5cf5d9502 [vm/compiler] Add nullable boxed native field slots.
Previously, all boxed native field slots were marked not nullable.
However, several boxed native fields are in fact nullable, which means
that even generated IL that appropriately checks these fields for null
can break in optimized code when the null checks are removed.

Also add some helper utilities for working with representations.

Change-Id: I22703d14cfbadbabeae74179476dea47ace12161
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/159280
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Clement Skau <cskau@google.com>
2020-08-20 11:36:00 +00:00
Tess Strickland 787446213c [vm/compiler] Move argument shape (not type) checks out of closures.
This CL performs the following checks in the invoke field dispatcher for
dynamic closure calls when lazy dispatchers are enabled:

* The provided function type arguments vector (if any) has the correct
  length.

* No function type arguments should be provided if the closure has
  delayed type arguments.

* All required arguments (positional in all modes, named in appropriate
  null safety modes) have been provided by the caller.

* If there are optional positional arguments, an appropriate number
  has been provided.

* If there are optional named arguments, their names are valid.

Since the runtime already handles checking the argument shapes when lazy
dispatchers are disabled, these checks are now completely removed from
closure bodies in all cases. Thus, the only remaining checks in closure
bodies are the type checks performed by AssertSubtype and
AssertAssignable when lazy dispatchers are enabled.

Changes in the Flutter Gallery:

* ARM7, release: -3.61% instructions, -2.19% total
* ARM7, sizeopt: -3.62% instructions, -2.55% total
* ARM8, release: -3.66% instructions, -1.98% total
* ARM8, sizeopt: -3.65% instructions, -2.37% total

Most of these changes are already exercised by existing tests such as
(but not limited to):

* corelib{,_2}/dynamic_nosuchmethod_test
* language{,_2}/call/call_test
* language{,_2}/closure/tearoff_dynamic_test
* language{,_2}/generic/function_bounds_test
* language{,_2}/parameter/named_with_conversions_test
* language{,_2}/vm/no_such_args_error_message_vm_test

I've added one test to specifically check the interaction between
dynamic calls and required named parameters. There is some coverage in
other NNBD tests, but those are not directly focused on testing this
specifically.

Other changes:

* Adds initial cached ranges for certain BinarySmiOp and ShiftIntegerOp
  instructions when the RHS is a constant, to avoid false negatives for
  deoptimization and throw checks prior to range analysis.

* Adds new slots for various Function fields.

* Adds the ability to define unboxed native slots, which are always
  unboxed after retrieval even in unoptimized code. In the first
  iteration, the backend only handles loads from Uint32 unboxed native
  slots. Part of https://github.com/dart-lang/sdk/issues/42793.

* Removed the special handling for loading from non-nullable int fields
  in AOT compilation. Instead, their treatment is unified with the
  treatment of the new unboxed native fields, since the source field is
  always unboxed and the result of the load is also always unboxed, as
  code involving them is always optimized.

Bug: https://github.com/dart-lang/sdk/issues/40813
Change-Id: Ia02aa3e872c1fefd906fd67b55021ea1797556e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155604
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-08-17 08:58:08 +00:00
Ryan Macnak 91ed534139 [vm] Support --use_bare_instructions when splitting snapshots.
- Don't use PC-relative calls when calling between loading units.
 - Sort the contents of the code cluster by loading unit, then by text offset.
 - Handle binding PC-relatives calls and inserting trampolines per loading unit.
 - Create one code order table per loading unit to implement PC -> Code lookup.
 - Read code order tables directly, instead of copying into malloc'd memory.

--use_table_dispatch still not yet supported.

This slightly shrinks non-split binaries (~2% clustered part, 0.4% total snapshot) due to the new delta encoding when Code references Instructions.

Bug: https://github.com/dart-lang/sdk/issues/41974
Change-Id: I51052ebc7b4968b554897d1710135a6c41821302
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/157820
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2020-08-12 17:23:14 +00:00
Martin Kustermann 61a944ca6a [vm/compiler] Align BoxInt64 implementation on x64 with arm/arm64 by calling a shared slow path
Change-Id: I3dcdc922e00898e49bf00b985cb2af747005d35f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142623
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-07-27 19:22:03 +00:00
Ryan Macnak 3844e74adb [vm, compiler] Fix bypassed EnsureIsNewOrRemembered in CreateArrayInstr slow path.
If inline bump-pointer allocation fails, allocation stubs must check whether the allocation result from the runtime is old and ensure it is in the remembered set if so to make write barrier elimination safe. CreateArrayInstr would directly call the runtime entry if inline bump-pointer allocation failed without performing the remembered check. This CL changes the slow path to call the AllocateArray stub instead, matching every other allocation slow path.

Bug: https://github.com/dart-lang/sdk/issues/42489
Change-Id: Ic502e43683607e1d0f85154f0e3a8c3ea11deefa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154623
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-07-16 20:52:54 +00:00
Martin Kustermann d215ab6d73 [vm] Assign top-level classes cids outside 16-bit range
Right now we assign class ids to top-level classes, abstract classes as
well as concrete classes. All of them have allocated from a 16-bit pool
of ids. The VM FATAL()s once it hits that limit.

Customers who run very large programs (significant amount of generated
code) on the Dart VM have started to hit this 16-bit class limit.

Concrete classes can have instances in the heap. Our current heap layout
only allows 16-bit class ids to be encoded in the header word. To avoid
increasing the size of heap objects or shrinking the size of the identity
hash code to 16-bit we keep class ids in object headers to be 16-bit.

Abstract classes cannot have instances in the heap. Though their class
ids are encoded in type objects. Furthermore we sort classes in
AOT/AppJIT mode to perform fast class-id range checks. To avoid impacting
this optimization we treat abstract classes the same way as concrete
classes.

Top-level classes cannot have instances in the heap. Their class ids are
only used in the runtime code, for example for hot-reload as well as
part of the service protocol.

=> We can allocate class ids outside the 16-bit range for top-level
classes, thereby freeing a significant amount of space in the 16-bit
range.

This CL does exactly that: We change classid_t to be int32_t. The
ClassLayout::id_ can now be assigned ids outside 16-bit range for
top-level classes. To do this we keep dart classes and top level classes
as separate arrays in the ClassTable.

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

See also b/160229360

Change-Id: I6710a644e7b0ab2d4f4c792bef8e1f91cb117421
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153607
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-07-09 18:33:32 +00:00
Alexander Markov 06a8cc8dea [vm/nnbd] Use separate runtime entry for throwing _CastError in null check operator
Previously, NullError runtime entry was used both to throw
NoSuchMethodError and _CastError. _CastError was used if selector is
null. However, with --dwarf-stack-traces CodeSourceMap is not preserved
and selector is not available, so wrong exception type was thrown.

This is fixed by introducing separate NullCastError runtime entry along
with corresponding shared stubs.

NullErrorSlowPath is extended to support 3 exception types
(NoSuchMethodError, ArgumentError and CastError).
NullArgErrorSlowPath is removed as it duplicates NullErrorSlowPath.

Fixes vm/dart/null_checks_with_dwarf_stack_traces_test
Fixes https://github.com/dart-lang/sdk/issues/42149

Change-Id: I4f2b34ad2b161459491de60d8737bb4f87117336
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153040
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2020-07-01 20:52:34 +00:00
Martin Kustermann 53807c1d79 [vm] Remove ARMv6 related code
This also allows unaligned access, since it's mandatory for ARMv7 (we
already take advantage of it for ARMv8).

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

Change-Id: I0bd61a930e61dea330ab21fd187fe64b057ca28e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152322
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-06-26 09:39:15 +00:00
linzj 54481776c9 Fix redundant comparison for InstantiateTypeArgumentsInstr.
Fixes #42389.

R=vegorov@google.com

Change-Id: Iba187e191ee2115d03d3846b58b0955581839d7b
Bug: https://github.com/dart-lang/sdk/issues/42389
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151680
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-06-18 11:08:03 +00:00
Daco Harkes 6544c69e23 [vm/ffi] Convert Objects to Dart_Handles in FFI calls
This includes support for calling Dart_PropagateError in native code
when doing FFI calls, and catching uncaught exceptions with Dart_IsError
when doing FFI callbacks.

The support for Dart_PropagateError adds a catch entry to the FFI
trampoline, which prevents inlining these trampolines in AOT. This
regresses the FfiCall benchmarks by 1-2% in AOT.

In addition, Dart_PropagateError requires maintaining a bit whether we
entered native/VM code from generated code through FFI or not. That way
we can do the proper transition on the exception path. When entering
generated code, we store this bit on the stack, right after the entry
frame.

Design: http://go/dart-ffi-handles

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

Change-Id: Idfd7ff69132fb29cc730931a4113d914d4437396
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-mac-debug-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-nnbd-linux-debug-x64-try,analyzer-nnbd-linux-release-try,front-end-nnbd-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145591
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-06-12 11:14:22 +00:00
Aske Simon Christensen e35ca30ca5 Reland "[vm] MemoryCopy instruction for copying between typed data and strings."
This is a reland of 6ecd8a10ea

Original change's description:
> [vm] MemoryCopy instruction for copying between typed data and strings.
> 
> Used for copying the bytes from the Uint8List to the _OneByteString in
> String.fromCharCodes and the pure-ASCII case of UTF-8 decoding.
> 
> Issue https://github.com/dart-lang/sdk/issues/42072
> Closes https://github.com/dart-lang/sdk/issues/41703
> 
> Change-Id: I1ae300222877d1c6e64e32c2f40b8fb187a584c0
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149500
> Commit-Queue: Aske Simon Christensen <askesc@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

Change-Id: Ia231c521e5f2db168cfc6094dfc7322327dedc6d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150925
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Aske Simon Christensen <askesc@google.com>
2020-06-11 12:29:19 +00:00
Ryan Macnak d1b0713e8b Revert "[vm] MemoryCopy instruction for copying between typed data and strings."
This reverts commit 6ecd8a10ea.

Reason for revert: Breaks ABI

Original change's description:
> [vm] MemoryCopy instruction for copying between typed data and strings.
> 
> Used for copying the bytes from the Uint8List to the _OneByteString in
> String.fromCharCodes and the pure-ASCII case of UTF-8 decoding.
> 
> Issue https://github.com/dart-lang/sdk/issues/42072
> Closes https://github.com/dart-lang/sdk/issues/41703
> 
> Change-Id: I1ae300222877d1c6e64e32c2f40b8fb187a584c0
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149500
> Commit-Queue: Aske Simon Christensen <askesc@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

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

Change-Id: I5fc0b58da80dca23c91b57ec2833492e9d0885a8
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150802
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2020-06-10 18:41:55 +00:00
Aske Simon Christensen 6ecd8a10ea [vm] MemoryCopy instruction for copying between typed data and strings.
Used for copying the bytes from the Uint8List to the _OneByteString in
String.fromCharCodes and the pure-ASCII case of UTF-8 decoding.

Issue https://github.com/dart-lang/sdk/issues/42072
Closes https://github.com/dart-lang/sdk/issues/41703

Change-Id: I1ae300222877d1c6e64e32c2f40b8fb187a584c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149500
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-06-10 14:40:17 +00:00
Aske Simon Christensen cf6f8903a5 [vm] IL instruction for UTF-8 scan.
Speeds up decoding across the board, with medium-length pure ASCII
strings seeing about 2x on X64 and IA32.

Closes https://github.com/dart-lang/sdk/issues/41702

Change-Id: I1c8e0bc69baaaeb6755d4c775e6fa0e6d18e1c57
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148762
Commit-Queue: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-06-08 15:03:34 +00:00
Alexander Markov 1618fd965b [vm/compiler] Optimize lazy field initialization
Load*Field and Init*Field IL instructions are fused into load
instructions with 'calls_initializer' flag.

A new, more powerful elimination of lazy initializer calls uses
data flow analysis and load forwarding (place numbering).

In addition to improved elimination of initializer calls,
fusing instructions avoids extra load after field is already
loaded for lazy initialization check.

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

Change-Id: Ibb2a63f84b9b0c970db67b3d6684ec15384a64e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148283
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-06-01 21:28:18 +00:00