Commit graph

51 commits

Author SHA1 Message Date
Martin Kustermann ef9d699f07 [vm/concurrency] Move all information except for the class pointers out of [ClassTable] into [SharedClassTable]
This CL moves heap related information (namely instance sizes and
allocation stats) out of the [ClassTable] into a [SharedClassTable].
Both classes are always in sync (i.e. they have the same number of entries).

This CL also changes GC related code to start using the size information
from the new [SharedClassTable].

In a futher step we will move the heap as well as this shared class
table out of the [Isolate] and into [IsolateGroup].

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

Change-Id: Id54a89c9251ad3bbc13e60d32dc4f7bcc7f1d805
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/116064
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2019-09-10 12:48:16 +00:00
Ryan Macnak 7e7369cd98 [vm, bytecode] Don't write Bytecode::var_descriptors_ in snapshots.
This matches the behavior for Code::var_descriptors and causes the field to effectively be nulled when writing a snapshot. It may be lazily recomputed by the reader. Fixes various app-jit tests in bytecode mode that causes the var descriptors to be generating by printing stack traces.

Change-Id: I04fddaf46508050eeab8af63d5c6eb1e1b7fa51f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/115000
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-08-29 22:29:13 +00:00
Ryan Macnak 980e5c7b57 [vm] Mark VM isolate objects at heap finalization instead of allocation.
Avoids unnecessary branching in allocation.

Also, rename the VMHeap bit to ReadOnly to reflect its current usage.

Change-Id: Ic6060eec263cef0a3fc92f253dff976cea45bdb2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95063
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2019-03-07 00:20:30 +00:00
Ryan Macnak fba89f9f64 [vm] Don't change the content of the VM isolate's snapshot based on what was loading into a core or app snapshot.
Ensures, by default, multiple core or app snapshots are capable of being loaded into the same process. Flags that affect stub generation can still create incompatibilities. A later CL will internalize VM isolate snapshot generation to the VM build and ensure compatibility.

Change-Id: I247063d5a3a611b04963b8e8ab2ac8a1f20ea57a
Reviewed-on: https://dart-review.googlesource.com/c/93962
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-02-26 19:04:50 +00:00
Martin Kustermann 51bc367806 [VM/AOT] Ensure we set flags from snapshot very early in the VM initialization
There are uses of flags before the VM snapshot gets read, so we need to
move the "snapshot sniffing" code to the very beginning of Dart::Init().

Due to the fact that FullSnapshotReader/Deserializer assume there is a
[Thread] available - and we don't have a [Thread] yet when we should
process the flags - this CL moves version/feature logic into a new
[SnapshotHeaderReader] class which does not depend on Thread/...

Change-Id: I38a45041f0696b96e44fc2b294e3442a5fba1a81
Reviewed-on: https://dart-review.googlesource.com/c/90941
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2019-01-25 10:31:48 +00:00
Ryan Macnak b6b4836d1d [vm] Reference type test stubs through Code; use the type as the owner of a type test stub.
Directly referencing VM isolate instructions from an isolate snapshot causes the instructions to be copied into the isolate's image page because instructions do not use the indirection of the ref array. Duplicating the instructions caused TypeTestingStubFinder::LookupByAddresss to be unable to identity the duplicate copies of the VM isolate type testing stubs.

Fixes identity of StubCode::*TypeTest broken by duplication in snapshot.
Fixes generating AppJIT snapshots after loading from AppJIT snapshots.
Fixes attribution of ticks for type test stubs in the AOT profiler.

Change-Id: I9879a85bd548e694ee36e14f795898582ccdddb0
Reviewed-on: https://dart-review.googlesource.com/c/90501
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
2019-01-23 22:59:47 +00:00
Martin Kustermann f1f688215a [VM/AOT] Initialize global VM flags by reading them from vm-isolate snapshots
Issue https://github.com/dart-lang/sdk/issues/33274

Change-Id: I2dca1fb9a8807294fb756ea796bb7560bb6d17cc
Reviewed-on: https://dart-review.googlesource.com/c/90221
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2019-01-23 09:49:46 +00:00
Vyacheslav Egorov a9ce969e53 [vm] Decouple growable_array.h and zone.h from thread.h
- Introduce a slimmed down version of thread.h, which just depends on the
Zone and StackResource.
- Introduce a layering check that would prevent the coupling in the future.

This is the first step towards decoupling compiler from runtime.

There are multiple reasons to introduce the decoupling but the main
reason currently is to introduce a controlled surface through which
compiler reaches into runtime to catch any places where runtime word size
might influence the compiler and then enable building compiler that
targets 32-bit runtime but is embedded into a 64-bit runtime.

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

Change-Id: Id63ebbaddca55dd097298e51c90d957a73fa476e
Reviewed-on: https://dart-review.googlesource.com/c/87182
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2019-01-11 20:47:10 +00:00
Martin Kustermann 288d5f0a2a [VM] Bare instructions - Part 2: Start relocating instructions in AOT mode
Start ordering instructions before writing them out in AOT snapshots.

This is done by:

  * discovery of relevant code objects
  * ordering of the code objects (currently simply discovery order)
  * relocate any pc-relative calls by patching up pc-relative calls with
    the actual distance
  * producing image writer commands which tell it in which order and at
    which .text offsets to write out instructions

