Commit Graph

13143 Commits

Author SHA1 Message Date
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
Daco Harkes 4adebc6d2a [vm] remove unecessary store of x18 to Thread
Related issue: https://github.com/dart-lang/sdk/issues/44435

TEST=Unfortunately we have no tests set up for shadow call stack.

Change-Id: Ibea3662ba2ef563702288b7a52f816df3217aa41
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175367
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-12-09 20:08:00 +00:00
Alexander Aprelev e45e4cad50 [vm/service] Fix calculation of heap size numbers for isolate groups
TEST=benchmarks/IsolateSpawnMemory with/without --enable-isolate-groups

Change-Id: Id8349839248323b84cbc743217cd4a380504c8b7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175520
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2020-12-09 17:36:20 +00:00
Martin Kustermann 425780f410 [vm/concurrency] Share program structure and JITed code with --enable-isolate-groups
This removes our temporary scaffolding support for JIT isolate groups
(which was implemented by creating a new isolate group, loading the
application kernel into it and then merging the heap into the original
isolate group - maintaining a different object store)

It makes all isolates within a group share the same object store, same
libraries and JITed code. It will be conservative to start with, only
allow running unoptimized code, etc.

We will gradually remove the restrictions imposed by this CL:
  https://dart-review.googlesource.com/c/sdk/+/173970

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

TEST=Tests using --enable-isolate-groups with JIT sharing.

Change-Id: I2bf69a6fe3c905067c4cec2e81613f731c52e5ee
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175302
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2020-12-09 09:39:59 +00:00
Ryan Macnak 1b160f79fe [vm] Gracefully handle loads not solicited by prefix.loadLibrary().
TEST=flutter
Bug: https://github.com/dart-lang/sdk/issues/41974
Change-Id: Ia0e99c5e84cdff8736c44e4e82ce40b045ed0207
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174563
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2020-12-08 22:14:25 +00:00
Jody Sankey 1c4e0d8dbd [fuchsia] Migrate off zx_clock_get.
zx_clock_get is a deprecated syscall that we're in the process of removing.
This CL replaces the only remaining usage with the modern equivalent.

Ref:
https://fuchsia.dev/fuchsia-src/contribute/governance/rfcs/0008_remove_zx_clock_get_and_adjust

TEST=existing tests on vm-fuchsia-release-x64-try

Bug: fuchsia:60521
Change-Id: Ic48563a09d7585af52027470f8202605da4ba70e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175324
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
2020-12-08 17:41:50 +00:00
Martin Kustermann a97b43f4ec [vm/concurrency] Allow concurrent evaluation (and caching) of metadata
If multiple threads want to obtain metadata they might both evaluate and
possibly cache the result of evaluation. Since the kernel loader
initialy adds metadata mappings (the value being kernel offsets) we use
the existing `IG->program_lock()` which the kernel loader already holds.

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

TEST=Tests using --enable-isolate-groups with JIT sharing.

Change-Id: I3b618f196abe9f7b584e4135a72a0017399ff2d5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175301
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-12-08 14:56:04 +00:00
Johnni Winther 3d19493f2d [cfe] Add flag to identify lowered locals
+ add predicate helpers to identify these and extract their
original names.

TEST=pkg/front_end/test/predicates/predicate_test.dart

Change-Id: I4d94c575d010b6b01c985eaf5392b9e0e979d044
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175250
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2020-12-08 14:53:14 +00:00
Martin Kustermann c549ecf1e6 [vm/concurrency] Allow code to be already installed when arriving in CompileFunction runtime entry
Issue https://github.com/dart-lang/sdk/issues/36097

TEST=Tests using --enable-isolate-groups with JIT sharing.

Change-Id: I155eef4731312f55f6c14a81aa0333cb84b70131
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175300
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-12-08 13:52:44 +00:00
Martin Kustermann fdd19ee3dc [vm/concurrency] Unify instance call miss handling across JIT/AOT
This unifies handling of instance call miss handling on
{JIT,AOT}x{ICOneArgMiss,ICTwoArgMiss,SwitchableCallMiss}.

