Commit graph

20862 commits

Author SHA1 Message Date
Tess Strickland d9f15ef891 [vm] Tweak handling of rare types with non-null instance type arguments.
The CFE may return super-bounded types (types that are a strict
supertype of the rare type) for certain type positions like the right
hand sides of `is` and `as` checks, so we can't assume that all types
involving a given class is a subtype of its rare type. Note that this is
only for uses that do not involve instantiation, as all instances of a
class must have runtime types that are a subtype of its rare type.

Keeping this in mind, here are the changes being made in this CL.

-----

In the flow graph builder when producting unoptimized code, we
previously assumed that if the checked type is not equal to the rare
type, then the code can't use _simpleInstanceOf, which only performs
class ID checks.  However, if the checked type is a supertype of the
rare type, we can, because any instance is guaranteed to be a subtype of
the checked type.

Note that this didn't cause incorrect behavior, just more work than
needed in some cases.

-----

In the generation of optimized type testing stubs, we assumed that the
null type argument vector (TAV) is a possible instance TAV for any
instance. However, if the rare type for a class has a non-null TAV, then
no instance of that class can have a null TAV and we can skip the null
check. (We keep it in the DEBUG case, but just to immediately trigger
a breakpoint if seen.)

Again, no incorrect behavior caused here previously, just an unnecessary
check that we now remove in some cases.

------

Also when generating optimized type testing stubs, when checking for the
null TAV prior to instance type argument checks, the code assumed that
it was possible to have to check type arguments if the checked type was
a super type of the rare type for the instance's class.  However, that's
backwards: if the checked type is a super type, then the runtime type of
any instance of the class is guaranteed to be a subtype and we shouldn't
be checking type arguments at all.

Thus, add an ASSERT that checks this, and instead only generate the code
that goes to the runtime if the null TAV is seen, as the runtime type of
the instance is the rare type and the rare type is guaranteed to not be
a subtype of the checked type.

Again, the previous version of this wouldn't have caused incorrect
behavior either, because the VM should never generate type arguments
checking in the type testing stub if the checked type is a supertype of
the class's rare type. Thus, that branch in the code generation was
just dead code.

-----

TEST=vm/cc/TTS, ci (especially DEBUG bots)

Issue: https://github.com/dart-lang/sdk/issues/52848
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64-try,vm-linux-debug-x64-try
Change-Id: I86d159693d6218f88dd1f04dd34cba702744b4d2
Fixed: 52848
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312500
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-07-06 08:16:47 +00:00
Vyacheslav Egorov fa8b149f81 [vm/io] Fix memory leak in FileSystemWatcher_InitWatcher
OSError has a destructor so we need to be careful when
using it with Dart_ThrowException which does not
invoke destructors.

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

TEST=standalone/regress_52715_test with ASAN

R=sstrickl@google.com

Cq-Include-Trybots: luci.dart.try:vm-aot-asan-linux-release-x64-try
Fixed: 52816
Change-Id: I8933c1ae41991586571bc76c35ec7dfc28bab7f1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312301
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-07-04 13:10:42 +00:00
Sergio Martins ea8485e967 [vm] Make Finalizer.attach assert if value is passed as token
It's not supported, as it would prevent the value from being
garbage collected, defeating the purpose of Finalizer.

Not sure if an exception is worth it, so added the assert
as suggested in the bug tracker.

TEST=vm/dart{,_2}/finalizer/finalizer_attach_checks_token_test

Bug: #52731
Change-Id: Id7b457ca1a95e71c1a43d2d2c8569c35659952b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311020
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-07-04 08:28:14 +00:00
Tess Strickland 4141158e2b [gardening] Fix MSVC build after a52f2b9617.
Without this, compiling with MSVC fails with the error:
```
error C2397: conversion from 'int' to 'uint8_t' requires a narrowing conversion
```

TEST=vm-msvc-windows builds

Cq-Include-Trybots: luci.dart.try:vm-msvc-windows-try
Change-Id: I157b8ac9f6f6aaaf31b71d2c0a5f5469d6dc21ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312262
Auto-Submit: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-07-03 14:59:48 +00:00
Tess Strickland 7cc005ea1a [vm] Make Class::RareType() the instantiated to bounds type.
Previously, Class::RareType() returned a Type where the type arguments
were null (e.g., all dynamic). However, this is an invalid type for
classes that have at least one type parameter with a bound that is not a
top type, and could mean that comparisons (such as subtyping) against
the "rare" type could return incorrect answers.

Instead, use TypeParameters::defaults() to get the canonicalized
instantiated to bounds type argument vector and use that instead.

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-linux-debug-x64-try,vm-linux-release-x64-try
Change-Id: Iea591e93102f53713265b481476f9670cfb81c93
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312261
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-07-03 14:52:19 +00:00
Daniel Bali a3e84160ec Expand collection of object instances.
TEST=vm/dart/analyze_snapshot_binary_test

Change-Id: I96ef5d8fc92292151444e52d189e6b2d10a99375
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308303
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-07-03 12:29:15 +00:00
Tess Strickland 85de9c1d7e [vm] Allow STCs that only store instantiator, not function, type args.
If we are generating a SubtypeTestCache for a known type that only
needs instantiator type arguments to be fully instantiated, then
don't store and check against the unneeded function type arguments.

TEST=vm/cc/STC, vm/cc/TTS, ci

Change-Id: I370adf820168079322b8a87811057670a47ee6b3
Cq-Include-Trybots: luci.dart.try:vm-tsan-linux-release-x64-try,vm-reload-rollback-linux-release-x64-try,vm-reload-linux-release-x64-try,vm-linux-release-x64-try,vm-aot-tsan-linux-release-x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-linux-debug-x64-try,vm-mac-debug-arm64-try,vm-aot-mac-release-arm64-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-linux-debug-ia32-try,vm-linux-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311382
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-07-03 10:39:53 +00:00
Alexander Markov 4650178857 Revert "[vm] Improve Class::Hash by also hashing its library"
This reverts commit 1cbb5debeb.

Reason for revert: ../../runtime/vm/compiler/aot/precompiler.cc: 3113: error: expected: api_uses_.HasKey(*entry)

Original change's description:
> [vm] Improve Class::Hash by also hashing its library
>
> Class::Hash previously only hashed class name. This could cause
> hash collisions for top-level classes which have the same name.
>
> Function::Hash uses Class::Hash, so it could also
> suffer from hash collisions among top-level functions.
>
> This change adds hashing of library URI when calculating
> Class::Hash / Function::Hash.
>
> TEST=ci
>
> Change-Id: I8bed681ecb8b8a6b0fceb99866c551ff19a36ab7
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311930
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Commit-Queue: Alexander Markov <alexmarkov@google.com>

Change-Id: I0ec3746d2756cd681695cf4b4304733783df7192
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/312060
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-06-30 17:04:36 +00:00
Alexander Markov 1cbb5debeb [vm] Improve Class::Hash by also hashing its library
Class::Hash previously only hashed class name. This could cause
hash collisions for top-level classes which have the same name.

Function::Hash uses Class::Hash, so it could also
suffer from hash collisions among top-level functions.

This change adds hashing of library URI when calculating
Class::Hash / Function::Hash.

TEST=ci

Change-Id: I8bed681ecb8b8a6b0fceb99866c551ff19a36ab7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311930
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-06-30 15:59:38 +00:00
Vyacheslav Egorov a52f2b9617 [vm] Rework awaiter stack unwinding.
The main contribution of this CL is unification of disparate
handling of various functions like `Future.timeout`,
`Future.wait`, `_SuspendState.createAsyncCallbacks` and
`_SuspendState._createAsyncStarCallback` into a single
`@pragma('vm:awaiter-link')` which allows Dart developers
to specify where awaiter unwinder should look for the next
awaiter.

For example this allows unwinding to succeed for the code like this:

    Future<int> outer(Future<int> inner) {
      @pragma('vm:awaiter-link')
      final completer = Completer<int>();

      inner.then((v) => completer.complete(v));

      return completer.future;
   }

This refactoring also ensures that we preserve information
(including Function & Code objects) required for awaiter
unwinding across all modes (JIT, AOT and AOT with DWARF stack
traces). This guarantees users will get the same information
no matter which mode they are running in. Previously
we have been disabling awaiter_stacks tests in some AOT
modes - which led to regressions in the quality of produced
stacks.

This CL also cleans up relationship between debugger and awaiter
stack returned by StackTrace.current - which makes stack trace
displayed by debugger (used for stepping out and determinining
whether exception is caught or not) and `StackTrace.current`
consistent.

Finally we make one user visible change to the stack trace:
awaiter stack will no always include intermediate listeners
created through `Future.then`. Previously we would sometimes
include these listeners at the tail of the stack trace,
which was inconsistent.

Ultimately this means that code like this:

    Future<int> inner() async {
      await null;  // asynchronous gap
      print(StackTrace.current); // (*)
      return 0;
    }

    Future<int> outer() async {
      int process(int v) {
        return v + 1;
      }

      return await inner().then(process);
    }

    void main() async {
      await outer();
    }

Produces stack trace like this:

    inner
    <asynchronous suspension>
    outer.process
    <asynchronous suspension>
    outer
    <asynchronous suspension>
    main
    <asynchronous suspension>

And when stepping out of `inner` execution will stop at `outer.process`
first and the next step out will bring execution to `outer` next.

Fixes https://github.com/dart-lang/sdk/issues/52797
Fixes https://github.com/dart-lang/sdk/issues/52203
Issue https://github.com/dart-lang/sdk/issues/47985

TEST=ci

Bug: b/279929839
CoreLibraryReviewExempt: CL just adds @pragma to facilitate unwinding
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-dwarf-linux-product-x64-try
Change-Id: If377d5329d6a11c86effb9369dc603a7ae616fe7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311680
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-30 14:03:03 +00:00
Martin Kustermann 45038a2e71 [vm] Avoid repeatedly re-setting stack limits on each dart invocation
Currently every invocation of a dart function will set and later on
reset the stack limits. Doing so requires acquiring locks.

Similarly because we have async ffi callbacks (another way to invoke
dart code) the logic was duplicated there.

Though the stack limit never changes for a given [OSThread]. Isolates
can run on different [OSThread]s throughtout its lifetime. But an
isolate always has to be entered on a native thread before it can
execute dart code.

=> We initialize the stack limit when we scheduling an isolate on a
thread and re-set it when unscheduling it.

=> That centralizes the place to one where we have to deal with stack
limits and avoids repeated acquiring of locks on each embedder dart
function invocation.

TEST=ci

Change-Id: Ia59ba8f92b93c58a990010ec75dfcd879aea2c43
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311960
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-06-29 17:29:48 +00:00
Ryan Macnak ac77af1c07 Group the GC tests into a common directory.
The makes it possible to run just these tests with `test.py vm/gc/`.

Change-Id: Ied4aa0b2fb045c19b1aced68f58a1ef195a5df8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311145
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-29 17:27:48 +00:00
Ryan Macnak 41bb44e93e [vm, gc] Update the write barrier stub to allow for both the generational and incremental barriers triggering.
Currently the generational and incremental barriers cannot both apply for the same store because the former only applies for old->new stores and the latter only applies for old->old stores. Marking through new-space will cause the incremental barrier to apply to all stores.

TEST=ci
Change-Id: I40d492cc8b5b2fff8d5d4bc8625d45f2e6a2d488
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309830
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-29 16:26:48 +00:00
Martin Kustermann 99db606bab [vm] Cleanup [PatchClass] in the VM
The [PatchClass] no longer needs to refer to a original [Class] and a
patched [Class] objects: Since the CFE does handling of patches the VM
only has a single [Class] object, so those two fields are always the
same.