Note: Our compiler currently does not emit any pc-relative calls. This
will be added later on.

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

Change-Id: I0153c32a7427ea395e80489efadd5513fe7ca371
Reviewed-on: https://dart-review.googlesource.com/c/85745
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2018-12-13 12:53:09 +00:00
Martin Kustermann e4e77b9817 [VM] Bare instructions - Part 1: Add support for telling the image writer in which order instructions should be written
Issue https://github.com/dart-lang/sdk/issues/33274

Change-Id: If8c967d3ecafc551938271ce52157c5c4f384dff
Reviewed-on: https://dart-review.googlesource.com/c/85764
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2018-12-13 12:10:59 +00:00
Samir Jindel 96dda6a516 Re-land "[vm/aot] Fill in names of properties in snapshot profile."
This reverts commit dc346e6fdd.

Cq-Include-Trybots: luci.dart.try:vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try, vm-kernel-precomp-mac-release-simarm64-try, vm-kernel-precomp-win-release-x64-try
Change-Id: I1b9181683757cf47f917274d21c8fc1c463218c7
Reviewed-on: https://dart-review.googlesource.com/c/85709
Commit-Queue: Samir Jindel <sjindel@google.com>
Auto-Submit: Samir Jindel <sjindel@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2018-12-03 19:11:42 +00:00
Alexander Aprelev dc346e6fdd Revert "[vm/aot] Fill in names of properties in snapshot profile."
This reverts commit 465f8595ec as it
breaks windows and mac bots.

Change-Id: I94a939d711f69a28f405ee32680315ad6677b09e
Reviewed-on: https://dart-review.googlesource.com/c/85722
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2018-11-30 19:52:23 +00:00
Samir Jindel 465f8595ec [vm/aot] Fill in names of properties in snapshot profile.
Change-Id: Ic709a3dc40390463ffb5fd76fd8eb63ebd87acc0
Cq-Include-Trybots: luci.dart.try:vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try, vm-kernel-precomp-mac-release-simarm64-try
Reviewed-on: https://dart-review.googlesource.com/c/85292
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2018-11-30 18:38:05 +00:00
Samir Jindel 880dfa0bca [vm/aot] Refactor clustered snapshot serialization to allow reflection of field names.
Cq-Include-Trybots: luci.dart.try:vm-kernel-win-release-x64-try, vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try
Change-Id: I6553e4a7964e953d1722975d20c89fee441ceb61
Reviewed-on: https://dart-review.googlesource.com/c/84627
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Auto-Submit: Samir Jindel <sjindel@google.com>
2018-11-26 14:17:47 +00:00
Samir Jindel cde4270e47 Re-land "[vm/aot] Snapshot size analysis."
Minor fixes have been applied, see diff against patchset 1.

This reverts commit 9b937f1226.

Change-Id: I8e4bbc0b88e33d3b554e91c17d1f849e24a1ccb3
Cq-Include-Trybots: luci.dart.try:vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try, vm-kernel-win-product-x64-try, vm-kernel-precomp-win-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/84845
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Auto-Submit: Samir Jindel <sjindel@google.com>
2018-11-22 15:14:46 +00:00
Zach Anderson 9b937f1226 Revert "[vm/aot] Snapshot size analysis."
This reverts commit 06c89287b9.

Reason for revert:
- Failure of v8_snapshot_profile_writer_test on vm-kernel-precomp-android-release
- many failures on windows precomp (?)
- link failures in windows product builds.

Original change's description:
> [vm/aot] Snapshot size analysis.
> 
> Cq-Include-Trybots: luci.dart.try:vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try
> Change-Id: Ie5d5d9f0f064f2c9ef8b7c9a0537b1e633bf8175
> Reviewed-on: https://dart-review.googlesource.com/c/84425
> Commit-Queue: Samir Jindel <sjindel@google.com>
> Reviewed-by: Ryan Macnak <rmacnak@google.com>

TBR=vegorov@google.com,rmacnak@google.com,sjindel@google.com

Change-Id: I461f06236f27bb5c6548bd08f4b73507d1b913fa
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Cq-Include-Trybots: luci.dart.try:vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/84860
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
2018-11-19 22:29:09 +00:00
Samir Jindel 06c89287b9 [vm/aot] Snapshot size analysis.
Cq-Include-Trybots: luci.dart.try:vm-kernel-optcounter-threshold-linux-release-x64-try, vm-kernel-precomp-linux-debug-x64-try, vm-kernel-precomp-linux-release-simarm-try, vm-kernel-precomp-linux-release-simarm64-try, vm-kernel-precomp-linux-release-x64-try
Change-Id: Ie5d5d9f0f064f2c9ef8b7c9a0537b1e633bf8175
Reviewed-on: https://dart-review.googlesource.com/c/84425
Commit-Queue: Samir Jindel <sjindel@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2018-11-19 20:29:05 +00:00
Régis Crelier f721d52163 [VM runtime] Introduce a new VM class Bytecode.
Allow pc_marker slot to hold a Code object or a new Bytecode object.