It changes the [PatchCallHandler] to work in 3 independent steps:

  * Resolve target function
  * Under IG->patchable_call_lock():
    * Update type feedback
    * Possibly cause call site transition
  * Return data to miss handler to finish the call

This is a pre-requisite for sharing JITed code across lightweight
isolates, since in such a scenario any number of threads can go out to
any miss handler. The call site could then be transitioned several times
before they even return (which is currently not handled correctly).

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

TEST=Tests using --enable-isolate-groups with JIT sharing.

Change-Id: I673a6cdc21040fe7577e1d658c300e560cc04b7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175142
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-12-08 13:28:24 +00:00
Jens Johansen 6c19a8fc81 [VM] Read and report constant constructor coverage from dill (2nd try)
This CL makes use of the now included constant constructor coverage
in the dill file.

It works like this:
* When the CFE evaluates constants, every constant constructor
  invocation evaluated saves the reference to the constructor in the
  `Source` (from the Components uri to source table) for the callers
  Library.
* This data is loaded into the VM in a "raw" format.
* When a request for coverage comes in, the VM - on top of the normal
  coverage processing - goes through all scripts to find constant
  constructor coverage for the requested script and offset. Note that
  all scripts must be checked because library A can have evaluated a
  constructor from library B - so even if only coverage for library B
  was requested, library A has to be checked.
  For all constructors found the start and end position is reported as
  covered. Note that this does not mark any initializes and there are
  (at least currently) no good way of marking which initializes were
  evaluated (because it has to be stable across edits even when the
  `advanced invalidation feature` is enabled).
* Note that the reason for the coverage to work on references - as
  hinted above - is because we want it to be stable across hot reloads
  even if/when advanced invalidation is enabled. This means, that
  library A cannot record "positional coverage" for library B because
  library B might get (for instance) new comments that will make any old
  offsets invalid. By using references we always lookup in the current
  world and use the correct offsets.

https://github.com/dart-lang/sdk/issues/38934

TEST=Existing test suite, new tests for the new coverage added.

Change-Id: I29531247a4b91a99d9a459cfdefbb9798e9c948f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175246
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2020-12-08 10:47:43 +00:00
Ryan Macnak e3a9d70591 [vm, service] Remove unsafe querying across threads during Isolate::PrintJSON.
Note this would be unsafe even if under a safepoint operation because not all of the queried threads participate in safepoints.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/44304
Bug: https://github.com/dart-lang/sdk/issues/44385
Change-Id: I8156e8c6049165e5c53b66c3391f3e8a496ddaaf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175000
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2020-12-08 00:36:38 +00:00
Ryan Macnak fc4726e1cb [vm, gc] Fix write-write race between array truncation and the concurrent sweeper.
TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/44091
Change-Id: I589b31c0b8664d6b10aa5aad5ed6079c55cfba0d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174843
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2020-12-07 20:05:38 +00:00
Ryan Macnak abbb51e1ff [vm] Clean up metadata tracking.
Remove the use of Fields, which have since the metadata mechanism was introduced come to require global registration.

Retain some sloppiness matching of declarations by name instead of identity for the sake of hot reload.

TEST=ci
Change-Id: Ifa4cc7724096c606f994b057b7838e124ceb3626
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175141
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-07 19:43:48 +00:00
Lasse R.H. Nielsen 6e29700e16 Update List constructor documentation, deprecate constructor.
Emphasize that the operation is going away,
and mark constructor as deprecated.

TEST= Refactoring+deprecation only, covered by existing tests.

Change-Id: I82aa044cd2cf7bf347b624371399f44bda8f4a07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173261
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
2020-12-07 16:20:28 +00:00
Martin Kustermann 6fbe1f906e [vm/concurrency] Guard against concurrent creation of implicit closure functions
Once we share the program structure across isoltes we have to guard
against concurrent lazy creation of implicit closure functions.

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