=> Change `PatchClass::{origin_class,patched_class} -> `PatchClass::wrapped_class`

We also remove the `Field::Origin()` / `Function::origin()` methods
as they return the same as the `Owner()` would return.

TEST=ci

Change-Id: Iec0849f6ffc2026760dad89a9bcf07e9469bc8b6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311840
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-06-29 15:03:37 +00:00
Martin Kustermann 63b567add2 [vm] Split isolate initialization logic into two pieces
This splits `Dart::InitializeIsolate()` into

* `Dart::InitializeIsolateGroup()` that sets up an `IsolateGroup`
  => This is only done at isolate group creation time when the very
     first isolate is created.

* `Dart::InitializeIsolate()` that sets up an `Isolate`.
  => This is done for every isolate.

This is purely refactoring / code cleanup.

TEST=ci

Change-Id: Ica906444f79fe49849b9e11e96f7c89184cb9d09
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311603
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-06-29 08:04:20 +00:00
Ryan Macnak 8853472dd6 [vm, gc] Pause concurrent marking during scavenge.
TEST=ci
Change-Id: I7c3deaf4383b993c4c0253a4f94a1d503b2d9a92
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309802
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2023-06-28 16:49:07 +00:00
Slava Egorov 8b6e39696f [vm/io] Avoid leaking Handle::data_ready_ on Windows.
Handle::data_ready_ contains bytes which are ready to be sent to Dart
side. Not all code paths fully drain this buffer and delete it
before destroying the handle, for example directory watch implementation
was prone to leaking data_ready_ when subscription was cancelled.

This CL switches the code to use unique_ptr to hold on to data_ready_
which makes sure that it is deleted when Handle is destroyed.

The code would benefit from holding all OverlappedBuffer instances
through unique_ptr but that is a much larger refactoring which
we leave for a later date.

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

TEST=standalone{,_2}/regress_52715_test

Bug: 52715
Cq-Include-Trybots: luci.dart.try:vm-win-release-x64-try,vm-win-debug-x64-try,vm-aot-win-release-x64-try,analyzer-win-release-try
Change-Id: Ie8d728b823de7e8f9de1489898e270580c2af269
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311841
Commit-Queue: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Slava Egorov <vegorov@google.com>
2023-06-28 13:06:51 +00:00
Vyacheslav Egorov 86c311607a [vm] Fix HeapProfileSampler::SampleOldSpaceAllocation
When Isolate is just starting up and no TLABs are yet present
we were setting interval_to_next_sample_ to -1 which caused
every old space allocation to be sampled.

This CL properly initializes the interval to sampling_interval_
instead.

TEST=vm/cc/DartAPI_HeapSampling_CorrectSamplingIntervalForOldSpaceAllocations

Change-Id: Ieb29234379d3afa4716ebdf3591f9fc0cbcaef71
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311844
Commit-Queue: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
Auto-Submit: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-06-28 12:58:32 +00:00
Martin Kustermann 8f7cf7724c [gardening] Ensure functions use stable hashes across reload
Root cause is that `Function::Hash()` depends on the owner class
id. This causes two issues

a) Issue with reload:

During reload the reloader code will change `Function::owner()`
from a `Class` to a `PatchClass`. This in return will cause a change in
the function's hash, which means we won't find the function in the
closure cache anymore.

b) Issue with app-jit:

As part of app-jit we re-number class ids. This re-numbering would also
render the closure cache as invalid - as the function hash code would
change. So instead the closure cache was cleared entirely. While this
works for AOT, in app-jit we may serialize closure functions and their
code. Though at app-jit runtime we then fail to find the functions in
the closure function cache (as it was cleared during snapshoting)

(This will surface by us triggering an optimizing compile of a function
in the background compiler which will try to make a new `Function`
object for a closure, even though the app-jit snapshot already has one)

To fix these issues we make the `Function::Hash()` stable across reload

  * we use `Function::Owner()` instead of `Function::owner()` (the
    former will always return the actual class, the ladder can return
    the `PatchClass`)

  * we avoid re-hashing the closure cache by making `Function::Hash()`
    use the name of the class instead of the class id

  * we clear out the closure cache array during AOT snapshoting, as this
    is not used in AOT runtime.

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

TEST=Fixes various issues on CI.

Change-Id: I352d0a768df0f29d504cdd80e3533cbedc437b9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311744
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-06-28 11:48:26 +00:00
Martin Kustermann 29509e0124 [gardening] Fix riscv32/riscv64 build
The constants in [0] were not quite correct for riscv.

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

TEST=ci

Change-Id: I194cde2541293935ef89861f3d1607c1913068f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311743
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2023-06-28 09:21:11 +00:00
Johnni Winther 0c8ded72dc [cfe] Add FileUriConstantExpression
This adds FileUriConstantExpression, a subclass of ConstantExpression, to support correct file offset of annotations for augmentations and patches.
The FileUriExpression is used to carry the file uri of the expression
before constant evaluation.

TEST=general/patch_annotations

Change-Id: I0dc8a0cb97dd530fd1960785d38c2d5e4883c3dd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311660
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-06-28 07:52:09 +00:00
Liam Appelbe 13ec07415b [vm] Async FFI callbacks
More details about the design:
https://docs.google.com/document/d/1QDjyY_6wOTOgURwpeYMKU9qEz0gKxx2MUrdruC6Kp6c/edit?usp=sharing

Change-Id: Ie3985d86dca7f5010044ca46c33ca177588c0f69
Bug: #37022
CoreLibraryReviewExempt: Reviewed by vm and api groups. web and wasm groups not affected because FFI isn't on those platforms.
TEST=async_void_function_callbacks_test.dart, ffi_callback_metadata_test.cc, other front end tests
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305900
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-06-28 01:00:18 +00:00
Alexander Markov 12c7455436 [vm] Reset closure functions cache when sorting class ids
Hashes of functions depend on the class ids, so cache of the closure
functions should be cleared when class ids are sorted.
This is safe to do because at that point all compiled code is cleared.

TEST=ci

Change-Id: Iaf3a66d1026611fc0a3df3903cb4e09e6d6c4c17
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311723
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-27 23:08:26 +00:00
Ryan Macnak 274db26c57 [vm, gc] Refactor weak mourning.
TEST=ci
Change-Id: I0d60ed9284651eb49ea2b44edc877083c8c8390d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311152
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2023-06-27 22:23:17 +00:00
Ryan Macnak 4949f6185e [vm, gc] The GC cares about immediate-ness not Smi-ness.
TEST=ci
Change-Id: Ib7bae6df6becf0ed696a4c00257cedaf46f750aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311148
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-27 19:47:04 +00:00
Alexander Markov dc30f815f1 [vm] Inline local functions declared in outer functions
Previously, inliner was able to inline closure calls only when closure
was allocated in the current function (or in a function which was
inlined so far). This is not true for local functions declared in outer
functions (they are allocated at declaration site).

Now, when calling local functions, target of closure call is always
known regardless of where the function is declared, so calls to local
functions can be inlined.

TEST=runtime/tests/vm/dart/inline_local_functions_il_test.dart
Fixes https://github.com/dart-lang/sdk/issues/52695
Fixes https://github.com/dart-lang/sdk/issues/15558

Change-Id: I0e51dbaf63a6d4427bff366b40414ca5fac3d418
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311465
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-06-27 19:42:15 +00:00
Tess Strickland 3a9c1e6d6d [vm] Remove extra DEBUG-only checking in SubtypeNTestCache.
These checks convert what would likely be a segfault into a breakpoint
instead, but they're heavyweight enough on certain tests to cause
timeouts. Remove them as issues here are easily debugged without them.

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

TEST=vm/dart/regress_48523 on debug reload bots

Change-Id: Icf9ea6191eb82c254d9a01fbc9f8ba6255602084
Cq-Include-Trybots: luci.dart.try:vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311621
Auto-Submit: Tess Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-06-27 15:36:38 +00:00
Slava Egorov 758727dd12 [vm] Rename tests causal_stacks -> awaiter_stacks and improve harness.
The main difference from the previous harness is that it
allows auto updating the expectations instead of
maintaining them manually.

This relands 0c1b2722ed with
changes to harness which fix issues on Windows.

Note: some amount of AOT failures are expected and should just
be approved. They will be fixed with the last CL in the series.

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-win-release-x64-try
Change-Id: I7ae84769ed54bc447ebf71acc68ba9d0b6717bac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311604
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Auto-Submit: Slava Egorov <vegorov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-06-27 11:50:32 +00:00
Tess Strickland 516f238aa6 Revert "[vm] Rename tests causal_stacks -> awaiter_stacks and improve harness."
This reverts commit 0c1b2722ed.

Reason for revert: Failures on AOT (stack expectations unmet) and Windows (parse errors due to Windows paths) trybots.

Original change's description:
> [vm] Rename tests causal_stacks -> awaiter_stacks and improve harness.
>
> The main difference from the previous harness is that it
> allows auto updating the expectations instead of
> maintaining them manually.
>
> TEST=ci
>
> Change-Id: I80e303d3ecbcc834ac94fa089cabe4f8834cc661
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311400
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
> Commit-Queue: Slava Egorov <vegorov@google.com>

Change-Id: I7311bf08403f4167f88f6204fde1a6fdee353f7d
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311600
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-06-27 09:02:28 +00:00
Tess Strickland 1df39e243a [gardening] Marking test that creates several snapshots slow on TSAN.
Change-Id: Iba88e9807a7d58d17fe6b2cf103d0f18fe7dbef5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311580
Auto-Submit: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-06-27 08:04:31 +00:00
Vyacheslav Egorov 0c1b2722ed [vm] Rename tests causal_stacks -> awaiter_stacks and improve harness.
The main difference from the previous harness is that it
allows auto updating the expectations instead of
maintaining them manually.

TEST=ci

Change-Id: I80e303d3ecbcc834ac94fa089cabe4f8834cc661
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311400
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-27 07:47:39 +00:00
Vyacheslav Egorov 8d5dbbdf69 [vm/debugger] Rename "causal" to "awaiter" internally
The name is more accurately reflects what this stack trace
contains: despite what causal implies it does *not* actually
reflect the stack which initiated the async operation. Instead
it contains the chain of listeners which will run when
the async operation completes - its awaiters.

TEST=ci

Change-Id: Ie7309c9b1c39246e0fd4c14f7b9c515bcdfbbe10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311384
Reviewed-by: Derek Xu <derekx@google.com>
2023-06-27 07:47:39 +00:00
Vyacheslav Egorov 6e46d4f896 [vm/debugger] Cleanup HandleSteppingRequest
No need to pass parameter explicitly because it is always
equal to the field.

TEST=ci

Change-Id: I04d86786d5278ad4ab4ce6c67e61b1fc94f692d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311383
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-27 07:18:50 +00:00
Vyacheslav Egorov ec15052c7f [vm] Remove old async_debugger flag.
Effectively it is true for all environments where
debugger is actually present.

TEST=service tests

Change-Id: I0592e83004271ca32c107f4347f7bd82172b0a62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310622
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-27 07:18:50 +00:00
Ryan Macnak bbeed85932 [vm, gc] Add some documentation about weakness.
Change-Id: I10ca59a29e3ac951b3e7830e6b90a36a6ac55a75
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311524
Reviewed-by: Alexander Aprelev <aam@google.com>
2023-06-26 23:14:26 +00:00
Ryan Macnak 95bd742546 [vm, gc] Fix missing longjump scope when parallel scavenge processes weak properties.
TEST=ci
Change-Id: I55661f92ec942a1adf36cff1cd020958b531bd8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311522
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-26 23:12:57 +00:00
Vyacheslav Egorov 4a6f9328a2 [vm/debugger] Simplify async breakpoints implementation
We no longer rewrite suspendable function into closures nested
inside the original function, so the whole synthetic async breakpoint
machinery is not needed.

Refactor `Breakpoint` class to make one-shot and per-closure
separate properties of breakpoint, which allows creating
one-shot-per-closure breakpoints.

TEST=existing service tests

Change-Id: I208afe13f36efa40f5746e44867bd24684cf5f03
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310601
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Derek Xu <derekx@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-26 22:45:10 +00:00
Vyacheslav Egorov 401a11d309 [vm] Remove obsolete code from inliner.
Described case no longer happens: either function
is marked as not-inlinable from the very beginning
or graph construction bails out entirely.

TEST=ci

Change-Id: I7e345dc948370050bd6e03a327f1fd1054fc8240
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311401
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-26 21:55:40 +00:00
Vyacheslav Egorov 1a582a6714 [infra] Fix update_line_numbers.dart script
TEST=manually tested

Change-Id: If2132e5610e8965f291b776bcc5cf5bc87a5001f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311341
Auto-Submit: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2023-06-26 20:01:31 +00:00
Alexander Aprelev 238ce4685a [vm/debugger] Update service_2/* tests with debugger() expectations.
Follow-up to bbdf87d277
TEST=ci

Bug: https://github.com/dart-lang/sdk/issues/52785
Change-Id: Ia5c83743efe6222396f63d5df77ebb4e39cbd768
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311440
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2023-06-26 18:46:46 +00:00
Tess Strickland 4aebac3d28 [vm] Verify STC input count matches stub expected input count in DEBUG.
If these checks fail, then a `SubtypeNTestCache` stub has been called
with a `SubtypeTestCache` that uses a different number of inputs
than the stub expects, which could lead to unexpected false negatives
or false positives, so catch it early.

TEST=vm/cc/TTS, ci

Change-Id: Ia9c48aad4c35872cad32b7b6f3eead3ee9e59680
Cq-Include-Trybots: luci.dart.try:vm-mac-debug-arm64-try,vm-linux-debug-x64c-try,vm-linux-debug-x64-try,vm-linux-debug-simriscv64-try,vm-linux-debug-ia32-try,vm-aot-linux-debug-simriscv64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311380
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-06-26 11:54:00 +00:00
Vyacheslav Egorov f1cd87e58e [infra] Tool for updating LINE_* in service tests.
Some of the service tests contain LINE_*
constants which match line numbers of `// LINE_*`
comments in the body of the test. Previously
we would manually maintain these constants,
which is rather tedious.