Change-Id: If11c1df6dafc5b1cfcce6f0322c36d1d68e86df9
Reviewed-on: https://dart-review.googlesource.com/c/82526
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2018-11-14 02:48:03 +00:00
Alexander Markov a4dc8cd22e [vm/kernel/bytecode] Make sure bytecode instructions are aligned in kernel
Change-Id: I109123e88b8352b198d5ef9aad9eedc1df7141c8
Reviewed-on: https://dart-review.googlesource.com/c/83543
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2018-11-09 17:08:46 +00:00
Ryan Macnak 8da46d35f5 [vm] Move heap-related code to its own subdirectory (cf. compiler).
Remove some dead includes.

Change-Id: I31f3e739e5ee46dcbba5d6a2f091491b46402943
Reviewed-on: https://dart-review.googlesource.com/60146
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2018-06-20 00:39:49 +00:00
Ryan Macnak 0cc70c4a7c [vm] Support for sharing parts of an app snapshot.
In addition, this removes support for seeding the VM isolate snapshot with Instructions and referencing those Instructions in the isolate snapshot. This was leftover from an earlier experiment to share Instructions between a Core-JIT snapshot and App-JIT snapshots. Removing this reclaims the sign bit on Instruction offsets.

Add missing cases to TypeTestingStubFinder::StubNameFromAddresss.

Change-Id: Ie87216b4e284db1dc3eddb12f38ddbe8a841d312
Reviewed-on: https://dart-review.googlesource.com/50620
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2018-04-27 17:42:16 +00:00
Martin Kustermann 3b414a277c Reland "[VM] Introduction of type testing stubs - Part 1-4"
Relands 165c583d57

    [VM] Introduction of type testing stubs - Part 1

    This CL:

      * Adds a field to [RawAbstractType] which will always hold a pointer
        to the entrypoint of a type testing stub

      * Makes this new field be initialized to a default stub whenever a
        instances are created (e.g. via Type::New(), snapshot reader, ...)

      * Makes the clustered snapshotter write a reference to the
        corresponding [RawInstructions] object when writing the field and do
        the reverse when reading it.

      * Makes us call the type testing stub for performing assert-assignable
        checks.

    To reduce unnecessary loads on callsites, we store the entrypoint of the
    type testing stubs directly in the type objects.  This means that the
    caller of type testing stubs can simply branch there without populating
    a code object first.  This also means that the type testing stubs
    themselves have no access to a pool and we therefore also don't hold on
    to the [Code] object, only the [Instruction] object is necessary.

    The type testing stubs do not setup a frame themselves and also have no
    safepoint.  In the case when the type testing stubs could not determine
    a positive answer they will tail-call a general-purpose stub.

    The general-purpose stub sets up a stub frame, tries to consult a
    [SubtypeTestCache] and bails out to runtime if this was unsuccessful.

    This CL is just the the first, for ease of reviewing.  The actual
    type-specialized type testing stubs will be generated in later CLs.

    Reviewed-on: https://dart-review.googlesource.com/44787

Relands f226c22424

    [VM] Introduction of type testing stubs - Part 2

    This CL starts building type testing stubs specialzed for [Type] objects
    we test against.

    More specifically, it adds support for:

      * Handling obvious fast cases on the call sites (while still having a
        call to stub for negative case)

      * Handling type tests against type parameters, by loading the value
        of the type parameter on the call sites and invoking it's type testing stub.

      * Specialzed type testing stubs for instantiated types where we can
        do [CidRange]-based subtype-checks.

        ==> e.g. String/List<dynamic>

      * Specialzed type testing stubs for instantiated types where we can
        do [CidRange]-based subclass-checks for the class and
        [CidRange]-based subtype-checks for the type arguments.

        ==> e.g. Widget<State>, where we know [Widget] is only extended and not
                 implemented.

      * Specialzed type testing stubs for certain non-instantiated types where we
        can do [CidRange]-based subclass-checks for the class and
        [CidRange]-based subtype-checks for the instantiated type arguments and
        cid based comparisons for type parameters.  (Note that this fast-case migth
        result in some false-negatives!)

        ==> e.g. _HashMapEntry<K, V>, where we know [_HashMapEntry] is only
                 extended and not implemented.

       This optimizes cases where the caller uses `new HashMap<A, B>()` and only
       uses `A` and `B` as key/values (and not subclasses of it).  The false-negative
       can occur when subtypes of A or B are used.  In such cases we fall back to the
       [SubtypeTestCache]-based imlementation.

    Reviewed-on: https://dart-review.googlesource.com/44788

Relands 25f98bcc75

    [VM] Introduction of type testing stubs - Part 3

    The changes include:

      * Make AssertAssignableInstr no longer have a call-summary, which
        helps methods with several parameter checks by not having to
        re-load/re-initialize type arguments registers

      * Lazily create SubtypeTestCaches: We already go to runtime to warm up
        the caches, so we now also create the caches on the first runtime
        call and patch the pool entries.

      * No longer load the destination name into a register: We only need
        the name when we throw an exception, so it is not on the hot path.
        Instead we let the runtime look at the call site, decoding a pool
        index from the instructions stream.  The destination name will be
        available in the pool, at a consecutive index to the subtype cache.

      * Remove the fall-through to N=1 case for probing subtypeing tests,
        since those will always be handled by the optimized stubs.

      * Do not generate optimized stubs for FutureOr<T> (so far it just
        falled-through to TTS).  We can make optimzed version of that later,
        but it requires special subtyping rules.

      * Local code quality improvement in the type-testing-stubs: Avoid
        extra jump at last case of cid-class-range checks.

    There are still a number of optimization opportunities we can do in
    future changes.

    Reviewed-on: https://dart-review.googlesource.com/46984