TEST=Tests using --enable-isolate-groups with JIT sharing.

Change-Id: Ia8addf44106bea1b4777f5044c6c862cc76e354c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175067
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-12-05 09:50:25 +00:00
Alexander Markov 4ab36120d7 [vm] Fix finalization of classes when instances are allocated
Classes should be allocate-finalized before instance can be allocated
in order to properly update class hierarchy information and invalidate
code which was speculatively optimized.

TEST=runtime/tests/vm/dart/regress_44342_test.dart

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

Change-Id: I52a415f4cf25010eb23be339266a91ae6b7d7261
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175106
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-12-04 23:54:37 +00:00
James Clarke 50a2216b31 Changes to make support WinUWP target
TEST=no new tests added for this change, existing tests should work.
Bug: 43762
Change-Id: I1cc4c18526c0eef62c441567e8a7e55dd3dd8b0d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167041
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2020-12-04 22:46:12 +00:00
Ryan Macnak 28fe36c637 [vm, compiler] Recognize WeakProperty's accessors.
The layout of WeakProperty is defined in C++ instead of Dart. Add missing recognition of its accessors so the compiler can use direct field access instead of always going through natives. Compare LinkedHashMap.

Change the sentinel for WeakProperty lists to object null so that no special constructor is needed.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/44333
Change-Id: I8686383053c2c345c972b6615b514a1381e79fda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175001
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-12-04 22:25:12 +00:00
Martin Kustermann f30675a29f [vm/concurrency] Ensure static field registration is done under programlock
Also prepare for being able to grow field table of other isolates when
registering a new static field.

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

TEST=Tests using --enable-isolate-groups.

Change-Id: If1bc272e71da5cc89f962cfcac04d72c9314cf51
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175066
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-12-04 19:38:52 +00:00
Alexander Aprelev 75c1d50906 [vm/slots] Use atomics for native slots.
This is to ensure that there are no data races when intitializing and accessing native slots.

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

TEST=build dart on mac with tsan

Change-Id: I311ae050a84b2d832799f5116d56b835e3d48f38
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174841
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2020-12-04 01:30:41 +00:00
Alexander Markov 3a75dffd8a [vm/nnbd] Add check for repeated initialization of late final local variables
TEST=tests/language/nnbd/syntax/late_modifier_runtime_error_test.dart

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

Change-Id: I93776094914358600b3bd6ae6df649500fcff7b6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174980
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2020-12-03 21:48:11 +00:00
Alexander Aprelev b67a585d6c [vm/isolate] Provide more verbose information when second mutator thread attempts to enter an isolate.
This should help with troubleshooting vm crashes caused by multiple mutator threads entering an isolate.

TEST=flutter/engine runtime_unittests that exhibits this flaky problem with DartIsolateTest.ValidLoadingUnitSucceeds

Change-Id: Ib503df844cceafa58882a695a1fe7ceaa88eaed4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174900
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2020-12-03 18:15:13 +00:00
Martin Kustermann b9fc38564c [vm/concurrency] Guard against concurrent allocate-finalizing of a class
Issue https://github.com/dart-lang/sdk/issues/36097

TEST=Tests using --enable-isolate-groups.

Change-Id: Id5c0350e9a8e55f13b53e161e9316a89d8a9f6c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174801
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-12-03 16:10:50 +00:00
Tess Strickland f6e4b77f6a [vm] Remove the only cases where TokenPositions are mutated.
The Next() method on TokenPositions used to increment the internal
value_ field, but now creates a new TokenPosition with value_ + 1.

There are only three places this is used:

* Getting the token position after the end token position for
  implicit closure functions in the scope builder.

* Getting the token position after the end token position for
  variable declarations in the scope builder.

* Iterating over the token positions on a single source line in
  the debugger.

So the overhead of creating new TokenPositions vs. mutating the original
should be limited, compared to the benefit of being able to assume
TokenPosition values are constant once created. There's too much
dependence on the copy and copy assignment operators due to the previous
possibility of mutation to make the internal field constant at the
moment without much more sweeping changes, unfortunately.

