Commit graph

84 commits

Author SHA1 Message Date
Alexander Markov 4075e8b3f9 [vm] New async*/yield/yield* implementation based on suspend/resume stubs
TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/48378
Change-Id: I0c2ca9269b2c8f008a79c139a0ce10231996732d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242923
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2022-05-02 20:53:01 +00:00
Alexander Markov bf4bb95308 [vm] New async/await implementation in the VM, part 2 - vm
The new implementation moves away from desugaring of async
functions on kernel AST, state machine generated in the flow graph and
capturing all local variables in the context.

Instead, async/await is implemented using a few stubs
(InitSuspendableFunction, Suspend, Resume, Return and
AsyncExceptionHandler). The stubs are implemented in a
platform-independent way using (macro-)assembler helpers.
When suspending a function, its frame is copied into a SuspendState
object, and when resuming a function it is copied back onto the stack.
No extra code is generated for accessing local variables.
Callback closures are created lazily on the first await.

Design doc: go/compact-async-await.

Part 1 (kernel): https://dart-review.googlesource.com/c/sdk/+/241842

TEST=ci

Issue: https://github.com/dart-lang/sdk/issues/48378
Change-Id: Ibad757035b7cc438ebdff80b460728b1d3eff1f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/242000
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2022-04-29 01:03:50 +00:00
Ryan Macnak a8d9119f00 [vm] Add missing field metadata for finalizers.
TEST=misc heap tools in Observatory
Change-Id: Iefaa6f749e3c950f7b5ee3d542e2db103fd47222
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241841
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-04-21 17:59:28 +00:00
Daco Harkes 828dcd00e8 [vm] Implement WeakReference in the VM
This CL implements `WeakReference` in the VM.

* This reduces the size of weak references from 2 objects using 8 words
  to 1 object using 4 words.
* This makes loads of weak reference targets a single load instead of
  two.
* This avoids the fix-point in the GC and message object copying for
  weak references. (N.b. Weak references need to be processed _after_
  the fix-point for weak properties.)

The semantics of weak references in messages is that their target gets
set to `null` if the target is not included in the message by a strong
reference.

The tests take particular care to exercise the case where a weak
reference's target is only kept alive because a weak property key is
alive and it refers to the target in its value. This exercises the fact
that weak references need to be processed last.

Does not add support for weak references in the app snapshot. It would
be dead code until we start using weak references in for example the
CFE.

This CL does not try to unify weak references and weak properties in
the GC or messaging (as proposed in go/dart-vm-weakreference), because
their semantics differ enough.

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

TEST=runtime/tests/vm/dart/finalizer/weak_reference_run_gc_test.dart
TEST=runtime/tests/vm/dart/isolates/fast_object_copy_test.dart
TEST=runtime/vm/object_test.cc
TEST=tests/lib/isolate/weak_reference_message_1_test.dart
TEST=tests/lib/isolate/weak_reference_message_2_test.dart

Change-Id: I3810e919a5866f3ae8a95bd9aa23a880a0b0921c
Cq-Include-Trybots: luci.dart.try:app-kernel-linux-debug-x64-try,dart-sdk-mac-arm64-try,vm-canary-linux-debug-try,vm-fuchsia-release-x64-try,vm-kernel-gcc-linux-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-debug-x64c-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-debug-simriscv64-try,vm-kernel-mac-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-nnbd-linux-release-ia32-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-mac-debug-arm64-try,vm-kernel-nnbd-mac-debug-x64-try,vm-kernel-nnbd-win-release-ia32-try,vm-kernel-nnbd-win-release-x64-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-precomp-win-debug-x64c-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-win-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232087
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-02-10 21:59:41 +00:00
Ryan Macnak a7faaaa148 [vm] Properly exclude the field descriptors from product builds.
TEST=ci
Change-Id: Ia9d345f7f6488b24b780979fd624d708c7038811
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/231182
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-02-02 00:32:25 +00:00
Vyacheslav Egorov 13d27d669d [vm] Improve Code cluster layout for startup
This change bakes binary search table which maps PC ranges
to corresponding stack maps and Code objects (if still present
in the snapshot) into RO data section of the snapshot - instead
of constructing it at load time.

This allows to considerably reduce amount of work done when
loading Code cluster for programs which have majority of their
Code objects discarded (i.e. in DWARF stack traces mode): as
we no longer write / read any information for discarded Code
objects.