Relands 2c52480ec8

    [VM] Introduction of type testing stubs - Part 4

    In order to avoid generating type testing stubs for too many types in
    the system - and thereby potentially cause an increase in code size -
    this change introduces a smarter way to decide for which types we should
    generate optimized type testing stubs.

    The precompiler creates a [TypeUsageInfo] which we use to collect
    information.  More specifically:

       a) We collect the destination types for all type checks we emit
          (we do this inside AssertAssignableInstr::EmitNativeCode).

          -> These are types we might want to generate optimized type testing
             stubs for.

       b) We collect type argument vectors used in instance creations (we do
          this inside AllocateObjectInstr::EmitNativeCode) and keep a set of
          of used type argument vectors for each class.

    After the precompiler has finished compiling normal code we scan the set
    of destination types collected in a) for uninstantiated types (or more
    specifically, type parameter types).

    We then propagate the type argument vectors used on object allocation sites,
    which were collected in b), in order to find out what kind of types are flowing
    into those type parameters.

    This allows us to extend the set of types which we test against, by
    adding the types that flow into type parameters.

    We use this final augmented set of destination types as a "filter" when
    making the decision whether to generate an optimized type testing stub
    for a given type.

    Reviewed-on: https://dart-review.googlesource.com/48640

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

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

Change-Id: Ib79fbe7f043aa88f32bddad62d7656c638914b44
Reviewed-on: https://dart-review.googlesource.com/50944
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2018-04-13 09:06:56 +00:00
Ryan Macnak 6db4ea4ca5 [vm] Use unsigned varints when possible in the clustered snapshot.
- References
 - ROData offsets
 - Cluster sizes
 - Variable-length object lengths

flutter_gallery:
Isolate(CodeSize): 2384368 -> 2302404 (-3.4%)
Total(CodeSize): 11651807 -> 11569439 (-0.7%)

Change-Id: I59ea4d4a48fcbecf5236d3895b495c88ed548ec3
Reviewed-on: https://dart-review.googlesource.com/50841
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2018-04-12 17:37:39 +00:00
Ryan Macnak b3c94b5d52 Revert "Reland "[VM] Introduction of type testing stubs - Part 1-4""
This reverts commit 34763bc4c9.

Bug: https://github.com/dart-lang/sdk/issues/32852
Change-Id: I2131907d7036644707d5109a951969fc48dd74e1
Reviewed-on: https://dart-review.googlesource.com/50842
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2018-04-11 22:42:59 +00:00
Vyacheslav Egorov 0b83be906c [vm/compiler/aot] Introduce ways to dump instruction size statistics.
We add two things:

* --print_instruction_stats makes compiler dump per IL instruction size
breakdown (how many bytes of code were produced from specific instruction
kinds). This was largely implemented by kustermann@ in
https://codereview.chromium.org/2584613002/ and this CL does only few changes
to the original implementation, namely more uniform handling of slow-path code
and puts statistics object into RawInstructions (which has free space due to
alignment) instead of RawCode.

* --print_instructions_sizes_to=symbols.json makes compiler dump per Instruction
object size breakdown into a JSON file. This JSON file can later be processed
with pkg/vm/tool/run_binary_size_analysis.dart script to produce interactive
binary size diagram similar to runtime/third_party/binary_size tool.

Change-Id: Ied4965b9a0a91b3025eefbe981ecd47cdcf782d6
Reviewed-on: https://dart-review.googlesource.com/50501
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2018-04-11 13:03:16 +00:00
Martin Kustermann 34763bc4c9 Reland "[VM] Introduction of type testing stubs - Part 1-4"
Relands 165c583d57

    [VM] Introduction of type testing stubs - Part 1

    This CL:

      * Adds a field to [RawAbstractType] which will always hold a pointer
        to the entrypoint of a type testing stub

      * Makes this new field be initialized to a default stub whenever a
        instances are created (e.g. via Type::New(), snapshot reader, ...)

      * Makes the clustered snapshotter write a reference to the
        corresponding [RawInstructions] object when writing the field and do
        the reverse when reading it.

      * Makes us call the type testing stub for performing assert-assignable
        checks.

    To reduce unnecessary loads on callsites, we store the entrypoint of the
    type testing stubs directly in the type objects.  This means that the
    caller of type testing stubs can simply branch there without populating
    a code object first.  This also means that the type testing stubs
    themselves have no access to a pool and we therefore also don't hold on
    to the [Code] object, only the [Instruction] object is necessary.

    The type testing stubs do not setup a frame themselves and also have no
    safepoint.  In the case when the type testing stubs could not determine
    a positive answer they will tail-call a general-purpose stub.

    The general-purpose stub sets up a stub frame, tries to consult a
    [SubtypeTestCache] and bails out to runtime if this was unsuccessful.

    This CL is just the the first, for ease of reviewing.  The actual
    type-specialized type testing stubs will be generated in later CLs.

    Reviewed-on: https://dart-review.googlesource.com/44787