This CL adds a scripts for updating the
constants automatically.

TEST=manually tested the tool

Change-Id: I3a5cdbd4cae2ab6eaec51c9bb5f48b351bfbbd7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310602
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2023-06-26 10:48:30 +00:00
Tess Strickland 719c0a91dc [vm] Remove UntaggedField::type_test_cache_.
This field is now only used when reloading to check assignability
during `ProgramReloadContext::ReloadPhase4CommitFinish()` (via
`PostCommit()` -> `InvalidateWorld()` -> `InvalidateFields`).

However, the method `DeoptimizeDependentCode()` is called near the
start of the actual reloading process in `Reload` prior to the
commit/rollback phases. This calls `DeoptimizeTypeTestingStubs()`, which
walks the heap and resets the contents of all `SubtypeTestCaches`
(`STC`s).

That means that the `STC` information isn't actually kept between
different reloads, so all this does is cause a number of `STC` objects
to be allocated during reload whose backing arrays are not used
post-reload for anything and so are unnecessary garbage.

That, and the creation of the `STC`s during `InvalidateFields` creates
all-input `STC`s, as they don't just check assignability to a given field type but also for checking elements of `RecordTypes`. That means
the per-field `STC`s contain way more information needed to check for
valid assignments to the corresponding field type, even if the `STC`
was used between reloads.

This CL removes the unnecessary field and changes `InvalidateFields`
so that the `STC`s used during reload are instead lazily allocated once
per `FieldInvalidator` object and now both the `STC` and its backing
array are now garbage post-field invalidation.

TEST=reload ci

Change-Id: I3ffa199551ba69f0afd4eba6303c6ff73d7473a3
Cq-Include-Trybots: luci.dart.try:vm-reload-linux-debug-x64-try,vm-reload-linux-release-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-reload-rollback-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-product-x64-try,vm-aot-linux-release-x64-try,vm-linux-release-x64-try,vm-linux-debug-x64-try,vm-aot-dwarf-linux-product-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311220
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-06-26 09:27:59 +00:00
Tess Strickland 06e099884b [vm] Adjust default value of FLAG_max_subtype_cache_entries flag.
The round default value used in f7e26c50 means that we allocate
a new backing array shortly before hitting the cap, and once we
hit the cap the max load factor for the new backing array is only ~49%.

Instead, given a desired maximum, calculate an appropriate default
value that ensures the cap is only hit shortly before the array reaches
the max load factor that causes reallocation.

TEST=ci

Change-Id: I4c4fc3f5726aea3b260cf288cd00f886c2a1bd96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311280
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-06-26 09:24:57 +00:00
Tess Strickland cefda02d24 [vm] Specify default capture mode for closures used in stub generation.
Without this, when building on Windows using MSVC, we get `error C3493:
'kCacheArrayReg' cannot be implicitly captured because no default
capture mode has been specified`.

TEST=vm-msvc-windows builds