Also remove the copy assignment in initializing TokenPosition constants.

TEST=Tested using existing tests on trybots.

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
Change-Id: Ie18b7f45bd9c6a43647ecd189330d91a4dff373b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174922
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Clement Skau <cskau@google.com>
2020-12-03 12:40:28 +00:00
Clement Skau c5eb666bcf Revert "[vm] Track metadata by identity instead of name."
This reverts commit bfd382820f.

Reason for revert: Breaks several lib_2/mirrors/ tests

Original change's description:
> [vm] Track metadata by identity instead of name.
>
> Remove the use of Fields, which have since the metadata mechanism was introduced come to require global registration.
>
> TEST=ci
> Change-Id: Ic2e0c4408557514507fd732e0cb19b022b2539c7
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161631
> Commit-Queue: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

TBR=kustermann@google.com,aam@google.com,rmacnak@google.com

Change-Id: Icf75e91872d9c85ce9be29a9a178d72ca024c98b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174920
Reviewed-by: Clement Skau <cskau@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
2020-12-03 08:03:11 +00:00
Alexander Markov 36015bde54 [vm/nnbd] More detailed error messages for late field/variable errors
TEST=tests/language/nnbd/syntax/late_modifier_runtime_error_test.dart

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

Change-Id: I84727583a0b743c5c868921a6148b18f12eb68e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174842
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2020-12-03 02:29:38 +00:00
Ryan Macnak bfd382820f [vm] Track metadata by identity instead of name.
Remove the use of Fields, which have since the metadata mechanism was introduced come to require global registration.

TEST=ci
Change-Id: Ic2e0c4408557514507fd732e0cb19b022b2539c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161631
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-02 23:43:07 +00:00
Ryan Macnak ca5853779b [vm, gc] Route most heap reads through LoadPointer.
Provides a good point to apply a read barrier, pointer decompression, or TSAN annotations.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/44091
Change-Id: I4e6930264f8ef8399e261fd24fcab78731d6e29c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174484
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-02 21:08:58 +00:00
Martin Kustermann 518cad6530 [vm/concurrency] Refactor SwitchableCallMiss handler to clarify difference between JIT and AOT
This CL if/defs AOT vs JIT parts of the SwitchableCallMiss handler in
order to ensure we don't attempt to e.g. use
CodePatcher::PatchSwitchableCall() in JIT mode or try to use AOT ICData
handling in JIT mode.

This is a preparation for enabling JITed code sharing across isolates,
which will extend this handler in the future.

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

TEST=Existing tests.

Change-Id: Ic4c07159919c922f6b6dcd4a395ee9c64a3e6058
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174641
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-12-02 20:32:28 +00:00
Martin Kustermann b6c28bb0c9 [vm/concurrency] Move various JIT compiler related locks from Isolate to IsolateGroup
Once we enable sharing of JITed code with --enable-isolate-groups, we
need to ensure all isolates use the same locks to for their shared data.

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

TEST=Tests running with --enable-lightweight-isolates.

Change-Id: Ie6e928c5505b39c93e086dfac379bd22034a0028
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174640
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-12-02 20:30:48 +00:00
Martin Kustermann 759caec558 [vm/concurrency] Add patchable_call_mutex and take it in miss handlers
We serialize all changes to patchable call state to ensure we always
make progress (e.g. transition from Monomorphic -> Polymorphic).

Only if the miss handler actually needs to patch the patchable call do
we stop mutators - if it only updates ICData we don't have to do that.
=> In the future we might introduce a more clever mechanism to avoid
   stopping mutators.

The CL also moves some locks from Isolate to IsolateGroup to ensure
all mutators use the same lock, since they operate on shared data
structures.

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

TEST=Existing isolate tests that --enable-isolate-groups.