Relands f226c22424

    [VM] Introduction of type testing stubs - Part 2

    This CL starts building type testing stubs specialzed for [Type] objects
    we test against.

    More specifically, it adds support for:

      * Handling obvious fast cases on the call sites (while still having a
        call to stub for negative case)

      * Handling type tests against type parameters, by loading the value
        of the type parameter on the call sites and invoking it's type testing stub.

      * Specialzed type testing stubs for instantiated types where we can
        do [CidRange]-based subtype-checks.

        ==> e.g. String/List<dynamic>

      * Specialzed type testing stubs for instantiated types where we can
        do [CidRange]-based subclass-checks for the class and
        [CidRange]-based subtype-checks for the type arguments.

        ==> e.g. Widget<State>, where we know [Widget] is only extended and not
                 implemented.

      * Specialzed type testing stubs for certain non-instantiated types where we
        can do [CidRange]-based subclass-checks for the class and
        [CidRange]-based subtype-checks for the instantiated type arguments and
        cid based comparisons for type parameters.  (Note that this fast-case migth
        result in some false-negatives!)

        ==> e.g. _HashMapEntry<K, V>, where we know [_HashMapEntry] is only
                 extended and not implemented.

       This optimizes cases where the caller uses `new HashMap<A, B>()` and only
       uses `A` and `B` as key/values (and not subclasses of it).  The false-negative
       can occur when subtypes of A or B are used.  In such cases we fall back to the
       [SubtypeTestCache]-based imlementation.

    Reviewed-on: https://dart-review.googlesource.com/44788

Relands 25f98bcc75

    [VM] Introduction of type testing stubs - Part 3

    The changes include:

      * Make AssertAssignableInstr no longer have a call-summary, which
        helps methods with several parameter checks by not having to
        re-load/re-initialize type arguments registers

      * Lazily create SubtypeTestCaches: We already go to runtime to warm up
        the caches, so we now also create the caches on the first runtime
        call and patch the pool entries.

      * No longer load the destination name into a register: We only need
        the name when we throw an exception, so it is not on the hot path.
        Instead we let the runtime look at the call site, decoding a pool
        index from the instructions stream.  The destination name will be
        available in the pool, at a consecutive index to the subtype cache.

      * Remove the fall-through to N=1 case for probing subtypeing tests,
        since those will always be handled by the optimized stubs.

      * Do not generate optimized stubs for FutureOr<T> (so far it just
        falled-through to TTS).  We can make optimzed version of that later,
        but it requires special subtyping rules.

      * Local code quality improvement in the type-testing-stubs: Avoid
        extra jump at last case of cid-class-range checks.

    There are still a number of optimization opportunities we can do in
    future changes.

    Reviewed-on: https://dart-review.googlesource.com/46984

Relands 2c52480ec8

    [VM] Introduction of type testing stubs - Part 4

    In order to avoid generating type testing stubs for too many types in
    the system - and thereby potentially cause an increase in code size -
    this change introduces a smarter way to decide for which types we should
    generate optimized type testing stubs.

    The precompiler creates a [TypeUsageInfo] which we use to collect
    information.  More specifically:

       a) We collect the destination types for all type checks we emit
          (we do this inside AssertAssignableInstr::EmitNativeCode).

          -> These are types we might want to generate optimized type testing
             stubs for.

       b) We collect type argument vectors used in instance creations (we do
          this inside AllocateObjectInstr::EmitNativeCode) and keep a set of
          of used type argument vectors for each class.

    After the precompiler has finished compiling normal code we scan the set
    of destination types collected in a) for uninstantiated types (or more
    specifically, type parameter types).

    We then propagate the type argument vectors used on object allocation sites,
    which were collected in b), in order to find out what kind of types are flowing
    into those type parameters.

    This allows us to extend the set of types which we test against, by
    adding the types that flow into type parameters.

    We use this final augmented set of destination types as a "filter" when
    making the decision whether to generate an optimized type testing stub
    for a given type.

    Reviewed-on: https://dart-review.googlesource.com/48640

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

Change-Id: I6d33d4ca3d5187a1eb1664078c003061855f0160
Reviewed-on: https://dart-review.googlesource.com/50482
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2018-04-10 12:20:10 +00:00
Martin Kustermann 1e997ee6b7 Revert "Reland "[VM] Introduction of type testing stubs - Part 1-4""
This reverts commit 8054409a02.

Reason for revert: Potential cause of flakes, not entirely clear yet if it was caused by this CL.

Change-Id: Icb119a107f22245ba2f303c7f2ae11f061f605f5
Reviewed-on: https://dart-review.googlesource.com/50261
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2018-04-09 14:29:07 +00:00
Martin Kustermann 8054409a02 Reland "[VM] Introduction of type testing stubs - Part 1-4"
Relands 165c583d57

    [VM] Introduction of type testing stubs - Part 1

    This CL:

      * Adds a field to [RawAbstractType] which will always hold a pointer
        to the entrypoint of a type testing stub

      * Makes this new field be initialized to a default stub whenever a
        instances are created (e.g. via Type::New(), snapshot reader, ...)

      * Makes the clustered snapshotter write a reference to the
        corresponding [RawInstructions] object when writing the field and do
        the reverse when reading it.

      * Makes us call the type testing stub for performing assert-assignable
        checks.

    To reduce unnecessary loads on callsites, we store the entrypoint of the
    type testing stubs directly in the type objects.  This means that the
    caller of type testing stubs can simply branch there without populating
    a code object first.  This also means that the type testing stubs
    themselves have no access to a pool and we therefore also don't hold on
    to the [Code] object, only the [Instruction] object is necessary.

    The type testing stubs do not setup a frame themselves and also have no
    safepoint.  In the case when the type testing stubs could not determine
    a positive answer they will tail-call a general-purpose stub.

    The general-purpose stub sets up a stub frame, tries to consult a
    [SubtypeTestCache] and bails out to runtime if this was unsuccessful.

    This CL is just the the first, for ease of reviewing.  The actual
    type-specialized type testing stubs will be generated in later CLs.

    Reviewed-on: https://dart-review.googlesource.com/44787