This CL also changes program visitor to deduplicate Code objects
if their instructions are deduplicated in AOT mode. Only a single
Code object can be choose as a representative for the given
PC range so it does not make sense to write multiple Code objects
into the snapshot which refer to the same Instructions.

The overall improvement is hard to quantify but ReadProgramSnapshot
shows the following improvement when starting a large
Flutter application on a slow Android device:

  before  223.55±59.94 (192.02 .. 391.74) ms
  after   178.06±47.03 (151.31 .. 291.34) ms

This CL packs CompressedStackMaps next to the binary search table
itself allowing us to address them via offsets instead of
pointers.

Snapshot sizes are actually affected positively by this change. On
the same large Flutter application I see

  DWARF stack traces on:  -1.34% total SO size
  DWARF stack traces off: -1.63% total SO size

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

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-debug-simarm64c-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-precomp-linux-release-x64-try
Change-Id: Ic997045a33daa81ec68df462a0792915885df66b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/220766
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2021-12-16 10:39:49 +00:00
Vyacheslav Egorov 71c9c2cd83 [vm] Remove support for non-bare AOT snapshots
Every AOT user out there has been using bare instructions mode
and continuing to maintaining non-bare instructions mode simply
adds costs (both in terms of time spent making changes to work
in a mode that is not used and CI resources spent on testing it).

This change removes FLAG_use_bare_instructions and changes the code
to assume that FLAG_precompiled_mode implies bare instructions.

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,app-kernel-linux-release-x64-try,app-kernel-linux-debug-x64-try
Change-Id: I5032b13bfcb613f79865f2cfa139cca8d1b42556
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/220964
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-11-24 13:03:52 +00:00
Ryan Macnak d9048340ba [vm, service] Include each isolate a separate synthetic object in heap snapshots.
Fix labels for sentinel, transition_sentinel, ImmutableArray, LinkedHashMap and LinkedHashSet.

Display unlimited children when look at successors, as the worst case is the size of the field table. For predecessors and dominators, the worst case is the whole heap.

TEST=ci
Change-Id: I6fcfdfb0833d58c9ac4f586b823244d817aeba27
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209841
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2021-08-17 16:49:32 +00:00
Ryan Macnak 2642c7c9ce [vm] Fix gcc build.
TEST=local build
Change-Id: I9503dfbb1b9ba6ef2b5fb8423c13d5066e5af98b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206140
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2021-07-13 01:55:45 +00:00
Daco Harkes 172e1bee70 [vm] Introduce LinkedHashBase
In separate CL so that the LinkedHashMap CL is a bit smaller.

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