Change-Id: I4a11a8b8bb65581c6aba11cdf73acdea0f24a502
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174469
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-12-02 18:14:18 +00:00
Johnni Winther d51ab9b62a [cfe] Add ProcedureStubKind
The enum `ProcedureStubKind` together with the flag `isSynthetic`
replaces the flags `isForwardingStub`, `isForwardingSemiStub`,
`isNoSuchMethodForwarder` and `isMemberSignature`.

The semantics of the existing properties on `Procedure` is unchanged.

The new MixinStub and MixinSuperStub stub kinds are not used yet and
the stub target for NoSuchMethodForwarder is not set yet.

TEST=refactoring


Change-Id: I6e81970dbb4baf0229f43c2a0bf0d5e575e65043
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174462
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-12-02 16:35:58 +00:00
Martin Kustermann a55b0137e9 [vm/concurrency] Make SafepointMutexLocker inherit from StackResource
The SafepointMutexLocker class already has a virtual destructor and was
therefore probably intended to be called when a longjmp() crosses it.

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

TEST=Added vm/cc tests in the CL.

Change-Id: Ifcfe51db733c4451be5be688df0c34004b98c3cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174644
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-12-02 14:59:13 +00:00
Martin Kustermann e74d01007e [vm/concurrency] Make updates to MegamorphicCache use type_feedback_mutex to prevent concurrent access
With lightweights isolates enabled we need to ensure to update entries
in MetamorphicCache in sequence with mutual exclusion.

This CL adds appropriate locking for the MegamorphicCache.

Right now this is safe in AOT because the entire SwitchableCallMiss
handler runs with stopped mutators. A future CL will relax this. That
future CL will also move the megamorphic mutex from Isolate to
IsolateGroup, since the megamoprhic caches are shared within an isolate
group.

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

TEST=CL is purely a refactoring.

Change-Id: I30305b04027d2bf9b4d5f6b1700bf158d38bdba7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174467
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-12-02 14:52:47 +00:00
Martin Kustermann 83e460ab6d [vm/concurrency] Make ICData use new type_feeback_mutex to prevent duplicate entries
Dart mutator threads cause update to runtime type feedback information
(e.g. ICData, MegamorphicCache). With multiple lightweight isolates
sharing JITed code, they will share the type feedback as well. That also
means multiple mutators can try to update type feedback at the same time
with the same (or different) feedback.

This means we can run into situations where we're trying to update type
feedback with information that's already there.
=> At a minimum we want to avoid adding duplicate entries to the ICData,
   so we have to guard against that.

Since the actual backing store to ICData is immutable, we have two
choices:

  * Let each thread read the current backing store, make a
    copy-on-write, add the new entry and update ICData with new backing
    store.
    => This can lead to an successful update being visible for a short
       period and then disappearing.

  * We can can ensure mutual exclusion when updating the backing store
    of ICData, thereby making read+grow+write appear atomic.
    => This requires taking a lock but ensures we never hit the same
       IC miss multiple times.

=> We take the latter approach for now.

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

TEST=CL is purely a refactoring.

Change-Id: Ic3b2de61e25de0210323edd732424cc7d1178771
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174465
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-12-02 14:51:07 +00:00
Martin Kustermann 95ad66642e [vm/concurrency] Use ICData::NewWithCheck() when creating new ICData with initial checks
Issue https://github.com/dart-lang/sdk/issues/36097

TEST=Refactoring, covered by existing test suite.

Change-Id: Idb1a3e8024dc257bac31267d7f9657c6faa3cbcb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174464
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-12-01 18:56:15 +00:00
Tess Strickland 52930fe2b9 [vm/compiler] Do not perform non-covariant checks in FFI trampolines.
Since they are accessed via closures, dynamic calls are handled via
dynamic closure call dispatchers and so no non-covariant argument
checking remains at this point.

TEST=Existing FFI tests on trybots, also added a few dynamic cast
tests just in case.

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

Cq-Include-Trybots: luci.dart.try:vm-precomp-ffi-qemu-linux-release-arm-try,vm-ffi-android-product-arm64-try,vm-ffi-android-product-arm-try
Change-Id: If8daa2d71de4e9391dd35b31b62b67a8e7e69ffe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174463
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2020-12-01 16:01:15 +00:00
Jens Johansen 05bac41e39 Revert "[VM] Read and report constant constructor coverage from dill"
This reverts commit 5370c56c80.