Relands f226c22424

    [VM] Introduction of type testing stubs - Part 2

    This CL starts building type testing stubs specialzed for [Type] objects
    we test against.

    More specifically, it adds support for:

      * Handling obvious fast cases on the call sites (while still having a
        call to stub for negative case)

      * Handling type tests against type parameters, by loading the value
        of the type parameter on the call sites and invoking it's type testing stub.

      * Specialzed type testing stubs for instantiated types where we can
        do [CidRange]-based subtype-checks.

        ==> e.g. String/List<dynamic>

      * Specialzed type testing stubs for instantiated types where we can
        do [CidRange]-based subclass-checks for the class and
        [CidRange]-based subtype-checks for the type arguments.

        ==> e.g. Widget<State>, where we know [Widget] is only extended and not
                 implemented.

      * Specialzed type testing stubs for certain non-instantiated types where we
        can do [CidRange]-based subclass-checks for the class and
        [CidRange]-based subtype-checks for the instantiated type arguments and
        cid based comparisons for type parameters.  (Note that this fast-case migth
        result in some false-negatives!)

        ==> e.g. _HashMapEntry<K, V>, where we know [_HashMapEntry] is only
                 extended and not implemented.

       This optimizes cases where the caller uses `new HashMap<A, B>()` and only
       uses `A` and `B` as key/values (and not subclasses of it).  The false-negative
       can occur when subtypes of A or B are used.  In such cases we fall back to the
       [SubtypeTestCache]-based imlementation.

    Reviewed-on: https://dart-review.googlesource.com/44788

Relands 25f98bcc75

    [VM] Introduction of type testing stubs - Part 3

    The changes include:

      * Make AssertAssignableInstr no longer have a call-summary, which
        helps methods with several parameter checks by not having to
        re-load/re-initialize type arguments registers

      * Lazily create SubtypeTestCaches: We already go to runtime to warm up
        the caches, so we now also create the caches on the first runtime
        call and patch the pool entries.

      * No longer load the destination name into a register: We only need
        the name when we throw an exception, so it is not on the hot path.
        Instead we let the runtime look at the call site, decoding a pool
        index from the instructions stream.  The destination name will be
        available in the pool, at a consecutive index to the subtype cache.

      * Remove the fall-through to N=1 case for probing subtypeing tests,
        since those will always be handled by the optimized stubs.

      * Do not generate optimized stubs for FutureOr<T> (so far it just
        falled-through to TTS).  We can make optimzed version of that later,
        but it requires special subtyping rules.

      * Local code quality improvement in the type-testing-stubs: Avoid
        extra jump at last case of cid-class-range checks.

    There are still a number of optimization opportunities we can do in
    future changes.

    Reviewed-on: https://dart-review.googlesource.com/46984

Relands 2c52480ec8

    [VM] Introduction of type testing stubs - Part 4

    In order to avoid generating type testing stubs for too many types in
    the system - and thereby potentially cause an increase in code size -
    this change introduces a smarter way to decide for which types we should
    generate optimized type testing stubs.

    The precompiler creates a [TypeUsageInfo] which we use to collect
    information.  More specifically:

       a) We collect the destination types for all type checks we emit
          (we do this inside AssertAssignableInstr::EmitNativeCode).

          -> These are types we might want to generate optimized type testing
             stubs for.

       b) We collect type argument vectors used in instance creations (we do
          this inside AllocateObjectInstr::EmitNativeCode) and keep a set of
          of used type argument vectors for each class.

    After the precompiler has finished compiling normal code we scan the set
    of destination types collected in a) for uninstantiated types (or more
    specifically, type parameter types).

    We then propagate the type argument vectors used on object allocation sites,
    which were collected in b), in order to find out what kind of types are flowing
    into those type parameters.

    This allows us to extend the set of types which we test against, by
    adding the types that flow into type parameters.

    We use this final augmented set of destination types as a "filter" when
    making the decision whether to generate an optimized type testing stub
    for a given type.

    Reviewed-on: https://dart-review.googlesource.com/48640

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

Change-Id: I44a1d5d4b27454ae026aef2a301aada3dd399ea0
Reviewed-on: https://dart-review.googlesource.com/49861
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2018-04-09 11:25:36 +00:00
Martin Kustermann dbb1d3d44f Revert "[VM] Introduction of type testing stubs - Part 1-4"
This reverts commit 2c52480ec8.
This reverts commit 25f98bcc75.
This reverts commit f226c22424.
This reverts commit 165c583d57.