TEST=tests/**_test.dart

Change-Id: I4ecff40a40fffbad4d9c37ca426066128c0ed7f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206223
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2021-07-08 20:28:44 +00:00
Tess Strickland cf63eaed4d [vm] Remove overlap between Function and FunctionType.
Previously there were several pieces of information shared between
both FunctionType and Function, mostly in the packed fields, but
named argument names were also kept in both places.

Now the FunctionType is the primary source for this information, with
the Function only keeping the names of positional arguments, which are
discarded in AOT snapshots.

This does mean extra work to access this information via the function
object, but for the most part, this information is only accessed in the
compiler or during dynamic lookups or checks in the runtime.

After adding the count of type parameters to the packed information
in FunctionType, the packed information has been split into two pieces:
one for parameter counts, another for type parameter counts. This
split does not increase the size of UntaggedFunctionType, as there
were 2 bytes available in the existing padding.

Changes on flutter gallery in release mode:

* ARM7 code size: total -0.91%, readonly -0.22%, isolate -4.32%
* ARM7 heap size: total -2.00%
* ARM8 code size: total -0.93%, readonly -0.22%, isolate -4.32%
* ARM8 heap size: total -2.12%

Changes on flutter gallery in release-sizeopt mode:

* ARM7 code size: total -0.24%, readonly -0.08%, isolate -1.49%
* ARM7 heap size: total -0.88%
* ARM8 code size: total -0.26%, readonly -0.11%, isolate -1.49%
* ARM8 heap size: total -1.01%

TEST=Refactoring, so existing tests.

Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try
Change-Id: Ic4d59a7b4acca039a5647f9163e716f6019163f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203241
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2021-07-02 14:26:04 +00:00
Ryan Macnak 866157762c [vm] Add missing field metadata.
TEST=examine a heap snapshot or snapshot profile
Change-Id: I86d1981a909dd7a1b078a1445ff7c1d661422965
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/205242
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2021-06-29 15:59:28 +00:00
Ryan Macnak e5bc0f0b86 [vm] Make various arrays const.
TEST=build
Change-Id: I8d3445b87caa979472c9a37df62507f152a4aefb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/203202
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-06-14 20:45:18 +00:00
Ryan Macnak 815fc81d24 [vm] Remove Script::compile_time_constants_.
Dead since 5cce1e4acd.

TEST=ci
Change-Id: I50e8bc9eea9625120c5038b29deb6b2ee33dd6c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202306
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2021-06-04 17:34:31 +00:00
Ryan Macnak 6589ca13bc Revert "[vm] Remove Script::compile_time_constants_."
This reverts commit a10e038f09.

Reason for revert: Android ARM32 disagrees on how UntaggedScript is packed

Original change's description:
> [vm] Remove Script::compile_time_constants_.
>
> Dead since 5cce1e4acd.
>
> TEST=ci
> Change-Id: If55de08b753e5948785187e455ac793356d1e794
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202066
> Commit-Queue: Ryan Macnak <rmacnak@google.com>
> Reviewed-by: Ben Konyi <bkonyi@google.com>

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

Change-Id: I41872aa99af056d4a2c730403628a86b61185e46
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202300
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-06-03 17:05:38 +00:00
Ryan Macnak a10e038f09 [vm] Remove Script::compile_time_constants_.
Dead since 5cce1e4acd.

TEST=ci
Change-Id: If55de08b753e5948785187e455ac793356d1e794
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/202066
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2021-06-02 22:50:14 +00:00
Regis Crelier 1f55b7ca10 Reland "[VM/runtime] Refactor the representation of type parameters in the VM."
This is a reland of 8a21ab195a

Original change's description:
> [VM/runtime] Refactor the representation of type parameters in the VM.
>
> This introduces a new VM internal class 'TypeParameters' representing the declaration of a list of type parameters, either in a class or function.
> The reference to (or use of) a type parameter is still represented by the existing 'TypeParameter' class.
>
> Fixes https://github.com/dart-lang/sdk/issues/43901
> Fixes https://github.com/dart-lang/sdk/issues/45763
>
> TEST=existing ones and a regression test
>
> Change-Id: I1fde808bf753cc1cb829f2c4383c1836651cee80
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189942
> Commit-Queue: Régis Crelier <regis@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>

This fixes https://github.com/dart-lang/sdk/issues/45911

TEST=existing ones and a regression test

Change-Id: I709d38b1df3d73fe3c9796d5aca3cbbdcf77fd38
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198380
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-05-05 23:43:14 +00:00
Michal Terepeta c6bffaf19e Revert "[VM/runtime] Refactor the representation of type parameters in the VM."
This reverts commit 8a21ab195a.

Reason for revert: Test failure: http://b/187227619

Original change's description:
> [VM/runtime] Refactor the representation of type parameters in the VM.
>
> This introduces a new VM internal class 'TypeParameters' representing the declaration of a list of type parameters, either in a class or function.
> The reference to (or use of) a type parameter is still represented by the existing 'TypeParameter' class.
>
> Fixes https://github.com/dart-lang/sdk/issues/43901
> Fixes https://github.com/dart-lang/sdk/issues/45763
>
> TEST=existing ones and a regression test
>
> Change-Id: I1fde808bf753cc1cb829f2c4383c1836651cee80
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189942
> Commit-Queue: Régis Crelier <regis@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>

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

Change-Id: If12caa1a84cb6d1c1b8225589f3c994d25abb120
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198282
Reviewed-by: Michal Terepeta <michalt@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Michal Terepeta <michalt@google.com>
2021-05-05 10:03:57 +00:00
Regis Crelier 8a21ab195a [VM/runtime] Refactor the representation of type parameters in the VM.
This introduces a new VM internal class 'TypeParameters' representing the declaration of a list of type parameters, either in a class or function.
The reference to (or use of) a type parameter is still represented by the existing 'TypeParameter' class.

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

TEST=existing ones and a regression test

Change-Id: I1fde808bf753cc1cb829f2c4383c1836651cee80
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189942
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-05-04 15:47:01 +00:00
Alexander Markov 17c33d8d52 Reland "[vm] Reduce size of Class objects in AOT and PRODUCT modes"
This is a reland of 2852408881

Original change's description:
> [vm] Reduce size of Class objects in AOT and PRODUCT modes
>
> This change conditionally removes certain fields from Class objects
> in AOT and PRODUCT modes.
>
> Flutter gallery in release-sizeopt mode:
> Snapshot size -0.47% (arm64), -0.44% (arm)
> Heap size of snapshot objects -4.1% (arm64), -4.3% (arm)
>
> On a large Flutter application compiled in --dwarf-stack-traces mode:
> Heap size of Class objects -26%
> Heap size of all snapshot objects -3.6%
>
> TEST=ci
> Issue: https://github.com/dart-lang/sdk/issues/44020
> Change-Id: I795c625b71558cd2f336f92fc326c36fd339cd4b
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195700
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

TEST=ci
Change-Id: Ib473a959a2c610b7a0e6f4000b2101e5256c6119
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196103
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2021-04-20 21:11:58 +00:00
Alexander Markov 867a95c50e Revert "[vm] Reduce size of Class objects in AOT and PRODUCT modes"
This reverts commit 2852408881.

Reason for revert: failures on Flutter engine tests.
Issue: https://github.com/flutter/flutter/issues/80801

Original change's description:
> [vm] Reduce size of Class objects in AOT and PRODUCT modes
>
> This change conditionally removes certain fields from Class objects
> in AOT and PRODUCT modes.
>
> Flutter gallery in release-sizeopt mode:
> Snapshot size -0.47% (arm64), -0.44% (arm)
> Heap size of snapshot objects -4.1% (arm64), -4.3% (arm)
>
> On a large Flutter application compiled in --dwarf-stack-traces mode:
> Heap size of Class objects -26%
> Heap size of all snapshot objects -3.6%
>
> TEST=ci
> Issue: https://github.com/dart-lang/sdk/issues/44020
> Change-Id: I795c625b71558cd2f336f92fc326c36fd339cd4b
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195700
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

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

Change-Id: I0dbf1d5fc139f3654ce52f185b799c09bba66de7
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Issue: https://github.com/dart-lang/sdk/issues/44020
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196102
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-04-20 16:54:29 +00:00
Alexander Markov 2852408881 [vm] Reduce size of Class objects in AOT and PRODUCT modes
This change conditionally removes certain fields from Class objects
in AOT and PRODUCT modes.

Flutter gallery in release-sizeopt mode:
Snapshot size -0.47% (arm64), -0.44% (arm)
Heap size of snapshot objects -4.1% (arm64), -4.3% (arm)

On a large Flutter application compiled in --dwarf-stack-traces mode:
Heap size of Class objects -26%
Heap size of all snapshot objects -3.6%

TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/44020
Change-Id: I795c625b71558cd2f336f92fc326c36fd339cd4b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/195700
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2021-04-20 00:45:38 +00:00
Alexander Markov 5129cff930 [vm/aot] Discard Code objects from the heap
While deserializing AOT snapshot, Code objects which do not contain
valuable information besides entry point and stack maps are discarded
and not allocated on the heap (they are replaced with
StubCode::UnknownDartCode()).

PC -> Code/CompressedStackMaps lookup is implemented using a separate
table (InstructionsTable).

Flutter gallery in release-sizeopt mode:
Heap size of snapshot objects: arm -26.89%, arm64 -27.68%

Large Flutter application in release mode with --dwarf-stack-traces:
Heap size of snapshot objects: -24.3%.
Discarded Code objects: 72.5% of all Code objects.

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

TEST=existing tests; "--dwarf_stack_traces --no-retain_function_objects
--no-retain_code_objects" mode is enabled for a few tests.

Change-Id: I5fe3e283630c8e8f4442319d5dcae38d174dd0d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189560
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2021-04-13 02:36:16 +00:00
Ryan Macnak 25fd0200ef [vm] Replace recanonicalization in primary snapshots with weak constant tables.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/41974
Change-Id: Icc4a3ebf861dca5172a0cfa2cd2eea266e814d0c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181480
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2021-02-10 01:21:07 +00:00
Ryan Macnak b1c09ecd8f [vm] Make naming more consistent when converting between handles, tagged and untagged pointers.
Currently we have things called XPtr which are not what you get from ptr().

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

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

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

TEST=ci
Change-Id: I6c7f34014cf20737607caaf84979838300d12df2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149367
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-01-15 23:32:02 +00:00
Regis Crelier b3bca1821c [VM/runtime] Decouple representation of function signatures from Function objects.
This fixes issue https://github.com/dart-lang/sdk/issues/43088

This CL improves on https://dart-review.googlesource.com/c/sdk/+/166920 by keeping the names of type parameters.

See go/dart-vm-signatures for motivation for this change.

TEST=existing suites

Change-Id: Ia82f1d322f72d07b2fb253cf914f9b868025c71e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/176981
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2021-01-07 23:45:37 +00:00
Ryan Macnak abbb51e1ff [vm] Clean up metadata tracking.
Remove the use of Fields, which have since the metadata mechanism was introduced come to require global registration.

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

TEST=ci
Change-Id: Ifa4cc7724096c606f994b057b7838e124ceb3626
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175141
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-07 19:43:48 +00:00
Clement Skau c5eb666bcf Revert "[vm] Track metadata by identity instead of name."
This reverts commit bfd382820f.

Reason for revert: Breaks several lib_2/mirrors/ tests

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

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

Change-Id: Icf75e91872d9c85ce9be29a9a178d72ca024c98b
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174920
Reviewed-by: Clement Skau <cskau@google.com>
Commit-Queue: Clement Skau <cskau@google.com>
2020-12-03 08:03:11 +00:00
Ryan Macnak bfd382820f [vm] Track metadata by identity instead of name.
Remove the use of Fields, which have since the metadata mechanism was introduced come to require global registration.

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

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

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/44091
Change-Id: I7bf6449bf7dfeabd9db76e4bb37456e3be2d5124
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172861
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-11-30 23:43:54 +00:00
Martin Kustermann dab1efeb5d [vm/concurrency] Make the IGs own the initial static field value table
As part of making lightweight isolates work in JIT, we will need to
ensure that whenever a new isolate is spawned it will get it's initial
global field table populated.

In order to achieve this we make the isolate groups initial field table
the authoritive place where we

  a) register initial static field values
  b) serializer reads them from, deserializer writes them to

This allows us to also remove the `FieldLayout::initial_saved_value_`
that was present for both static and non-static fields. In reality this
initial saved value is only meaningful for static fields though it was
kept in memory as well as (de)serialized even for non-static fields.

The one place where it was actually used for non-static fields was
incorrect and should instead use `null`.

The removal of this field results in net removal of code in this CL.

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

TEST=Internal refactoring, relying on existing test coverage.

Change-Id: I088a87e2ea159bac7fa7f1f360da553d752e6569
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173263
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2020-11-24 11:25:58 +00:00
Martin Kustermann c8ebfcd739 [vm] Remove unused code related to RedirectionData
Since the transition from Source based to Kernel based frontend to the
Dart VM, we have not supported callable redirecting factories. This has
caused all removed code in this CL to be unused and untested!

The support for reifing redirection related information would mainly be
used by embedder / dart:mirrors. Right now its not used by anyone and
the kernel support was never implemented.

I suggest we remove the unused and untested code until a decision has
been made that we actually want to support it - in which case it can be
properly implemented, possibly by re-using some of the deleted code in
this CL.

TEST=CL removes unused code, no test result changes.

Change-Id: I7ed45c85b4efcc1e81ce44cbe08bb555e52101b9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166853
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-11-17 08:51:30 +00:00
Ben Konyi 996626c089 [ VM / Service ] Remove ReceivePort debugging information in product
builds.

Change-Id: Ie054fa03b3c8d6dc849c9e369b5b4ec48a4b3d2d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170402
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-11-06 19:23:23 +00:00
Ben Konyi d5118d5fc8 Reland "[ Service / dart:isolate ] Added getPorts RPC and 'debugName' optional"
This reverts commit f78c40e32a.

Change-Id: Id838b39afcb371d3b50f0009322ecf0fb2080894
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169461
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2020-10-29 02:52:03 +00:00
Alexander Markov 7588ed86de Remove bytecode mode from the VM
Change-Id: Ief167b7ffc128105a03cc225ab750234c9a6a7a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169147
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-10-28 17:42:35 +00:00
Tess Strickland f78c40e32a Revert "Reland "[ Service / dart:isolate ] Added getPorts RPC and 'debugName' optional""
This reverts commit a5d4511847.

Reason for revert: Failure in test standalone_2/io/unix_socket_test on reload bots, see https://github.com/dart-lang/sdk/issues/43952.

Original change's description:
> Reland "[ Service / dart:isolate ] Added getPorts RPC and 'debugName' optional"
>
> This reverts commit b71477a2a6.
>
> Change-Id: Iba11c41e43ec8c08b48147bbd07b71a151c3d1e6
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169243
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Ben Konyi <bkonyi@google.com>

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

Change-Id: I2ac1f18fef03d29bf74df4f49a91406a26f1ce26
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169323
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2020-10-28 10:51:40 +00:00
Ben Konyi a5d4511847 Reland "[ Service / dart:isolate ] Added getPorts RPC and 'debugName' optional"
This reverts commit b71477a2a6.

Change-Id: Iba11c41e43ec8c08b48147bbd07b71a151c3d1e6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169243
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2020-10-28 00:49:11 +00:00
Ben Konyi b71477a2a6 Revert "[ Service / dart:isolate ] Added getPorts RPC and 'debugName' optional"
This reverts commit 5bf9163e1b.

Reason for revert: Tests failing on bots.

Original change's description:
> [ Service / dart:isolate ] Added getPorts RPC and 'debugName' optional
> parameter for ReceivePort and RawReceivePort
>
> This change collects additional information related to ReceivePort
> allocation locations and an optional debug name that will be displayed
> by tooling. ReceivePort is now a special InstanceKind and a ReceivePort
> @Instance will include the port ID, allocation stack trace, and debug
> name.
>
> Change-Id: I003cfff2b7649218e37d9b653c0e953df5d992e7
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167902
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

TBR=bkonyi@google.com,rmacnak@google.com,asiva@google.com

Change-Id: I39c3abb07c8c40c158eb4549749b076399bccce9
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169160
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2020-10-27 03:14:30 +00:00
Ben Konyi 5bf9163e1b [ Service / dart:isolate ] Added getPorts RPC and 'debugName' optional
parameter for ReceivePort and RawReceivePort

This change collects additional information related to ReceivePort
allocation locations and an optional debug name that will be displayed
by tooling. ReceivePort is now a special InstanceKind and a ReceivePort
@Instance will include the port ID, allocation stack trace, and debug
name.

Change-Id: I003cfff2b7649218e37d9b653c0e953df5d992e7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167902
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-10-26 23:09:47 +00:00
Ryan Macnak d4ffb92ed8 [vm] Reify loading units.
Loading unit metadata is expanded to create an object representing each loading unit, and each library to reference the loading unit it is a part of.

To be used at compile-time to help assign objects to snapshots.

To be used at runtime to track which units have been loading and the base objects for cross-snapshot references.

Bug: https://github.com/dart-lang/sdk/issues/41974
Change-Id: Icd3fa95ffd5949bd8f7f84a6f750c4c515de0dba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/151865
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-07-09 00:15:07 +00:00
Alexander Markov 994f454996 [vm/nnbd] Call field initializer from stubs for late instance fields
This change introduces 2 new stubs, InitLateInstanceField and
InitLateFinalInstanceField. Those stubs call field initializer
directly without going to runtime.

Fixes the regressions on Uri.pathSegments.easy and Uri.pathSegments.hard.normalized
benchmarks with NNBD SDK after https://dart-review.googlesource.com/c/sdk/+/143189.

Change-Id: I6bde7a98010ac1321a95eda8b0f125105f3993c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144807
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-04-28 21:35:23 +00:00
Ryan Macnak 6fe15f6df9 [vm] Represent tagged pointers as C++ value types instead of C++ pointer types.
This works around bugs in UndefinedBehaviorSanitizer and Clang.

Bug: b/28638298
Change-Id: I6be595f9664516019d28017d24559583a1ae3a21
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144354
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-04-25 05:21:27 +00:00
Alexander Aprelev 80ae6ed91d [vm/aot-switchable-calls] Introduce single runtime entry for all switchable calls
Bug: https://github.com/dart-lang/sdk/issues/37835
Bug: https://github.com/dart-lang/sdk/issues/36097
Change-Id: I0198fd0328945b04e4f2254bacac25b41038e78c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138361
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-04-04 15:03:48 +00:00
Teagan Strickland b55342cb3e [vm/aot] Drop some Function objects not needed at runtime.
In particular, don't serialize a function if its code is used by the
dispatch table, but there's no need for the function object itself
at runtime like dynamic lookup or dynamic invocation forwarders.

However, just because the owning function is not needed at runtime,
it may be used during serialization for things like assembly label
creation. Thus, instead of just clearing out the Code's owner field,
we add a new WeakSerializationReference (WSR) object whose target is
the original contents of the owner field. The WSR allows the
serializer to access the original owner, but also signals to the
serializer that the target should not be serialized in AOT snapshots
unless there are additional strong (non-WSR) references.

If no strong references are found, then the references to the WSR
in the snapshot are replaced with a reference to a WSR that only
contains the class ID of the original target. The serializer creates
only one WSR per class ID.

If strong references are found, then the target is still serialized.
In this case, the WSR is dropped entirely and any reference to it is
replaced with a direct reference to the serialized target. Thus, WSRs
only exist in the precompiled runtime for targets with no strong
references.

Changes on the Flutter gallery in release mode:
arm7: total size -1.10%, isolate size -6.08%
arm8: total size -1.16%, isolate size -6.09%

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

Change-Id: I5b435ca71ef85f50fe3484789087471a91aa4fe2
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-kernel-precomp-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137104
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2020-03-30 18:33:48 +00:00
Regis Crelier cfc006a8f4 [VM/nnbd] Fix sharing of type argument vectors (fixes #40451).
Apply the same fix as in https://dart-review.googlesource.com/c/sdk/+/136709
to TypeArguments::CanShareInstantiatorTypeArguments and to TypeArguments::CanShareFunctionTypeArguments.

Move the inlined code performing an instantiation cache lookup to stubs in order to reduce code size.
Add stubs checking nullability of type arguments to share instantiator (or function) type arguments before looking up instantiation cache, and possibly calling into the runtime for instantiation.
Modify constant propagator to instantiate constant type arguments at compile time.

Change-Id: I72fee1a6881ac3bec55fae7d0ef5a3361544a141
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138009
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-03-13 22:29:47 +00:00
Daco Harkes d950783c07 [vm/ffi] Unify RawTypedData::data and Pointer::data
This does not make FFI Structs with TypedData yet, but makes the loads/stores support using TypedData.

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

Change-Id: I5d03e324c98c79c07955d70db86ab2e2d8dc4ec2
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137305
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-03-05 17:18:24 +00:00
Daco Harkes b406802981 [vm/ffi] Unbox Pointer data field
This regresses Pointer load and store loops because LoadUntagged is never hoisted out of loops. But with support for passing TypedData, in a follow up CL, we cannot assume that only Pointers are passed in the future.

It also changes the FfiCallInstr context to hold the Pointer, rather than the address, as call sites can be unoptimized and we cannot handle an untagged address there.

Issue: https://github.com/dart-lang/sdk/issues/40767
Issue: https://github.com/dart-lang/sdk/issues/36730
Change-Id: Icc716d79eb9eb2b5aac4f03dbf6c622a6825ffdc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137793
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-03-05 17:18:24 +00:00
Alexander Markov c1616f92ef [vm] Introduce FutureOr class in the VM
This makes it possible to use FutureOrCid in the VM and efficiently
test if type is FutureOr. This also makes it possible to use predicates
like IsTopType very early during VM bootstrapping (before reusable
handles are initialized). The latter is needed to correctly select
type testing stub for top types.

Change-Id: I4c482143c0ebaafa1c8e13e95dc6f20e3af7059a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136000
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2020-02-14 21:40:17 +00:00
Alexander Aprelev e2aadc7a07 Reland "[vm/fieldtable] Move current field values out of Field object into separate table."
This reverts commit c8f8c11b70 with the fix for https://github.com/flutter/flutter/issues/49008 in Patchset 2.

Change-Id: I85406b92a69ed950d0ba945f96997658be3cae64
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132302
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2020-01-17 18:12:24 +00:00