Reason for revert: Failures on
dartk-android-product-arm
dartk-android-product-arm
dartkp-linux-release-arm-qemu

like this:

sizeof(ScriptLayout) got 64, Script_InstanceSize expected 56
../../runtime/vm/dart.cc: 160: error: CheckOffsets failed. Try updating offsets by running ./tools/run_offsets_extractor.sh

sizeof(ScriptLayout) got 64, AOT_Script_InstanceSize expected 56
../../runtime/vm/dart.cc: 160: error: CheckOffsets failed. Try updating offsets by running ./tools/run_offsets_extractor.sh


Original change's description:
> [VM] Read and report constant constructor coverage from dill
>
> This CL makes use of the now included constant constructor coverage
> in the dill file.
>
> It works like this:
> * When the CFE evaluates constants, every constant constructor
>   invocation evaluated saves the reference to the constructor in the
>   `Source` (from the Components uri to source table) for the callers
>   Library.
> * This data is loaded into the VM in a "raw" format.
> * When a request for coverage comes in, the VM - on top of the normal
>   coverage processing - goes through all scripts to find constant
>   constructor coverage for the requested script and offset. Note that
>   all scripts must be checked because library A can have evaluated a
>   constructor from library B - so even if only coverage for library B
>   was requested, library A has to be checked.
>   For all constructors found the start and end position is reported as
>   covered. Note that this does not mark any initializes and there are
>   (at least currently) no good way of marking which initializes were
>   evaluated (because it has to be stable across edits even when the
>   `advanced invalidation feature` is enabled).
> * Note that the reason for the coverage to work on references - as
>   hinted above - is because we want it to be stable across hot reloads
>   even if/when advanced invalidation is enabled. This means, that
>   library A cannot record "positional coverage" for library B because
>   library B might get (for instance) new comments that will make any old
>   offsets invalid. By using references we always lookup in the current
>   world and use the correct offsets.
>
> https://github.com/dart-lang/sdk/issues/38934
>
> TEST=Existing test suite, new tests for the new coverage added.
>
> Change-Id: I925963d1a9b9907efe621c72deb7348fa3be5ae8
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171949
> Commit-Queue: Jens Johansen <jensj@google.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Reviewed-by: Vyacheslav Egorov <vegorov@google.com>

TBR=vegorov@google.com,bkonyi@google.com,jensj@google.com

Change-Id: I5187e6749d59ded250ec0933a94db0536485b70a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174470
Reviewed-by: Jens Johansen <jensj@google.com>
Commit-Queue: Jens Johansen <jensj@google.com>
2020-12-01 14:12:16 +00:00
Jens Johansen 5370c56c80 [VM] Read and report constant constructor coverage from dill
This CL makes use of the now included constant constructor coverage
in the dill file.

It works like this:
* When the CFE evaluates constants, every constant constructor
  invocation evaluated saves the reference to the constructor in the
  `Source` (from the Components uri to source table) for the callers
  Library.
* This data is loaded into the VM in a "raw" format.
* When a request for coverage comes in, the VM - on top of the normal
  coverage processing - goes through all scripts to find constant
  constructor coverage for the requested script and offset. Note that
  all scripts must be checked because library A can have evaluated a
  constructor from library B - so even if only coverage for library B
  was requested, library A has to be checked.
  For all constructors found the start and end position is reported as
  covered. Note that this does not mark any initializes and there are
  (at least currently) no good way of marking which initializes were
  evaluated (because it has to be stable across edits even when the
  `advanced invalidation feature` is enabled).
* Note that the reason for the coverage to work on references - as
  hinted above - is because we want it to be stable across hot reloads
  even if/when advanced invalidation is enabled. This means, that
  library A cannot record "positional coverage" for library B because
  library B might get (for instance) new comments that will make any old
  offsets invalid. By using references we always lookup in the current
  world and use the correct offsets.