Change-Id: I3892d672b9ca0b0acc0b9b83c32ecc92355839c2
Reviewed-on: https://dart-review.googlesource.com/49843
Reviewed-by: Martin Kustermann <kustermann@google.com>
2018-04-06 08:35:01 +00:00
Martin Kustermann 165c583d57 [VM] Introduction of type testing stubs - Part 1
This CL:

  * Adds a field to [RawAbstractType] which will always hold a pointer
    to the entrypoint of a type testing stub

  * Makes this new field be initialized to a default stub whenever a
    instances are created (e.g. via Type::New(), snapshot reader, ...)

  * Makes the clustered snapshotter write a reference to the
    corresponding [RawInstructions] object when writing the field and do
    the reverse when reading it.

  * Makes us call the type testing stub for performing assert-assignable
    checks.

To reduce unnecessary loads on callsites, we store the entrypoint of the
type testing stubs directly in the type objects.  This means that the
caller of type testing stubs can simply branch there without populating
a code object first.  This also means that the type testing stubs
themselves have no access to a pool and we therefore also don't hold on
to the [Code] object, only the [Instruction] object is necessary.

The type testing stubs do not setup a frame themselves and also have no
safepoint.  In the case when the type testing stubs could not determine
a positive answer they will tail-call a general-purpose stub.

The general-purpose stub sets up a stub frame, tries to consult a
[SubtypeTestCache] and bails out to runtime if this was unsuccessful.

This CL is just the the first, for ease of reviewing.  The actual
type-specialized type testing stubs will be generated in later CLs.

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

Change-Id: I174a11b3b812799f399a60af799144c2ba3c26ec
Reviewed-on: https://dart-review.googlesource.com/44787
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
2018-04-06 07:00:50 +00:00
Ryan Macnak 3989d09c95 [vm] Move writing snapshot magic value from embedder to VM.
Add Dart_IsSnapshot and Dart_IsKernel to the embedding API.

Change-Id: I7d4e1d145557e8f11dbc3c143767ad38b3615a4a
Reviewed-on: https://dart-review.googlesource.com/46360
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2018-03-19 17:47:55 +00:00
asiva 9884447cc5 Add a new API function to sniff a snapshot to determine if the
snapshot is a Dart2 snapshot or a Dart1 snapshot.
This will be used by the flutter engine to initialize itself
correctly based on the snapshot provided.

Change-Id: I06adaac74b350f96aa6ebb55887e4a81f09fbd14
Reviewed-on: https://dart-review.googlesource.com/41082
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2018-02-14 23:27:38 +00:00
Ryan Macnak d366f9619a [vm] Toward deterministic builds.
- Remove random build-id.
 - Replace build time in embedded version string with commit time.
 - Remove timestamps from Observatory tarball.
 - Zero-initialize skipped bytes in snapshot streams.
 - Fix uninitialized fields in PatchClass, Script and Library.
 - Disable (under flag) random identity hashes and concurrent GC.

Bug: https://github.com/dart-lang/sdk/issues/31427
Change-Id: I3e95de679c8372841cd27ca60df78d9b00ffbfe1
Reviewed-on: https://dart-review.googlesource.com/22901
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
2017-11-23 00:07:56 +00:00
Ryan Macnak cbb7cb360b [vm] Include the content of image pages into --print-snapshot-sizes-verbose.
E.g.,
             Cluster   Objs     Size Fraction Cumulative
    (RO)Instructions      0 11465312 0.500079 0.500079
        (RO)StackMap  97579  3525312 0.153763 0.653842
   (RO)CodeSourceMap  22358  1752087 0.076420 0.730262
   (RO)OneByteString  30427  1644273 0.071718 0.801980
          ObjectPool  27233  1077927 0.047016 0.848995
               Array  25995  1029434 0.044901 0.893896
            Function  36468   924984 0.040345 0.934241
                Code  35686   782093 0.034112 0.968353
               Class   4026   177417 0.007738 0.976091
           TypedData  33768   125511 0.005474 0.981566
                 ...

Change-Id: I9f1e45ce85df6a4509f6d9fb2c28b41157872941
Reviewed-on: https://dart-review.googlesource.com/20262
Reviewed-by: Siva Chandra <sivachandra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2017-11-11 00:19:18 +00:00
Ryan Macnak b7a509e98a [vm] Add --print-snapshot-sizes-verbose.
E.g.,
             Cluster     Size Fraction Cumulative
               Array  1079963 0.206635 0.206635
          ObjectPool  1063564 0.203497 0.410132
            Function   961383 0.183946 0.594079
                Code   802081 0.153466 0.747545
              ROData   379720 0.072654 0.820199
               Class   185324 0.035459 0.855658

Bug:
Change-Id: I948877963b467263d399fa14ef32eedace02d6a5
Reviewed-on: https://dart-review.googlesource.com/19840
Reviewed-by: Siva Chandra <sivachandra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2017-11-10 00:23:42 +00:00
Ryan Macnak 8ed836fd6d [vm] Factor out the image snapshot code.
Prep for aligning image pages.

Bug: https://github.com/dart-lang/sdk/issues/30978
Change-Id: I5abd5d73ac9fed427942218a827e144fc74593de
Reviewed-on: https://dart-review.googlesource.com/18121
Reviewed-by: Siva Annamalai <asiva@google.com>
2017-11-02 00:57:42 +00:00
Ryan Macnak a2695ad29b When deduplicating program metadata, try to use objects from the VM isolate.
Expands the mechanism that moves token streams to the VM isolate to include instructions and code metadata.