Change-Id: Iebc443ce887dd32b186d51695cbc0bfd95d09f35
Cq-Include-Trybots: luci.dart.try:vm-msvc-windows-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311320
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-06-26 08:40:50 +00:00
Tess Strickland f7e26c508d [vm] Add support for hash-based caches in SubtypeNTestCache stubs.
This also lowers the threshold for converting from a linear cache
to a hash-based cache from 100 to 30 on non-IA32 architectures.
(IA32 still goes to runtime if there's a hash-based cache.)

For SubtypeTestCache benchmarks above this threshold, we see an
improvement varying from ~50-100% to ~700-800% on all architectures,
from lowest number of checks (50) to highest (1000).

For SubtypeTestCache benchmarks below this threshold, no major
changes are seen: generally <5% improvement or <5% regression per
check at most.

TEST=vm/cc/TTS

Change-Id: I83aa7c085ab5a411e944ec660d6b8eba7a788ee0
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-simriscv64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-linux-release-simarm64-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-x64c-try,vm-aot-tsan-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-release-ia32-try,vm-linux-debug-x64c-try,vm-linux-debug-x64-try,vm-linux-debug-simriscv64-try,vm-linux-release-simarm64-try,vm-linux-release-simarm-try,vm-mac-release-arm64-try,vm-mac-release-x64-try,vm-tsan-linux-release-x64-try,vm-reload-rollback-linux-release-x64-try,vm-reload-linux-release-x64-try,vm-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308941
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-06-24 12:56:12 +00:00
Ryan Macnak 1f953c3fe1 [vm, gc] Remove some dead code.
TEST=ci
Change-Id: Ia0d0f181b8d54c3ec0e1cc8f2076bea7854379ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311142
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2023-06-23 20:35:00 +00:00
Ryan Macnak b9843b876d [vm] Prevent nested handling of SIGPROF.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/52765
Change-Id: I14301d67ad245d3df96624155b383cb5f4c7f981
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310975
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2023-06-23 17:01:58 +00:00
Alexander Aprelev bbdf87d277 [vm/debugger] Have debug step check point after debugger() call.
Fixes https://github.com/dart-lang/sdk/issues/46006
TEST=ci

Change-Id: I89a7ad248b75204d1754668cfb23c8d98f554b28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310779
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2023-06-23 16:53:48 +00:00
Tess Strickland 2b1c0f5692 [vm] Reorder SubtypeTestCache inputs to improve non-dynamic cases.
In particular, avoid storing/comparing the destination type unless the
SubtypeTestCache was created for a dynamic AssertAssignable instruction.

TEST=vm/cc/STC_{Linear,Hash}Lookup, vm/cc/TTS

Bug: https://github.com/dart-lang/sdk/issues/48345
Change-Id: I279c69a668ce19785785cf71707acf951f2b2133
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-simriscv64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-linux-release-simarm64-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-x64c-try,vm-aot-tsan-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-release-ia32-try,vm-linux-debug-x64c-try,vm-linux-debug-x64-try,vm-linux-debug-simriscv64-try,vm-linux-release-simarm64-try,vm-linux-release-simarm-try,vm-mac-release-arm64-try,vm-mac-release-x64-try,vm-tsan-linux-release-x64-try,vm-reload-rollback-linux-release-x64-try,vm-reload-linux-release-x64-try,vm-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310340
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-06-22 16:47:59 +00:00
Tess Strickland 0304832202 [vm] Check hash-based caches in the DRT_InstanceOf runtime entry.
We added a hash-based cache check in DRT_TypeCheck until the
SubtypeNTestCache stubs handle hash-based caches to avoid doing
the full runtime check when unnecessary, but did not do so for
DRT_InstanceOf. This fixes that until an upcoming CL that adds
support for hash-based caches in the SubtypeNTestCacheStubs lands.

TEST=Manual inspection of profiles before and after change. Not
adding an automated test as this change is a temporary bandaid
similar to the tested path in DRT_TypeCheck that will be removed soon.

Change-Id: I905a0fc6f501c68d66ae1ee848631c40cad04af2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310882
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-06-22 12:21:58 +00:00
Tess Strickland 97a09b90c8 [sdk] Add NativeRuntime.buildId to dart:developer.
TEST=vm/dart/build_id

Issue: https://github.com/dart-lang/sdk/issues/51941
CoreLibraryReviewExempt: Native runtime only API
Change-Id: Ib3757480f0eab6d147385a87adf657f4f709ec4e
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-product-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-win-release-x64-try,vm-aot-win-product-x64-try,vm-aot-win-debug-x64c-try,vm-aot-android-release-arm_x64-try,vm-fuchsia-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307122
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
2023-06-22 11:11:11 +00:00
Vyacheslav Egorov 8e6290bcb0 [vm] Remove unused ObjectStore::completer_class()
TEST=ci

Change-Id: I074c69dd81e3ed7b9b79f537a2162573d19c776f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310721
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-06-21 18:09:13 +00:00
Alexander Aprelev 7bdbc0560e [vm/win] Use wide-character api for local hostname on Windows.
Fixes https://github.com/dart-lang/sdk/issues/52701
TEST=test locally

Change-Id: Ia38b67cadea3d15824b06d0a2fc69f0c20192bb6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310481
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-06-21 16:57:49 +00:00
Tess Strickland dfc1b6b16b [vm] Store the number of used inputs in SubtypeTestCaches.
Previously, SlowTypeTestStub would use the incoming instance and
destination type to determine which `SubtypeNTestCacheStub` to call,
where `N` is the number of inputs checked for each entry. The code
for generating `InstanceOf` instructions performs similar work,
inlining some checks and then falling back to checking and updating
an appropriate `SubtypeNTestCacheStub` if the inlined checks fail.

Meanwhile, the runtime would use all available information to
create a new entry when needed, depending on the `SubtypeNTestCacheStub`
called at runtime to ignore the parts of the entry it didn't need.

To illustrate a situation where the runtime might use more
information to create an entry than needed by the stub, consider
the following class header:

```
  class C<T> extends D
```

If no subtype of `D` requires knowing the specific type arguments for
an instance to determine whether that instance is an instance of `D`,
then the compiler can generate a `Subtype1TestCacheStub` call, where
only the class id of the instance is checked.

However, in the runtime, when updating the cache, the runtime will
create an entry that includes the specific type arguments used to
instantiate `C` when the initial cache miss occurred, as the runtime
does not know how many inputs the code that checks that SubtypeTestCache
uses. If the cache has grown to the point that it is hash-based, that
means the runtime uses the instance type arguments of the first cache
miss to determine the correct place to create a new entry.

When the stub only performs a linear search over the cache contents,
this works, as every entry is checked until a matching entry is found,
and thus the stub can ignore unneeded information. However, if a cache
is hash-based, this doesn't work: if the first miss was an instance
of `C<int>`, then the runtime includes all that information in a new
entry. This means the stub has to calculate the instance type
arguments, which it did not have to do before, and if a subsequent
check uses different instance type arguments (e.g., an instance of
`C<String>`), the result may still be a cache miss, and the runtime
adds another entry which has the same information as the previous
entry as far as the stub was originally concerned.

Thus, to limit itself to considering only the inputs used by the
appropriate `SubtypeNTestCacheStub`, the runtime needs to be told how
many inputs are used. This CL adds an additional field to
`SubtypeTestCache`s which contains the number of used inputs, and
changes the places where `SubtypeTestCache`s are allocated in the
flow graph compiler and the `DRT_TypeCheck` runtime entry to pass the
appropriate number of inputs. To ensure that the runtime and stubs
agree on how many inputs should be used, the `SlowTypeTestStub` now
uses the value of this field to determine which `SubtypeNTestCacheStub`
to call.

TEST=vm/cc/STC_{Linear,Hash}Lookup

Bug: https://github.com/dart-lang/sdk/issues/48345
Change-Id: Ie16f2d12c4c5eae856b668f28178818203662d1c
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-simriscv64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-linux-release-simarm64-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-release-ia32-try,vm-linux-debug-x64c-try,vm-linux-debug-x64-try,vm-linux-debug-simriscv64-try,vm-linux-release-simarm64-try,vm-linux-release-simarm-try,vm-mac-release-arm64-try,vm-mac-release-x64-try,vm-tsan-linux-release-x64-try,vm-reload-rollback-linux-release-x64-try,vm-reload-linux-release-x64-try,vm-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310180
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-06-21 15:24:30 +00:00
Tess Strickland 24ad7f9000 [vm/tests] Skip vm/cc/TypeArguments_Cache_ManyInstantiations on qemu.
This is just a larger version of another test
vm/cc/TypeArguments_Cache_SomeInstantiations, which does run on
qemu and tests the same paths, so it's okay to skip.

TEST=vm-linux-release-riscv64-qemu

Change-Id: Ie39665c818cc95c934582383b5e57d77f539f46d
Cq-Include-Trybots: luci.dart.try:vm-ffi-qemu-linux-release-riscv64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310680
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Auto-Submit: Tess Strickland <sstrickl@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-06-21 14:43:25 +00:00
Tess Strickland 9a6c33571f [vm] Set page_size_ to 0 after deleting the compressed heap.
When DEBUG is defined, deleting the compressed heap uses the
page size to check alignments.

TEST=*-debug-{x64c,arm64c} builds

Change-Id: Idc0c3fd213d1639234ae52a19466843464790e64
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64c-try,vm-aot-win-debug-x64c-try,vm-linux-debug-x64c-try,vm-win-debug-x64c-try,vm-ffi-android-debug-arm64c-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310581
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Tess Strickland <sstrickl@google.com>
2023-06-21 11:39:50 +00:00
Ryan Macnak dbd7b967af [fuchsia] Plumbing for the VMEX resource.
TEST=ci
Change-Id: I2e812e6eef2a3c6f91aec955609ece2ca4df15a1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308805
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-20 19:28:18 +00:00
Alexander Markov 66f1611fee [vm] Deoptimize code if can-be-Future property of a class changes due to dynamic loading
Sometimes compiler omits type checks for the 'await' and 'return from
async' by relying on the fact that certain classes cannot hold
instances of Future.

In JIT mode, the property 'class-can-be-Future' may change when a new
class is loaded dynamically (e.g. through IsolateMirror.loadUri).

In such a case, the generated code assuming that certain class
cannot be Future should be correctly deoptimized.
This CL implements this deoptimization by adding such classes into
the list of CHA guarded classes.

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

Change-Id: Ib3a3768d073e8562b794186e72cb9d61e9f496fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309822
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-06-20 17:17:34 +00:00
Martin Kustermann ef97228d03 [vm] Make vm/dart/regress_52703_test work on android
Closes https://github.com/dart-lang/sdk/issues/52739

TEST=vm/dart/regress_52703_test on Android

Change-Id: Ia568044d6663483e446c1945de70298c5bc111fd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/310281
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-06-20 13:31:29 +00:00
Daco Harkes 1bc47181f2 [test] Fix line number expectation
Because of the `// @dart = 2.9` comment, everything is two lines down.

TEST=runtime/tests/vm/dart_2/checked_parameter_assert_assignable_stacktrace_test.dart

Closes: https://github.com/dart-lang/sdk/issues/52737
Change-Id: If2b4d22f933ed975a0623eb6d8e2f6c674bf9177
Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64-try,vm-kernel-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309901
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
2023-06-20 13:26:55 +00:00
Jens Johansen 12d0d34b00 [VM] Add token position to type argument AssertAssignable call
This CL adds the token position of the checked parameter when doing the
AssertAssignable for better stacktraces when it fails.

E.g.

```
$ cat t.dart
class A {
  void takesA(A a) {
    print("Hello A");
  }
}
class B extends A {
  void takesA(covariant B b) {
    print("Hello B");
  }
}

void main() {
  A a = new A();
  A b = new B();
  b.takesA(b);
  b.takesA(a);
}
```

Before fix:

```
$ out/ReleaseX64/dart t.dart
Hello B
Unhandled exception:
type 'A' is not a subtype of type 'B' of 'b'
#0      B.takesA (file:///path/to/t.dart)
#1      main (file:///path/to/t.dart:16:5)
[...]
```

With fix:

```
$ out/ReleaseX64/dart t.dart
Hello B
Unhandled exception:
type 'A' is not a subtype of type 'B' of 'b'
#0      B.takesA (file:///path/to/t.dart:7:27)
#1      main (file:///path/to/t.dart:16:5)
[...]
```

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

Change-Id: I6409f6d9c41e9825391957f0df2b92b48ed0eb7a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302203
Commit-Queue: Jens Johansen <jensj@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-06-19 11:32:27 +00:00
Liam Appelbe 5f7a3910fe [vm] Remove ProcessStarter on iOS
Bug: https://github.com/dart-lang/sdk/issues/45452
Fixes: https://github.com/dart-lang/sdk/issues/45452
Change-Id: I85fe624b64b8fac1e0a24a817f197c715dab3e27
TEST=CI and manual testing on iPhone
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193525
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
2023-06-19 00:25:12 +00:00
Ryan Macnak c6b49d984f [vm, gc] Update WaitForSweeperTasks to know there are non-sweeper concurrent tasks.
TEST=ci
Change-Id: I91b7c2dfffe28fac6a9e31622209f8c22fa85822
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309801
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-16 20:53:00 +00:00
Ryan Macnak 18a905f117 [vm, gc] Parallelize handling of large pages during compaction.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/52513 (benchmark)
Change-Id: I4c30e9f148e90255e616bc8ea23f0778c1117b81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308164
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-16 15:37:37 +00:00
Martin Kustermann 3dd9389c1f [vm] Fix leakage of file system watcher related data structures
Closes https://github.com/dart-lang/sdk/issues/52703

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

Change-Id: Ia76c721a3d3a1466ed1c2e7bd847c331cee95ed7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309862
Reviewed-by: Lasse Nielsen <lrn@google.com>
Auto-Submit: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-06-16 12:08:43 +00:00
Ilya Yanok ac06671ac6 Revert "[vm] Mark Zone memory as unallocated/allocated/uninitialized for Address and Memory Sanitizer."
This reverts commit c7b288492a.

Reason for revert: breaks tests in G3, b/287581831

Original change's description:
> [vm] Mark Zone memory as unallocated/allocated/uninitialized for Address and Memory Sanitizer.
>
> TEST=ci
> Change-Id: Ia283d9aefec767e6ccc4f1c88abba73ce1c35e87
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212022
> Reviewed-by: Brian Quinlan <bquinlan@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

Change-Id: I94ce2141e7b16c8e4be6641253e37dfa82698486
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309861
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2023-06-16 11:22:38 +00:00
Martin Kustermann ddc236ba64 [vm] Add @pragma('vm:keep-name') annotation
This allows us to keep symbol names for classes/methods/fields - even if
obfuscation is enabled, but has no other effect on tree shaker / ...

For go/dart-ama

TEST=vm/dart/keep_name_pragma_test

Change-Id: I66c0fc32217d9180f821658bae463f2c1d7fb1af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309740
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Auto-Submit: Martin Kustermann <kustermann@google.com>
2023-06-16 10:22:23 +00:00
Tess Strickland 1912fcc50b [vm] Make type testing stubs tests more precise.
Use `#if defined(TESTING)` for defining and using test-only flag
variables.

TTSTestCase had several flag fields where most of the flag fields should
not be set at the same time. Instead, use a separate `expected_result`
field that precisely states what type of result we expect from running
the test, and perform more precise checking of the expected state prior
to invocation and after invocation based on that.

Remove the old `TESTING_runtime_fail_on_existing_STC_entry` flag
variable and the abort it caused when set if an STC entry was found
when entering the runtime. Instead, replace it with two new flag
variables:

* `TESTING_runtime_entered_on_TTS_invocation`: whether the runtime
  was entered for any reason during TTS invocation.
* `TESTING_found_hash_STC_entry`: whether we found an entry in a
  hash-based STC, and so didn't perform runtime assignability checking.

Also modify most of the tests to check that either running the same
test case twice gives the same results, or in the case of
`kNewSTCEntry`, that a subsequent run with `kExistingSTCEntry` finds
the added entry.

TEST=vm/cc/TTS

Change-Id: Ibc3f49766494d0c61e2f78835637b9596b7f2db7
Cq-Include-Trybots: luci.dart.try:vm-linux-debug-x64-try,vm-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309285
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-06-16 09:11:58 +00:00
Derek Xu be125afc18 [VM/Service] Create package:vm_service_protos for distributing code for working with Perfetto protos
TEST=get_perfetto_vm_timeline_rpc_test and
get_perfetto_cpu_samples_rpc_test

Change-Id: I4a001ec634b939a258e337630633ce826e0f8b4d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303022
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-06-15 19:01:00 +00:00
Simon Binder 62488db4da [vm/ffi] Add DynamicLibrary.close()
This adds the `close()` method to `DynamicLibrary`, which uses
`dlclose()` on Unix and `FreeLibrary` on Windows to close a dynamic FFI
library.

TEST=tests/ffi/dylib_close_test.dart
Closes https://github.com/dart-lang/sdk/issues/40159

Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-riscv64-try,vm-ffi-qemu-linux-release-arm-try,dart2wasm-linux-d8-try,dart2wasm-linux-chrome-try,vm-reload-rollback-linux-debug-x64-try,vm-reload-linux-debug-x64-try,vm-win-debug-x64c-try,vm-win-debug-x64-try,vm-aot-android-release-arm_x64-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-asan-linux-release-x64-try,vm-aot-msan-linux-release-x64-try,vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-x64-try,vm-aot-mac-release-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try
CoreLibraryReviewExempt: `dart:ffi` VM only API.
Change-Id: I73af98677b481902fe548bdcee56964a0195faf0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307680
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-06-15 17:19:37 +00:00
Ryan Macnak 218ef4712b [vm] Unpoison memory before zapping.
Zapping is applied to the whole segment, not just what had been allocated, and the unallocated portion is poisoned.

TEST=debug asan
Change-Id: I2e0d42f97dda4d38fc2579b54d8e171ee88098fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309781
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
2023-06-15 16:53:25 +00:00
Alexander Markov 47abd96c5b Reland "[vm] Fix CompileType::CanBeFuture()"
This is a reland of commit 6f4bed30cc

Original change's description:
> [vm] Fix CompileType::CanBeFuture()
>
> In certain cases compiler can omit a type check in 'await e' if it can
> prove that expression 'e' cannot be evaluated to Future.
>
> Previously, if actual type of 'e' is unknown, CompileType::CanBeFuture()
> tested if static type of 'e' is a subtype of Future.
>
> This is not correct, as static type could have a subtype which is also
> a subtype of Future, but static type itself is not a subtype of Future:
>
> class A {}
> class B implements A, Future<A> {}
>
> A e = confuse(B()); // 'e' is B, but has a static type A.
> await e;            // A is not a subtype of Future, but 'e' is Future
>                     // and should be awaited.
>

TEST=language/async/await_flatten_test
Fixes https://github.com/dart-lang/sdk/issues/52585

Change-Id: I37add9021261c95dee5930e031187868e821c161
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309481
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-06-15 00:34:18 +00:00
Ryan Macnak c7b288492a [vm] Mark Zone memory as unallocated/allocated/uninitialized for Address and Memory Sanitizer.
TEST=ci
Change-Id: Ia283d9aefec767e6ccc4f1c88abba73ce1c35e87
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212022
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-14 21:50:17 +00:00
Ryan Macnak ff378c0e79 [vm] Fix building with older sysroots.
Cf. dfce3aa0ff

TEST=https://ci.chromium.org/p/fuchsia/g/dart/console
Change-Id: I8c385931548bace9d0753f7dcbae829eff0079bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309520
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2023-06-14 20:36:48 +00:00
Alexander Markov fc950c75e8 Revert "[vm] Fix CompileType::CanBeFuture()"
This reverts commit 6f4bed30cc.

Reason for revert: g3 failure (b/287294480).

Original change's description:
> [vm] Fix CompileType::CanBeFuture()
>
> In certain cases compiler can omit a type check in 'await e' if it can
> prove that expression 'e' cannot be evaluated to Future.
>
> Previously, if actual type of 'e' is unknown, CompileType::CanBeFuture()
> tested if static type of 'e' is a subtype of Future.
>
> This is not correct, as static type could have a subtype which is also
> a subtype of Future, but static type itself is not a subtype of Future:
>
> class A {}
> class B implements A, Future<A> {}
>
> A e = confuse(B()); // 'e' is B, but has a static type A.
> await e;            // A is not a subtype of Future, but 'e' is Future
>                     // and should be awaited.
>
> TEST=language/async/await_flatten_test
> Fixes https://github.com/dart-lang/sdk/issues/52585
>
> Change-Id: I270a8260224246e1f8c16eff57231363a0f25ae6
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309380
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

Change-Id: I87a08e46b4af6c57efa828c0f9041e6b5e51708e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309480
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-06-14 19:32:07 +00:00
Alexander Markov 6f4bed30cc [vm] Fix CompileType::CanBeFuture()
In certain cases compiler can omit a type check in 'await e' if it can
prove that expression 'e' cannot be evaluated to Future.

Previously, if actual type of 'e' is unknown, CompileType::CanBeFuture()
tested if static type of 'e' is a subtype of Future.

This is not correct, as static type could have a subtype which is also
a subtype of Future, but static type itself is not a subtype of Future:

class A {}
class B implements A, Future<A> {}

A e = confuse(B()); // 'e' is B, but has a static type A.
await e;            // A is not a subtype of Future, but 'e' is Future
                    // and should be awaited.

TEST=language/async/await_flatten_test
Fixes https://github.com/dart-lang/sdk/issues/52585

Change-Id: I270a8260224246e1f8c16eff57231363a0f25ae6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309380
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-06-14 19:18:26 +00:00
Ryan Macnak 0abd362a3e [build] Flutter Engine uses a different Fuchsia SDK setup.
TEST=engine
Change-Id: I776af7dfe3bb5582491bd82c135a71e29cb1d0f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309340
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-06-14 16:19:13 +00:00
Tess Strickland 1100859b7e [vm] Fix STC lookup during hot reload.
TEST=reload

Change-Id: I7345a8babaa9df87afca8777d5a3edaef8f2475c
Cq-Include-Trybots: luci.dart.try:vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/309240
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-06-14 11:45:36 +00:00
Johnni Winther 7226c7245e [kernel] Remove RedirectingFactory node
Closes #28421
Closes #29169

TEST=existing

Change-Id: Iee7d84fadc10981648cb327589fd7aa15b9b3e12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308140
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Johnni Winther <johnniwinther@google.com>
2023-06-14 06:38:32 +00:00
Ryan Macnak 3220e31e99 [fuchsia] Don't use zx_vmo_replace_as_executable during process spawning.
TEST=ci
Change-Id: Ibe95541d3439cae5215344d886d75dc0632771c3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308810
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-14 01:38:34 +00:00
Ryan Macnak f779164902 [vm] Avoid generated code knowing about handles.
The safepoint transition has occurred sufficiently before invoking the entry stub since 26f235faf5.

TEST=ci
Change-Id: I68d92de0aa8b831dd3848acce0e9897060487a84
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296342
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-13 21:49:14 +00:00
Tess Strickland 6bdb88b8f6 [vm] Load-acquire the backing array for the cache.
TEST=iso-stress-linux

Change-Id: I79f8565e111066c7ab3652a48211b9630055f5b2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308900
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-06-13 12:46:58 +00:00
Tess Strickland 396796fba9 [vm] Abstract out pieces of SubtypeTestCache stubs across architectures.
Also eliminates the need to store the delayed type arguments on the
stack during the search loop on ARM.

TEST=vm/cc/TTS

Change-Id: Ife01cc8d255724c272bc277eec397486cedc07a7
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-simriscv64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-linux-release-simarm64-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-x64c-try,vm-aot-tsan-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-release-ia32-try,vm-linux-debug-x64c-try,vm-linux-debug-x64-try,vm-linux-debug-simriscv64-try,vm-linux-release-simarm64-try,vm-linux-release-simarm-try,vm-mac-release-arm64-try,vm-mac-release-x64-try,vm-tsan-linux-release-x64-try,vm-reload-rollback-linux-release-x64-try,vm-reload-linux-release-x64-try,vm-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307681
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-06-13 09:53:12 +00:00
Tess Strickland c93c5bdd88 [vm] Use hash-based caches for large SubtypeTestCaches.
We use specialized type testing stubs in `as` checks to quickly answer
whether the type of an object is assignable to a given type. However,
perfect specialization of the type testing stub is not possible in all
cases. Thus, we use SubtypeTestCaches (STCs) to cache the result of
checking assignability in the runtime to avoid repeated runtime calls
for the same check.

Previously, the STC was linear and capped at 100 entries. This cap was
for two reasons:

* STC are created per `as` check, not per checked type, so there could
  be many STCs created for a given type if assignability to that type
  is checked many times throughout the code.
* STC were strictly linear, and thus eventually the cost of
  traversing the cache outweighs the cost of returning a false
  negative that requires going to the runtime and doing the check there.

This CL provides a partial solution to the second reason by performing
similar work to that done for instantiation caches in TypeArguments
(4f925105), where the STC is linear up to a certain threshold, and then
converted to a hash-based STC. Like that CL, only the runtime currently
handles the lookup of cached results in hash-based STCs, with the
changes needed for the `SubtypeNTestCacheStub`s coming in a followup CL.

Since the stubs have not yet been adjusted, we keep the maximum size of
linear caches the same at 100, and allow hash-based STCs to grow to a
maximum size of 1000 since the STCs are still created per `as` check.
This means once the STC has grown over 100 entries, all STC checks
require a runtime call, but for checks cached in the STC, the answer is
found and provided without either doing the slower full runtime check
for assignability and without an attempt to respecialize the type
testing stub when applicable.

Our benchmarks generally see at most a ~2-5% performance regression for
cases where the STC remains linear (except for on the Raspberry Pi 4, where the hit ranges from ~25%-40%), but a performance improvement of
~500-1300% for cases where the STC is converted to a hash table.

TEST=vm/cc/TTS_STC_{Some,Many}Asserts

Change-Id: Ie8629708b5c12fa8464359a2f77c6da56ba46c0c
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-simriscv64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-linux-release-simarm64-try,vm-aot-linux-release-simarm_x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-release-ia32-try,vm-linux-debug-x64c-try,vm-linux-debug-x64-try,vm-linux-debug-simriscv64-try,vm-linux-release-simarm64-try,vm-linux-release-simarm-try,vm-mac-release-arm64-try,vm-mac-release-x64-try,vm-tsan-linux-release-x64-try,vm-reload-rollback-linux-release-x64-try,vm-reload-linux-release-x64-try,vm-ffi-qemu-linux-release-arm-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284682
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-06-13 09:53:12 +00:00
Johnni Winther e831cb8510 [cfe] Check @patch annotations
This normalizes the checking of patches so that it matches the checking
of augmentations. This means that the @patch annotation must and can
only be used on patches.

The dart: libraries and patches have been updated accordingly.

TEST=ffi

Change-Id: I78767eebd1a8861859067ae5ff9c0339f0985bb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306041
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-06-13 07:27:08 +00:00
Ryan Macnak 73e1f83404 [vm, compiler] Honor kNewAllocatableSize.
TEST=ci
Change-Id: Ica8e167f8d67899d1a5f55cd18b1b1e02d422236
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306904
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-12 19:48:37 +00:00
Derek Xu f98f292708 Reland "[VM/Timeline] Add Dart_RecordTimelineEvent Embedder API to support reporting flow events that can be serialized in Perfetto's format"
Patchset 1 is a reland of commit
f52bdb96aa, and Patchset 2 adds a
corrected reland of commit 0d0e301979.

The leak in g3 was caused by moving the `state_ = 0;` line before the
`owns_label()` check in `TimelineEvent::Reset`.

TEST=Ran the g3 tests that were failing on a cbuild copy with these
changes (sponge2/1134a5bb-5168-4e4c-bb03-72a7d7ad6ab4).

Original change's description:
> [VM/Timeline] Add Dart_RecordTimelineEvent Embedder API to support reporting flow events that can be serialized in Perfetto's format
>
> Added a deprecation notice to Dart_TimelineEvent as well.
>
> TEST=Used the embedder API to report an events of each of the following types:
> Dart_Timeline_Event_Begin, Dart_Timeline_Event_Duration,
> Dart_Timeline_Event_Instant, Dart_Timeline_Event_Async_Begin, and
> Dart_Timeline_Event_Async_Instant, each associated with flow IDs. Then,
> retrieved the trace using GetPerfettoVMTimeline and checked that flow arrows
> were displayed correctly in the Perfetto trace viewer.
>
> Change-Id: I82e49554b5970767e306dc4149a782e99a5c6512
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302963
> Commit-Queue: Derek Xu <derekx@google.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>

Change-Id: I08783d6b5575fb3fe43da3203e58902bf9b7d038
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308721
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-06-12 19:31:38 +00:00
Ryan Macnak baf2163e19 [test] Don't try to query RSS under QEMU.
It appears either the effects of madvise(DONTNEED) aren't emulated or we're confounded by the memory usage of the emulator itself.

Bug: https://github.com/dart-lang/sdk/issues/52653
Change-Id: I14d5efabb7413ed14ddc60426a3e7e4a796f3a60
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308740
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
2023-06-12 18:16:21 +00:00
Ryan Macnak b594b409cc [test] Ensure the sweeper completes before querying heap capacity.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/52681
Change-Id: I13e3047a30a4619782518e23cbcc26af0a570c3c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308741
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-12 18:03:49 +00:00
Derek Xu 524cf849b2 Revert "[VM/Timeline] Add Dart_RecordTimelineEvent Embedder API to support reporting flow events that can be serialized in Perfetto's format"
This reverts commit f52bdb96aa.

Reason for revert: https://dart-review.googlesource.com/c/sdk/+/308360
was reverted due to g3 problems, and the code in this CL will leak
without the code in that CL.

Original change's description:
> [VM/Timeline] Add Dart_RecordTimelineEvent Embedder API to support reporting flow events that can be serialized in Perfetto's format
>
> Added a deprecation notice to Dart_TimelineEvent as well.
>
> TEST=Used the embedder API to report an events of each of the following types:
> Dart_Timeline_Event_Begin, Dart_Timeline_Event_Duration,
> Dart_Timeline_Event_Instant, Dart_Timeline_Event_Async_Begin, and
> Dart_Timeline_Event_Async_Instant, each associated with flow IDs. Then,
> retrieved the trace using GetPerfettoVMTimeline and checked that flow arrows
> were displayed correctly in the Perfetto trace viewer.
>
> Change-Id: I82e49554b5970767e306dc4149a782e99a5c6512
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302963
> Commit-Queue: Derek Xu <derekx@google.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>

Change-Id: I98a259c7de8fa4b7dbcbe42f7332ab20b553e9cc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308680
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-06-12 15:40:07 +00:00
Tess Strickland dfce3aa0ff [vm] Attempt to retrieve build ID or UUID from the loaded snapshot.
For direct-to-ELF snapshots, the story remains the same as before,
as we use the information from the Image header if available.

If it isn't, then we fall back to dladdr to get the dynamic shared
object containing the app snapshot and then walk the ELF or Mach-O
headers to find the build ID or UUID information.

TEST=vm/dart/use_dwarf_stack_traces_flag

Issue: https://github.com/dart-lang/sdk/issues/51941
Change-Id: I3705ed244d1b4a1255e75fffd238a29fc2a60800
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-simarm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-product-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-linux-product-x64-try,vm-aot-win-release-x64-try,vm-aot-win-product-x64-try,vm-aot-win-debug-x64c-try,vm-aot-android-release-arm_x64-try,vm-aot-android-release-arm64c-try,vm-fuchsia-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306640
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-06-12 15:26:29 +00:00
Ilya Yanok 84a6b3197b Revert "[VM/Timeline] Reset flow_ids_ in TimelineEvent::Reset"
This reverts commit 0d0e301979.

Reason for revert: breaks tests in G3, see b/286799580

Original change's description:
> [VM/Timeline] Reset flow_ids_ in TimelineEvent::Reset
>
> TEST=Ran the vm/cc/DartAPI_TimelineEvents_Serialization test with ASAN.
>
> Fixes: https://github.com/dart-lang/sdk/issues/52652
> Change-Id: I665c7fc6c8fa2a12c24b579386b1373f7e63792c
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308360
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Derek Xu <derekx@google.com>

Change-Id: I344320d97cb414f29b627859f71fba4967073062
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308660
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Ilya Yanok <yanok@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-06-12 10:35:27 +00:00
Tess Strickland d735c5d3bc [vm] Fix regression where separate debugging info is obfuscated.
TEST=vm/dart/unobfuscated_static_symbols_test

Fixes: b/286598307
Change-Id: I7db0f803147bd00e414e0ef72a195189661a8c8b
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308620
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2023-06-12 09:42:04 +00:00
Derek Xu 63f9cd722a [VM/Service] Add isolateGroup property to Event
TEST=reload_sources_rpc_triggers_isolate_reload_event_test.dart
Change-Id: I0669d09461f147226f1dd2a598896e9a6b44d9b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308221
Commit-Queue: Derek Xu <derekx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2023-06-09 17:57:12 +00:00
Derek Xu 0d0e301979 [VM/Timeline] Reset flow_ids_ in TimelineEvent::Reset
TEST=Ran the vm/cc/DartAPI_TimelineEvents_Serialization test with ASAN.

Fixes: https://github.com/dart-lang/sdk/issues/52652
Change-Id: I665c7fc6c8fa2a12c24b579386b1373f7e63792c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308360
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-06-09 16:18:47 +00:00
Martin Kustermann 70064fcdbb [vm] Remove Isolate::ic_miss_code, make stub use it from Thread
The `Isolate::ic_miss_code()` is always initialized to
`StubCode::SwitchableCallMiss()`. That stub is already cached on the
`Thread` object.

=> No need for the field in `Isolate`.

TEST=ci

Change-Id: Ie3f32b4a800c6f43007a0599ab386b7bb78653c1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308304
Reviewed-by: Tess Strickland <sstrickl@google.com>
2023-06-09 14:43:21 +00:00
Alexander Markov 8cf12b0b30 [vm] Remove graph intrinsics for implicit getters and setters
Now that compiler supports generating functions without a frame,
graph intrinsics for implicit getters and setters are not better than
normal optimized body of implicit getters and setters.

This change cleans up these graph intrinsics.

TEST=existing
Closes https://github.com/dart-lang/sdk/issues/52466

Change-Id: I42c0498fe919474de21f7c077b1fb2aab03089ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308160
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-06-09 14:15:28 +00:00
Tess Strickland 6d71b30ad0 [gardening] Mark vm/dart/regress_48523_test as Slow on TSAN.
Change-Id: Ia31ce705076eba125cbce4321430fb676cb424c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308343
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Tess Strickland <sstrickl@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-06-09 13:32:37 +00:00
Martin Kustermann d962f3562c [vm] Make Thread::EnterIsolate() return void as it always succeeds
TEST=ci

Change-Id: Iebec6ee16e8750418ef2968b08f501fd9a3c2106
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308042
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-06-09 11:45:45 +00:00
Tess Strickland aec34fa6a2 [gardening] Mark ManyInstantiations slow on qemu bots.
Change-Id: Iaebebf24006dd5b0439e35bb0a07ddc1718b6d9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308320
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Tess Strickland <sstrickl@google.com>
2023-06-09 09:31:40 +00:00
なつき 99c68b013b Add missing include for errno.h
Closes https://github.com/dart-lang/sdk/pull/52648

GitOrigin-RevId: 1e7b71080fdc5ea1fd810b78e4e5ec0a6c69a71d
Change-Id: I0b516e22dc4802e9f090b3ddaca49e2cb99f3cf8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308280
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-06-09 08:29:30 +00:00
Derek Xu f52bdb96aa [VM/Timeline] Add Dart_RecordTimelineEvent Embedder API to support reporting flow events that can be serialized in Perfetto's format
Added a deprecation notice to Dart_TimelineEvent as well.

TEST=Used the embedder API to report an events of each of the following types:
Dart_Timeline_Event_Begin, Dart_Timeline_Event_Duration,
Dart_Timeline_Event_Instant, Dart_Timeline_Event_Async_Begin, and
Dart_Timeline_Event_Async_Instant, each associated with flow IDs. Then,
retrieved the trace using GetPerfettoVMTimeline and checked that flow arrows
were displayed correctly in the Perfetto trace viewer.

Change-Id: I82e49554b5970767e306dc4149a782e99a5c6512
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302963
Commit-Queue: Derek Xu <derekx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2023-06-08 21:32:38 +00:00
Vyacheslav Egorov 0b62bb66ed [vm/io] Make sure to write until EAGAIN on POSIX
We are using `epoll()` in edge-triggerred mode, which requires
us to hit `EAGAIN` on `write()` before we are guaranteed
to receive an `EPOLLOUT` event.

`_SocketStreamConsumer` looks at `_NativeSocket.writeAvailable`
after issuing a `write` to decide whether it should continue
writing or pause and wait until event handler sends us `writeEvent`.

However we did not previously set `writeAvailable` to `true` until
the first `writeEvent` arrived, which lead to a hang on some
Linux servers: we would write a small amount of bytes into a pipe
and then wait for `writeEvent`, which would never come, as `epoll()`
is only guaranteed to wake up with `EPOLLOUT` if we hit `EAGAIN`
on `write()`.

This CL also changes `_NativeSocket.nativeWrite` implementation
to write bytes into the file descriptor until it gets EAGAIN.
This reduces the number of roundtrips between Dart and
native.

Unfortunately this CL does not come with a regression test
because it is relying on concrete `epoll()` behaviour and it this
behaviour does not reproduce for me.

TEST=Tested manually on the affected servers.

FIXED=b/286346121

Fixed: 286346121
Change-Id: I37fef9aa12b1da724b035aa9577b414a8057217e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/308101
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-08 13:17:28 +00:00
Christophe B b66afce6ca Add missing void in function declarations to avoid warning
Closes https://github.com/dart-lang/sdk/pull/52563

GitOrigin-RevId: e7577ad346046a30712fbec61243af2779f24c72
Change-Id: I066f363f4197171cdb45f8679279239f780a59ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307880
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-08 13:16:18 +00:00
Johnni Winther ccb21bd54b [kernel] Add RedirectingFactoryTarget to FunctionNode
This replaces the RedirectingFactoryBody with a dedicated
RedirectingFactoryTarget object on FunctionNode.

TEST=existing

Change-Id: I3cc8b9f8abf938c6d60fdbc91b1f4210686fc359
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307082
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Jens Johansen <jensj@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-06-08 08:04:15 +00:00
Derek Xu 6ca0693c28 Revert "[VM/Service] Add code for working with Perfetto protos to package:vm_service"
This reverts commit 6c3c34560e.

Reason for revert: We will put the proto bindings in a separate package to prevent introducing new transitive dependencies into package:flutter.

Original change's description:
> [VM/Service] Add code for working with Perfetto protos to package:vm_service
>
> TEST=get_perfetto_vm_timeline_rpc_test and
> get_perfetto_cpu_samples_rpc_test
>
> Change-Id: I23a30629f1d7a8cd7e2c9daad2d02fae4decb338
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302421
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Derek Xu <derekx@google.com>

Change-Id: I3bd9ce8a09e131271f76fe46ca92288f888d6147
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307968
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-06-07 21:28:00 +00:00
Mihail Slobodyanuk a4b25027fe Fix Socket remoteAddress obtaining on Win32 #51778
Closes https://github.com/dart-lang/sdk/pull/51981

GitOrigin-RevId: de22efdd25a716b6c7eac086e2cb12e8793554f5
Change-Id: If1d8247f7e0188c47c19e19f33732a56493d21d8
Bug: https://github.com/dart-lang/sdk/issues/51778
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294220
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Brian Quinlan <bquinlan@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
2023-06-07 19:32:49 +00:00
Ryan Macnak 884be01ec3 [vm, gc] Add option to madvise(DONTNEED) when sweeping.
- More expensive sweeping that will also slow down the mutator from more TLB invalidation
 - Might cause OOM sooner from PTE fragmentation
 - Won't decrease the Dart heap capacity stat
 - Unclear how often holes are at least page sized

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/52571
Change-Id: I54011e451bf0ad21859c11023d1c4123cc0fa435
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306902
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-06-07 19:01:51 +00:00
Martin Kustermann 219bf34064 [vm/ffi] Simplify some aspects of ffi callback metadata implementation
Make the free and allocated lists simply linked lists of `Metadata*`
(instead of `Metadata*` pointing to Trampoline, which - via some
logic - can be translated into next `Metadata*`).

Make the layout of the virtual address space mapping and
offsets `constexpr` functions instead of computing them at
runtime & caching in fields.

Use `uword` to represent `Trampoline` entrypoint (as we generally
use `uword` for `Code.EntryPoint()` / ...)

TEST=ci

Change-Id: If4ffa11712acc46c9295b609caff7576d2354fe4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305983
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-06-07 10:51:31 +00:00
Vyacheslav Egorov 74285a6e31 [io] Take pending writes into account in _SocketStreamConsumer
On Windows `_NativeSocket.nativeWrite` returning to caller does
not mean that the data was flushed into OS buffer. Overlapped
operation might still be in progress - and it will be cancelled
with data loss if we close the handle.

This means _SocketStreamConsumer should take such pending writes
into account and not issue `done` event until pending write
completes.

This change prevents data loss when communicating with
subprocesses on Windows. Previously even doing
`await process.stdin.flush()` would not guarantee data
delivery.

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

TEST=tests/standalone/io/regress_50904_test.dart

Cq-Include-Trybots: luci.dart.try:vm-win-release-x64-try,vm-win-debug-x64-try,pkg-win-release-try
Change-Id: I13ab2cc3ce45f1ff8cb3183884d26bbb2b72f7ac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307043
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-06-07 09:49:35 +00:00
Alexander Markov 463c7cb5a2 [vm] Support unchecked AsExpressions in the VM
This is a follow-up to https://dart-review.googlesource.com/c/sdk/+/307044.

TEST=ci

Change-Id: Ib08ca334b463a4926347dcdeb965f81d1979b703
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307660
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-06-06 16:26:25 +00:00
Ryan Macnak 3a598b4c03 [vm, gc] Honor kAllocatablePageSize during promotion and snapshot reading.
Avoids objects between kAllocatablePageSize and kNewAllocatableSize getting promoted to regular pages and contributing to fragmentation. The snapshot allocator is also updated to be able to assert the invariant that objects larger than kAllocatePageSize never appear on non-large old pages.

TEST=ci
Bug: b/264420546 (speculative)
Change-Id: Ib2d61f0797bad4c8c6229cf4842169fae5c7053e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306906
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-06-06 16:20:47 +00:00
Daco Harkes b5ee6fa888 [vm/ffi] Support native assets in dart build with relative path
`ResolveUri` in the VM works on Uris, not on paths.
Add `file://` to complete the uri with a schema, and remove `file://`
again before calling dlopen.

TEST=pkg/dartdev/test/native_assets/build_test.dart
Added a relative path run.

Closes: https://github.com/dart-lang/sdk/issues/52614
Change-Id: Ib253f530b9edecb69ba1ec2269874fdfc2693b37
Cq-Include-Trybots: luci.dart.try:pkg-linux-debug-try,pkg-linux-release-try,pkg-mac-release-arm64-try,pkg-mac-release-try,pkg-win-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/307460
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Hossein Yousefi <yousefi@google.com>
2023-06-06 09:41:02 +00:00
Liam Appelbe 07f587504b Reland "[vm] Migrate FFI callbacks to the new metadata system."
This reverts https://dart-review.googlesource.com/c/sdk/+/306674

Patchset 1 is a pure rollback of the rollback.
Patchset 2 is https://dart-review.googlesource.com/c/sdk/+/306316
Patchset 4+ is the forward fix for the Fuchsia issues.

The Fuchsia bug that we're fixing (or working around), is that
VirtualMemory::DuplicateRX doesn't work on Fuchsia. A proper fix will
require special casing it, like on MacOS. In the mean time we can avoid
using this function by only allowing one page of trampolines on Fuchsia.
Unfortunately, when I removed the BSS stuff from the original CL, it
was necessary to duplicate even the first page, so I've had to add that
stuff back just for Fuchsia.

Change-Id: Id42de78ee5de126bcc83bfa4148f6efb4045f976
Bug: https://github.com/dart-lang/sdk/issues/52579
Bug: https://buganizer.corp.google.com/issues/284959841
Fixes: https://github.com/dart-lang/sdk/issues/52581
TEST=CI, especially vm-fuchsia-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306676
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-06-06 02:07:58 +00:00
Alexander Markov 5ff0821b27 [kernel,vm] First-class kernel serialization of FutureOrType and NullType
TEST=ci
Fixes https://github.com/dart-lang/sdk/issues/52565

Change-Id: I9906f2d10c7ed51d11a0c402b51c8189ac3b6298
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306901
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-06-05 21:24:35 +00:00
Ryan Macnak 41c17e0b01 [vm, gc] Remembered cards tweaks.
- Represent cards with one bit instead of one byte.
- Shrink the region tracked by one card.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/52513 (benchmark)
Change-Id: Ieba8d77bc9ff0dd3b7747329d6e446a5b41969e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/245908
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-02 19:50:08 +00:00
Alexander Aprelev e0ced74e15 [gardening] Marking evaluate_activation_test as slow.
The tests are flaky - going from (expected)RuntimeError to (unexpected)timeout.
BUG=https://github.com/dart-lang/sdk/issues/45124
TEST=ci

Change-Id: Ifd8aef25c47b983425afdf80e3ad64dcefc00415
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306667
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Auto-Submit: Alexander Aprelev <aam@google.com>
2023-06-02 17:52:13 +00:00
Derek Xu 475240d234 Reland "[VM/Timeline] Make timestamp1_or_id variables more understandable"
This is a reland of commit 46e70a7c07

It turns out that flow events do need to be associated with IDs in
Chrome's trace format, so the diff between patchset 1 and 6 contains the
changes required to document that.

TEST=Checked that duration events still looked correct in traces written
by the Perfetto file recorder. Checked that events still looked correct
in traces recorded to the MacOS recorder. Checked that flow events still
looked correct in Observatory. Ran the
vm/cc/DartAPI_TimelineEvents_Serialization test in debug mode, and with
ASAN and TSAN.

CoreLibraryReviewExempt: Does not change any APIs, just stops passing a
value that will never be read. Specifically, we do not need to pass a
flow ID on the end side of track events.
Change-Id: I6b8bb3236339dbe54378b2e9dea06faf22b964a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306664
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-06-01 19:50:38 +00:00
Alexander Markov 63d856d487 [test] Avoid quadratic complexity in vm/dart/unobfuscated_static_symbols_test
This change makes this test much faster and should fix the timeouts on
the slow simarm_x64 configuration.

Change-Id: I6ba489d2dee3963bb070c1e86abff88420fa3ce7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306900
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-06-01 17:36:29 +00:00
Ryan Macnak 52791b4e0d [build] Decide in one place between using app-jit and kernel for the SDK snapshots.
Change-Id: Id642c635979b96f09780aba49ffcb1b9f215878d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306666
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-06-01 15:20:58 +00:00
Liam Appelbe 8ea3e9fd0d Revert "[vm] Migrate FFI callbacks to the new metadata system."
Roll back https://dart-review.googlesource.com/c/sdk/+/302903
and https://dart-review.googlesource.com/c/sdk/+/306124

Since the bug is in VirtualMemory::DuplicateRX, also roll back
https://dart-review.googlesource.com/c/sdk/+/303960
https://dart-review.googlesource.com/c/sdk/+/304400
https://dart-review.googlesource.com/c/sdk/+/304620

Bug: https://buganizer.corp.google.com/issues/284959841
Change-Id: Id212de209fb57b2c3395bb61064dc8f569832884
TEST=CI
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306674
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-06-01 01:00:58 +00:00
Derek Xu e7fd092044 Revert "Reland "[VM/Timeline] Make timestamp1_or_id variables more understandable""
This reverts commit 46e70a7c07.

Reason for revert: New asserts failing in Flutter Engine tests

Original change's description:
> Reland "[VM/Timeline] Make timestamp1_or_id variables more understandable"
>
> Relanding without changes because the cbuild failure was unrelated.
>
> TEST=Checked that duration events still looked correct in traces written
> by the Perfetto file recorder. Checked that events still looked correct
> in traces recorded to the MacOS recorder.
>
> This is a reland of commit 354e1d22cb
>
> Original change's description:
> > [VM/Timeline] Make timestamp1_or_id variables more understandable
> >
> > This CL improves documentation, and renames fields/methods to make it
> > more understandable that timestamp1 and id are stored in the same field
> > of dart::TimelineEvent (because the event types that need to store
> > timestamp1 are disjoint from the ones that need to store id).
> >
> > TEST=Checked that duration events still looked correct in traces written
> > by the Perfetto file recorder. Checked that events still looked correct
> > in traces recorded to the MacOS recorder.
> >
> > Change-Id: I25ff1f4c6cc432f035ac2be99fa7f162290ea77f
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305880
> > Reviewed-by: Ben Konyi <bkonyi@google.com>
> > Commit-Queue: Derek Xu <derekx@google.com>
>
> Change-Id: I28c0c3af9869900cc8bb2b3b416904a231d143e0
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306301
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Derek Xu <derekx@google.com>

Change-Id: Ia1fe524268c06fd68c689fe048d8cc38a6ed8a23
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306661
Reviewed-by: Ben Konyi <bkonyi@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-05-31 16:51:49 +00:00
Alexander Markov 3484bfe964 [vm/compiler] Avoid specialization of calls to setters of late final fields
Setters of late final fields should check that field is not initialized
yet, so they should not be replaced with a StoreField in call specializer.

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

Change-Id: I2d7a4a8e112fe7b78e6d28efe4174159e3cabe04
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306303
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-05-31 14:04:39 +00:00
Martin Kustermann 0d3ef451c7 [gardening] Remove assert(_remoteVm == null) as this is a non-nullable late-final field
TEST=Fixes assertion hits.

Change-Id: If601bf17df0a9c0da5bafcc686091dd3aed5f4d7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306562
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-05-31 10:46:10 +00:00
Martin Kustermann 471ad8c088 [vm] Ensure error out-parameter is cleared
This fixes a regression introduced in [0] that removed clearing of the
error out-parameter.

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

TEST=Fixes `free(<invalid-pointer>)` test failures.

Change-Id: Id2db1458128c3b5cb3b37e4327ba71ff81100f15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306604
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-05-31 09:50:45 +00:00
Martin Kustermann 5136814ec2 [vm] Attempt to make vm/dart/isolates/reload_many_isolates_live_and_die_test more robust
This test is launcing N=20 parallel tracks. Each track is effectively
a child isolate that will make a tail call to another child isolate.

=> Limit number of parallel isolates to number of cores.

We are seeing sometimes failures where prints get interleaved into
stdout.

=> Do not assume the strings in stdout are from start of line.

We are sometimes seeing timeouts even though all isolates have finished
in the subprocess

=> wait for exit code & RPC connection closing in parallel
=> print their result.

Issue https://github.com/dart-lang/sdk/issues/51347
TEST=vm/dart{,_2}/isolates/reload_many_isolates_live_and_die_test

Change-Id: Ie8ecf863c2aab04264edf05a5628fa23b26a4813
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306602
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-05-31 09:16:25 +00:00
Tess Strickland ecf1968122 [vm] Do not obfuscate code or object symbols in the static symbol table.
Also changes pkg/native_stack_traces to return a parsed MachO file
if the MachO file doesn't contain DWARF information, so we can examine
its static symbol information for the new test.

Issue: https://github.com/flutter/flutter/issues/124715

TEST=vm/dart/unobfuscated_static_symbols

Change-Id: I07d3ced56eeba852ebe4178dfd2b66ebb899eb76
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-mac-product-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305720
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-05-31 08:06:08 +00:00
Alexander Markov abd95e21ca [vm] Fix handling of nullability in FutureOr type checks
TEST=runtime/tests/vm/dart/regress_52536_test.dart
Fixes https://github.com/dart-lang/sdk/issues/52536

Change-Id: I1d2fc86071747bc401f419d9e0897420a873a647
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306310
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-05-30 23:41:19 +00:00
Ryan Macnak 97b2c09d99 [standalone] Increase the default idle timeout to 61s.
2b8ca6f2f5 increased the idle policy's willingness to perform longer GC. This CL increases the amount of evidence the policy requires to consider itself idle to decrease the probability of a mispredict / wakeup during an idle GC. 61s is chosen to decrease the likelihood of resonance with periodic tasks.

Eventually compaction should not have an O(heap) blocking time, allowing compaction to be coupled to the growth policy instead of the idle policy.

TEST=manually inspect timeline
Bug: https://github.com/dart-lang/sdk/issues/52513
Change-Id: I5f2b02834413089545612a7fce26da928597d611
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306308
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-05-30 21:58:31 +00:00
asiva 54dea888a5 [dart cli] Remove need for dartdev.dill file from sdk
The bulid rules generate an appjit snapshot or a kernel file under
dartdev.dart.snapshot depending on whether the target_cpu is the same as
the host_cpu.
Generation of the additional dartdev.dill file is not needed because of
this, the logic to start the dartdev isolate tries to load
dartdev.dart.snapshot as an appjit snapshot first and if that fails it
tries it as a kernel file.

TEST=ci

Change-Id: I1c985bdf543d3eb5e17d968378053cc558fd8a0f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306134
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2023-05-30 21:42:39 +00:00
Derek Xu 46e70a7c07 Reland "[VM/Timeline] Make timestamp1_or_id variables more understandable"
Relanding without changes because the cbuild failure was unrelated.

TEST=Checked that duration events still looked correct in traces written
by the Perfetto file recorder. Checked that events still looked correct
in traces recorded to the MacOS recorder.

This is a reland of commit 354e1d22cb

Original change's description:
> [VM/Timeline] Make timestamp1_or_id variables more understandable
>
> This CL improves documentation, and renames fields/methods to make it
> more understandable that timestamp1 and id are stored in the same field
> of dart::TimelineEvent (because the event types that need to store
> timestamp1 are disjoint from the ones that need to store id).
>
> TEST=Checked that duration events still looked correct in traces written
> by the Perfetto file recorder. Checked that events still looked correct
> in traces recorded to the MacOS recorder.
>
> Change-Id: I25ff1f4c6cc432f035ac2be99fa7f162290ea77f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305880
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Derek Xu <derekx@google.com>

Change-Id: I28c0c3af9869900cc8bb2b3b416904a231d143e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306301
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-05-30 15:40:33 +00:00
Martin Kustermann 20248e1c2e [vm] Make vm/dart/isolates/reload_many_isolates_live_and_die_test more robust
This test is launcing a subprocess with N parallel tracks.
Each track is effectively a child isolate that will make a
tail call to another child isolate. This process will continue
until a reload is requested.

=> So it tests performing hot-reload of an application that has
a lot of isolate creation, initialization, destructions in it.

Right now it uses N=20 for normal architectures (and N=2 for
simulators).

It turns out that part of the slowness of this test is due to the
subprocess's "vm-service" sending massive amounts of data via the
websocket to the parent process that performs reloading:

Each isolate will produce 4 events:
  * IsolateStart
  * IsolateRunnable
  * ServiceExtensionAdded
  * IsolateExit
and send those to the `vm-service` isolate. The service isolate will
then send those further via the WebSocket API to the parent process.

=> For 400k isolates this may send 3 GB of data via websocket.
=> The individual events most likely result in individual syscalls.
=> Networking stack on windows/mac may not be soo good, which
would explain why it's more likely to time out there vs linux

We ensure the helper reload utilites unsubscribe to the "isolate"
stream once there's no longer a need for it.
=> This will avoid the 3 GB of network traffic.
=> It will avoid a subset (but not all) of the isolate -> vm-service events

Issue https://github.com/dart-lang/sdk/issues/51347
TEST=vm/dart{,_2}/isolates/reload_many_isolates_live_and_die_test

Change-Id: I971b983a08ea8febd38e8b40a53ed6b114c4daca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306421
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-05-30 13:54:57 +00:00
Derek Xu 2e29ed3874 Revert "[VM/Timeline] Make timestamp1_or_id variables more understandable"
This reverts commit 354e1d22cb.

Reason for revert: broke cbuild

Original change's description:
> [VM/Timeline] Make timestamp1_or_id variables more understandable
>
> This CL improves documentation, and renames fields/methods to make it
> more understandable that timestamp1 and id are stored in the same field
> of dart::TimelineEvent (because the event types that need to store
> timestamp1 are disjoint from the ones that need to store id).
>
> TEST=Checked that duration events still looked correct in traces written
> by the Perfetto file recorder. Checked that events still looked correct
> in traces recorded to the MacOS recorder.
>
> Change-Id: I25ff1f4c6cc432f035ac2be99fa7f162290ea77f
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305880
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Derek Xu <derekx@google.com>

Change-Id: I37c74620105299c0b5e7725fd994609af177a9f8
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306280
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-05-29 19:10:27 +00:00
Derek Xu 354e1d22cb [VM/Timeline] Make timestamp1_or_id variables more understandable
This CL improves documentation, and renames fields/methods to make it
more understandable that timestamp1 and id are stored in the same field
of dart::TimelineEvent (because the event types that need to store
timestamp1 are disjoint from the ones that need to store id).

TEST=Checked that duration events still looked correct in traces written
by the Perfetto file recorder. Checked that events still looked correct
in traces recorded to the MacOS recorder.

Change-Id: I25ff1f4c6cc432f035ac2be99fa7f162290ea77f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305880
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-05-29 18:46:54 +00:00
Ryan Macnak 89330b306b [vm] Fix MSVC build.
TEST=ci
Change-Id: I20c24948d426a396817807c2d9c570e67d4a106c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306124
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2023-05-26 20:51:28 +00:00
Alexander Markov 466bbd2545 Reland "Reland "[vm] Unify hash codes in type objects""
This is a reland of commit f96d179ae4

Original change's description:
> Reland "[vm] Unify hash codes in type objects"
>
> This is a reland of commit e82a2230fd
>
> Original change's description:
> > [vm] Unify hash codes in type objects
> >
> > TEST=ci
> >
> > Change-Id: I53d2268c3aab6fc4583c3201051b68f8fc05d56d
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305361
> > Commit-Queue: Alexander Markov <alexmarkov@google.com>
> > Reviewed-by: Ryan Macnak <rmacnak@google.com>
>
> TEST=ci
> Change-Id: I333ed4297ad4af97000c98dfe4547b4cab6cb313
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305780
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Alexander Markov <alexmarkov@google.com>

TEST=ci
Change-Id: Ib38656b32ead96b77d7f80665b93a623431f5594
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306001
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-05-26 20:13:17 +00:00
Daco Harkes 157f6bb8a3 [test/ffi] Stop printing uninitialized union members
TEST=function_structs_by_value_generated_ret_*
TEST=function_callbacks_structs_by_value_generated_test

Closes: https://github.com/dart-lang/sdk/issues/52527
Change-Id: Ie910ca319e0b2bc35ee2bcededd4094b209e3282
Cq-Include-Trybots: luci.dart.try:vm-aot-msan-linux-release-x64-try,vm-msan-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305982
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-05-26 16:22:25 +00:00
Alexander Markov c57f889d43 Revert "Reland "[vm] Unify hash codes in type objects""
This reverts commit f96d179ae4.

Reason for revert: failures on Flutter Windows bots (https://github.com/flutter/flutter/issues/127666)

Original change's description:
> Reland "[vm] Unify hash codes in type objects"
>
> This is a reland of commit e82a2230fd
>
> Original change's description:
> > [vm] Unify hash codes in type objects
> >
> > TEST=ci
> >
> > Change-Id: I53d2268c3aab6fc4583c3201051b68f8fc05d56d
> > Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305361
> > Commit-Queue: Alexander Markov <alexmarkov@google.com>
> > Reviewed-by: Ryan Macnak <rmacnak@google.com>
>
> TEST=ci
> Change-Id: I333ed4297ad4af97000c98dfe4547b4cab6cb313
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305780
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Alexander Markov <alexmarkov@google.com>

Change-Id: I1a933e39b81e99e732db56e616b24d6ec604f01b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306000
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-05-26 14:36:14 +00:00
Daco Harkes 706f6b2ca4 [vm/ffi] Cleanup old RTEs
The cleanup isn't symmetrical in all files:
- 1x `Ffi_loadStruct` wasn't referenced from the Dart patch file.
- 4x `Unaligned` loads and stores were never runtime entries.
This sums up to a 4 - 1 = 3 diff between the diffs of the .h files.

TEST=ffi test suite

Change-Id: I0a4ab023b7eb116f87cf9bc10a970e6a531c5319
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64c-try,vm-aot-linux-debug-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-reload-rollback-linux-debug-x64-try,vm-reload-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305942
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
2023-05-26 13:43:28 +00:00
Derek Xu 193c4ccbb9 [VM/Timeline] Store an array of flow IDs in each dart::TimelineEvent
instead of just one ID

Sometimes the Flutter Engine is associating events with multiple flows,
this change is needed to allow events to be associated with multiple
flows in a Perfetto-format trace.

TEST=Checked the flow events reported through dart:developer still
looked correct when retrieved in Perfetto traces.

Change-Id: I2901ffde5e8b984abb1e924e014722bb0568f6d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305801
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-05-26 13:08:27 +00:00
Martin Kustermann 95492b9f48 [vm] Avoid having two [Code] objects for same force-optimized [Function] around
Force-optimized functions cannot deoptimize & reoptimize. Compiling them
always produces the same code.

If two mutators trigger lazy compilation of the same force-optimized
function we can let the first one win and let all others skip the
installation of code (detected in the installation phase where all
other mutators are stopped at safepoint).

This will avoid having multiple [Code] objects for the same
force-optimized function in normal circumstances.

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

TEST=ci

Change-Id: I922728795943f006406feeca2e7a9f899859e800
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305920
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-05-26 08:50:45 +00:00
Alexander Markov f96d179ae4 Reland "[vm] Unify hash codes in type objects"
This is a reland of commit e82a2230fd

Original change's description:
> [vm] Unify hash codes in type objects
>
> TEST=ci
>
> Change-Id: I53d2268c3aab6fc4583c3201051b68f8fc05d56d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305361
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

TEST=ci
Change-Id: I333ed4297ad4af97000c98dfe4547b4cab6cb313
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305780
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-05-25 21:55:24 +00:00
Chingjun Lau 9304a8dfd1 Add a new getIsolatePauseEvent method in the VM service.
In Flutter hot reload, the flutter_tools are calling the `getIsolate`
to read the pause state of the isolate, which returns a full list of
libraries loaded in the isolate. The size of the return object grow
linearly to the number of Dart files, which can take ~500ms to transfer
for a large app.

This change adds a new method to only read what is needed.

TEST=pkg/vm_service/test/get_isolate_pause_event_rpc_test.dart

Change-Id: If19910cb3ff5d5057932551ac738afd3c3136fac
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305362
Reviewed-by: Ben Konyi <bkonyi@google.com>
Auto-Submit: Chingjun Lau <chingjun@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-05-25 21:55:21 +00:00
Vyacheslav Egorov fc6eb985cd Train kernel-service on M1 Macs
R=kustermann@google.com

Change-Id: I542a7dfb3987d7e66ffe4fb8b5cd75a3f7674bd1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305741
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-05-25 14:38:54 +00:00
Vyacheslav Egorov f86f41226d [vm/timeline] Include callback data into Dart_TimelineRecorderEvent.
This simplifies embedders which otherwise need to maintain
special mappings to find their isolate specific data structures.

TEST=vm/cc/DartAPI_SetTimelineRecorderCallback

Change-Id: If819437cad2e1bf3fe5ba50fe67d01e8bd992064
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/304962
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-05-25 10:19:48 +00:00
Liam Appelbe f0f732b1a6 [vm] Migrate FFI callbacks to the new metadata system.
This is the same metadata system that will support async callbacks. The
main thing this does is take the trampolines that used to be JIT only,
and use them in AOT too. This is partly a safety thing (there's some
extra checks that used to be skipped on AOT), but mostly just so that
the metadata system is unified between the sync and async callbacks.

More details about the design:
https://docs.google.com/document/d/1QDjyY_6wOTOgURwpeYMKU9qEz0gKxx2MUrdruC6Kp6c/edit?usp=sharing

I split this off the async CL. Some of the comments refer to async
stuff that doesn't exist yet, but it's coming immediately after this so
I didn't update them.

Change-Id: Icd5e86934ee9ae34c2c0e2ed2bbd1b928a7184ac
TEST=ffi_callback_metadata_test.cc and CI
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/302903
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2023-05-24 22:22:04 +00:00
Alexander Markov ee36a2dcef Revert "[vm] Unify hash codes in type objects"
This reverts commit e82a2230fd.

Reason for revert: g3 failures

Original change's description:
> [vm] Unify hash codes in type objects
>
> TEST=ci
>
> Change-Id: I53d2268c3aab6fc4583c3201051b68f8fc05d56d
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305361
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

Change-Id: If22c8ed05cd23eb5c62c7a431311827a480263a6
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305540
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2023-05-24 21:43:06 +00:00
Alexander Markov e82a2230fd [vm] Unify hash codes in type objects
TEST=ci

Change-Id: I53d2268c3aab6fc4583c3201051b68f8fc05d56d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305361
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-05-24 20:40:49 +00:00
Alexander Markov c554ae04fc [vm] Fix Type.hashCode asm intrinsic with compressed pointers
When loading cached hash code, asm intrinsic used LoadCompressed
which results in garbage in the high 32-bits of the register.
So the full register was not zero and intrinsic could return zero value
in the low 32-bits.

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

Change-Id: Ie800dcea02db5b54bd8bf7e9df0f437f09e92932
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305360
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-05-24 20:03:38 +00:00