https://github.com/dart-lang/sdk/issues/38934

TEST=Existing test suite, new tests for the new coverage added.

Change-Id: I925963d1a9b9907efe621c72deb7348fa3be5ae8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/171949
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-12-01 12:32:15 +00:00
Martin Kustermann 33b7721c51 [vm/concurrency] Make Dart_CreateIsolateInGroup() return an error if --enable-isolate-groups is not passed
This is a safeguard to prevent accidental uses of this API by embedders
if those embedders do not pass --enable-isolate-groups.

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

TEST=runtime/tests/vm/dart/isolates/dart_api_create_lightweight_isolate_test.dart

Change-Id: Iba667f0e9fbbb33de963fabb80da546df794257c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174404
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2020-12-01 10:35:54 +00:00
Jens Johansen 9b5764d05d [CFE] Add uri to crashing error message when finding .packages file
TEST=test was changed.

Change-Id: I68c2041e51c66a93f00a0e2be026caef25ddb223
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174241
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-12-01 08:28:24 +00:00
Clement Skau 2d36c85ff8 [vm] Removes support for --causal-async-stacks
All existing embedders have been opted into --lazy-async-stacks, the
VM also uses it as it's default in all configurations.

After this CL, any user of --causal-async-stacks will get an error
message when trying to use it.
=> In any such case, please simply remove the flag.

TEST=Exhaustive CQ.

Bug: https://github.com/dart-lang/sdk/issues/37668
Change-Id: Ia440afcf2dba464aa8b8cf381b93bbac8eb9f8dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172564
Commit-Queue: Clement Skau <cskau@google.com>
Reviewed-by: Clement Skau <cskau@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-01 07:27:14 +00:00
Ryan Macnak d3d92e316b [vm, tsan] Consistently modify the object header as a full word.
An address containing an object header is sometimes interpreted as a object slot due to array truncation and concurrent marking/sweeping. Always accessing it as a word assuages TSAN that it won't be subject to tearing, and allows for the removal of TSAN suppressions from header access. In turn, this will allow TSAN to verify some acquire/release header accesses.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/44091
Change-Id: I7bf6449bf7dfeabd9db76e4bb37456e3be2d5124
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172861
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-11-30 23:43:54 +00:00
Ben Konyi 5ba23bc30e [ VM / Service ] Ensure printRetainingPath handles paths which include
objects stored in Expandos

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

TEST=Updated existing test to include Expando case.

Fixed: 44016
Change-Id: I92edb4347765972ebfd9e1d025529fa96361f6d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173080
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2020-11-30 18:45:02 +00:00
Alexander Aprelev 1702a66338 [vm/concurrency] Guard Field::length updates.
Issue https://github.com/dart-lang/sdk/issues/36097.

TEST=existing test suite

Change-Id: Id345b3f700d731270606b096f9b1225267eea606
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173402
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2020-11-30 16:29:42 +00:00
Daco Harkes ba5e72ebe4 [vm] Replace TARGET_OS_IOS with TARGET_OS_MACOS_IOS
TEST=Manually tested in Flutter iOS build.

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

Change-Id: I47b3bb9eb1fe567e6f14b1c01548b0c0d9b2a683
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173267
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-11-30 16:04:12 +00:00
Vyacheslav Egorov a2acd59d73 [vm/ffi] Fix LR clobber in JumpToFrame stub on ARM
Both ARM and ARM64 variants did not account for the
fact that TransitionNativeToGenerated will clobber
LR on slow path.

TEST=tests/ffi/regress_jump_to_frame_test.dart

Cq-Include-Trybots: luci.dart.try:vm-ffi-android-release-arm-try,vm-ffi-android-release-arm64-try,vm-kernel-linux-release-simarm64-try,vm-kernel-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try
Change-Id: I40d48b720b2a7f31ff20903a887295ab2034662c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173962
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-11-27 09:11:49 +00:00