Allow the isolate snapshot to reference Instructions in the VM isolate.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2909403002 .
2017-09-01 13:26:29 -07:00
Zachary Anderson 6cd8a79078 VM: Re-format to use at most one newline between functions
R=asiva@google.com

Review-Url: https://codereview.chromium.org/2974233002 .
2017-07-13 08:08:37 -07:00
Ryan Macnak e3a07d3145 Resolve inconsistent treatment of stubs in kAppJIT snapshots in favor of writing stubs in the snapshot.
Remember Instructions offsets using the object id weak table. Fixes duplication of instruction objects in non-product kAppJIT snapshots. Also provides a good basis for referencing VM isolate Instructions from an isolate snapshot.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2859913002 .
2017-05-09 10:04:24 -07:00
Ryan Macnak 02c54a6aa6 Rename InstructionsReader to ImageReader for symmetry with ImageWriter.
R=asiva@google.com

Review-Url: https://codereview.chromium.org/2860883002 .
2017-05-04 09:59:33 -07:00
Ryan Macnak 17e43f284b Tree shaker:
- Don't remove entries from a library's dictionary while iterating over it.
 - Remove library prefixes from library dictionaries.
 - Compact library dictionaries after removing entries.
 - Track snapshot references in debug mode and give a backtrace when unencountering an unexpected object.
 - Verify removed libraries are not included in the snapshot by marking their top-level classes.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2823873003 .
2017-04-19 10:03:43 -07:00
Ryan Macnak 22eee804cd Do not rewrite the VM isolate's symbol table during AOT snapshots.
This has the effect of making every program generate the same VM isolate, allowing an embedder to load different programs into different isolates.

Verify the number of base objects in clustered snapshots.

Remove dead code leftover from core snapshots switching from saving scripts to saving token streams in the VM isolate.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2790243003 .
2017-04-06 13:22:25 -07:00
Vyacheslav Egorov ff9c17504a VM: Make Dart::FeaturesString respect isolate flags controlling asserts and type checks.
Before it simply looked at FLAG_enable_{asserts/type_checks}.

We allow disabling or enabling type checks / asserts for newly created isolates
through Dart_IsolateFlags even when they are enabled globally through
FLAG_enable_{asserts/type_checks} flags.

This change allows isolates to use app-jit snapshots trained with type checks /
asserts disabled as long as isolate itself has type check and asserts disabled,
independent of whether FLAG_enable_{asserts/type_checks} is set globally or not.

Additionally disable type checks and asserts on Kernel isolate even if flags
FLAG_enable_{asserts/type_checks} are set.

This change allows to train Kernel app-jit snapshot once and use it both for

$ dart --dfe=...

and for

$ dart --checked --dfe=...

configurations.

BUG=
R=rmacnak@google.com

Review-Url: https://codereview.chromium.org/2720123004 .
2017-02-28 21:05:29 +01:00
Ryan Macnak 8b217ec519 Rename references to "external pages" as "image pages" to avoid confusion with the kind of external memory associated with finalizers.
R=asiva@google.com

Review-Url: https://codereview.chromium.org/2654183002 .
2017-01-26 09:53:06 -08:00
Ryan Macnak b46af1e75f Refactor snapshots pieces to include a section for loading instructions into the heap of a regular isolate.
Progress toward allowing each isolate to load a different snapshot.

R=asiva@google.com

Review-Url: https://codereview.chromium.org/2622053002 .
2017-01-23 10:25:02 -08:00
Ryan Macnak dc426c8c52 Rename snapshot kind enum values (kAppWithJIT -> kAppJIT, kAppNoJIT -> kAppAOT).
R=fschneider@google.com

Review-Url: https://codereview.chromium.org/2580823003 .
2016-12-15 12:16:02 -08:00
Zachary Anderson a1bcf051d8 clang-format runtime/vm
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2481873005 .
2016-11-08 13:54:47 -08:00
Zachary Anderson 103881d01c Make header include guards great again
i.e. #ifndef VM_WHATEVER -> #ifndef RUNTIME_VM_WHATEVER

This lets us remove a hack from the PRESUBMIT.py script that existed
for reasons that are no longer valid, and sets us up to add some
presubmit checks for the GN build.

R=asiva@google.com, rmacnak@google.com

Review URL: https://codereview.chromium.org/2450713004 .
2016-10-26 00:26:03 -07:00
Ryan Macnak 83da4db9f9 Collect TokenStreams into the vm isolate snapshot instead of Scripts.
Fixes caching-JIT and codeless app snapshots.

After the move of the compile time constant cache from the object store to individual caches on each script, we started attempting to include const objects in the vm isolate instead of the regular isolate.

R=fschneider@google.com

Review URL: https://codereview.chromium.org/2140333002 .
2016-07-12 16:25:21 -07:00
Ryan Macnak d75699e863 Make core snapshots word-size portable again.
Flutter creates a single core snapshot (from x64) that is used by both sky_snapshot (x64) and the engine (arm).

R=asiva@google.com

Review URL: https://codereview.chromium.org/2132833002 .
2016-07-08 14:18:44 -07:00