Commit Graph

129 Commits

Author SHA1 Message Date
Alexander Markov 9af507e0f5 [vm] Auto-generate InstanceSize definitions for array objects in runtime_api
Previously, compiler::target::Foo::InstanceSize(intptr_t length)
definitions were hand-written and compiler::target::Foo::InstanceSize()
were often defined using the size of UntaggedFoo for array-like objects.
This results in an unnecessary code duplication and discrepancy
between Foo::InstanceSize() which returns 0 and
compiler::target::Foo::InstanceSize() which returns size of the header.

This change adds ARRAY_SIZEOF variant to runtime_offsets_list.h
and switches array-like objects to auto-generated InstanceSize methods.

Also, this change strengthens assertions around host and target
values of InstanceSize() and NextFieldOffset() being the same
unless DART_PRECOMPILER is defined (which may do cross-compilation).

Stronger assertions flushed out a few discrepancies between
runtime_api.h and object.h, which are also fixed in this change.

TEST=ci

Change-Id: I9f67c6a71b9300af5e656fdc70f6a3e341c1d029
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196345
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2021-04-22 18:21:16 +00:00
Ryan Macnak 7e1d1963e5 [vm] Switch TypeArguments to compressed pointers.
TEST=ci
Change-Id: Ic3162ef1558fb803ab68749f1f1a4d820645ec7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/194017
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2021-04-21 00:06:58 +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 a6ffc74a4a [vm] Switch most Instances whose layout is determined in C++ to compressed pointers.
Instances whose layout must agree with a layout determined by Dart code are not switched: Array, GrowableObjectArray, Closure, LinkedHashMap.

TEST=ci
Change-Id: I19baf6473a29dd14f84aa1e087eee16b0e6e9d77
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193442
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2021-04-05 17:43:16 +00:00
Ryan Macnak 19e5899a02 [vm] Switch most non-Instances to compressed pointers.
The following are not compressed: Code, ObjectPool, Context, CallSiteData and subclasses.

Code::instructions_ is uncompressible because the VM doesn't control the address of Instructions when they are loaded via dynamic library.

Loads from the ObjectPool are a frequent occurrence in generated code, and shrinking ObjectPool entries would be offset by longer code sequences to decompress them. Also, some ObjectPool entries contain uncompressible pointers to C functions.

Context is not compressed based on reports from earlier work on compressed pointers that compressing them is disproporately bad for performance. The earlier work used a different, more-expensive compression scheme, so we should reinvestigate this.

CallSiteData et al. are on the hot path for unoptimized code but make up a comparatively small portion of the heap size.

TEST=ci
Change-Id: I9a425fa4e12113c9fd0b51999525d32a7e589a90
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/190600
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2021-03-18 22:52:04 +00:00
Martin Kustermann df439941e4 [vm/compiler] Change various allocation fast paths to check for --use-slow-path and --no-inline-alloc
This will allow future tests to force allocations to go to runtime. This
will be used to test deoptimization on allocation slow paths.

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

TEST=Existing test suite.

Change-Id: I0d552c2b313147ce08c5fbb22761a400388abe7b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191043
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2021-03-17 14:49:42 +00:00
Vyacheslav Egorov d42de4ed06 [vm] Crash on impossible GDT null errors
This CL adds code to detect situations when we hit
null error through GDT call with non-null receiver.

We achieve this by making receiver's cid part of the
GDT calling convention and checking this cid
in runtime entry responsible for throwing the null
error.

This CL is an attempt to narrow down b/179632636
and collapse various impossible crash reports
into a single native crash cluster by crashing VM
instead of throwing a null error.

TEST=tested manually

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try
Change-Id: If2ed4646c4c0f403016266e4e83e296a7b234cb5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/191141
Auto-Submit: Vyacheslav Egorov <vegorov@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-03-15 15:35:10 +00:00
Ryan Macnak 8db0a975c1 [vm] Allow garbage in the upper-half of compressed Smis.
Allows removing a branch when decompressing pointers and removing fixup sign-extension after Smi ops that use 32-bit ops to detect overflow. Increases the code size of indexed and stores for some widths due to addressing mode limitations.

TEST=ci
Change-Id: Ia48353cccbbc586dd0d2e055a843c65e37c63a30
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185660
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2021-03-11 19:39:01 +00:00
Alexander Markov ddfc98337b Reland "[vm/aot] Avoid using most Code objects in stack traces with --dwarf-stack-traces"
This is a reland of b6dc4dad4d

TEST=ci

Original change's description:
> [vm/aot] Avoid using most Code objects in stack traces with --dwarf-stack-traces
>
> The following changes are done in preparation for the removal of Code
> objects in AOT with --dwarf-stack-traces:
>
> * Stack trace objects are extended to hold uword PCs (which may not
>   fit into Smi range).
>
> * Scanning stack frames in GC (StackFrame::VisitObjectPointers)
>   now avoids using Code objects.
>   In order to find CompressedStackMaps it now calls
>   ReversePc::FindCompressedStackMaps.
>
> * Singleton Code object (StubCode::UnknownDartCode()) is prepared as
>   a replacement for Code objects in stack traces. It has
>   PayloadStart() == 0 and Size() == kUwordMax so it includes
>   arbitrary PCs.
>
> * In --dwarf-stack-traces mode, most Code objects obtained from stack
>   frames are replaced with StubCode::UnknownDartCode().
>   This simulates future behavior of ReversePc::Lookup when Code objects
>   will be removed.
>
> Issue: https://github.com/dart-lang/sdk/issues/44852
> Change-Id: I7cec7b8b9396c9cfeca3c256a412ba4e82a7e0c4
> TEST=ci
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182720
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Tess Strickland <sstrickl@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

Change-Id: Ia2fc4672a085cd963b7fc103369851df3603590c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/186202
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2021-02-22 10:46:28 +00:00
Ryan Macnak d0707f6695 [vm, compiler] Remove one branch from the array allocation stubs.
TEST=ci
Change-Id: Id95988ff233af9a754d419cd5be8750b3af31315
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185700
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-02-19 22:08:15 +00:00
Ryan Macnak 109d963bf9 [vm] Use 31-bit Smis in compressed pointer mode.
The range of Smis must be reduced so that pointer compression is not lossy.

Smis are kept in sign-extended form. In the future, we might track down all places that perform Smi comparisons or otherwise assume sign-extension. Allowing garbage in the upper half would make it safe to unconditionally add the heap base during pointer decompression.

Based on cf78da8a48.

TEST=ci
Change-Id: If8c76da3166c170618e5b3f3991353bab5c84e6f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/181760
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2021-02-18 20:40:20 +00:00
Alexander Markov fde0ed2e93 Revert "[vm/aot] Avoid using most Code objects in stack traces with --dwarf-stack-traces"
This reverts commit b6dc4dad4d.

Reason for revert: broke package:vm_snapshot_analysis in Flutter
(https://github.com/flutter/flutter/issues/76313).

Original change's description:
> [vm/aot] Avoid using most Code objects in stack traces with --dwarf-stack-traces
>
> The following changes are done in preparation for the removal of Code
> objects in AOT with --dwarf-stack-traces:
>
> * Stack trace objects are extended to hold uword PCs (which may not
>   fit into Smi range).
>
> * Scanning stack frames in GC (StackFrame::VisitObjectPointers)
>   now avoids using Code objects.
>   In order to find CompressedStackMaps it now calls
>   ReversePc::FindCompressedStackMaps.
>
> * Singleton Code object (StubCode::UnknownDartCode()) is prepared as
>   a replacement for Code objects in stack traces. It has
>   PayloadStart() == 0 and Size() == kUwordMax so it includes
>   arbitrary PCs.
>
> * In --dwarf-stack-traces mode, most Code objects obtained from stack
>   frames are replaced with StubCode::UnknownDartCode().
>   This simulates future behavior of ReversePc::Lookup when Code objects
>   will be removed.
>
> Issue: https://github.com/dart-lang/sdk/issues/44852
> Change-Id: I7cec7b8b9396c9cfeca3c256a412ba4e82a7e0c4
> TEST=ci
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182720
> Commit-Queue: Alexander Markov <alexmarkov@google.com>
> Reviewed-by: Tess Strickland <sstrickl@google.com>
> Reviewed-by: Martin Kustermann <kustermann@google.com>

Issue: https://github.com/dart-lang/sdk/issues/44852
Change-Id: I6f66171eecf1133363a7ce56193e782e43a20baf
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/185488
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2021-02-18 18:04:29 +00:00
Alexander Markov b6dc4dad4d [vm/aot] Avoid using most Code objects in stack traces with --dwarf-stack-traces
The following changes are done in preparation for the removal of Code
objects in AOT with --dwarf-stack-traces:

* Stack trace objects are extended to hold uword PCs (which may not
  fit into Smi range).

* Scanning stack frames in GC (StackFrame::VisitObjectPointers)
  now avoids using Code objects.
  In order to find CompressedStackMaps it now calls
  ReversePc::FindCompressedStackMaps.

* Singleton Code object (StubCode::UnknownDartCode()) is prepared as
  a replacement for Code objects in stack traces. It has
  PayloadStart() == 0 and Size() == kUwordMax so it includes
  arbitrary PCs.

* In --dwarf-stack-traces mode, most Code objects obtained from stack
  frames are replaced with StubCode::UnknownDartCode().
  This simulates future behavior of ReversePc::Lookup when Code objects
  will be removed.

Issue: https://github.com/dart-lang/sdk/issues/44852
Change-Id: I7cec7b8b9396c9cfeca3c256a412ba4e82a7e0c4
TEST=ci
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182720
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-02-17 20:12:32 +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
Daco Harkes 3e7cda8a4e [vm/ffi] Support passing structs by value
This CL adds passing structs by value in FFI trampolines.
Nested structs and inline arrays are future work.
C defines passing empty structs as undefined behavior, so that is not
supported in this CL.

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

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

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

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

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

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

Change-Id: I474d3a4ee1faadbe767ddadd1b696e24d8dc364c
Cq-Include-Trybots: luci.dart.try:dart-sdk-linux-try,dart-sdk-mac-try,dart-sdk-win-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-mac-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-nnbd-mac-release-x64-try,vm-kernel-nnbd-win-debug-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,vm-kernel-msan-linux-release-x64-try,vm-kernel-precomp-msan-linux-release-x64-try,vm-kernel-precomp-android-release-arm_x64-try,analyzer-analysis-server-linux-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140290
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-14 16:22:48 +00:00
Tess Strickland 57b54b00e1 [vm] Unify type testing stub testing framework.
In particular, make it so that the type testing stub testing
framework can use the same indirect stub call generation as
the flow graph compiler. This avoids having to change generation
in two places if we later update how indirect calls are generated.

Other changes:

* Generate a register mask of modified registers instead of a boolean
  for more precise reporting of what was modified.

* Add a STCInternalRegs struct, like TTSInternalRegs, which exposes
  the registers not preserved by the subtype test cache stubs.

* Be more precise in the TypeTestABI about which registers are preserved
  on successful checks (namely, the inputs provided by AssertAssignable
  and InstanceOf) and which may not be, and add the TTS and STC internal
  registers to the non-preserved list.

TEST=Ran modified test on trybots for each supported architecture.

Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-release-simarm64-try,vm-kernel-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-ia32-try
Change-Id: I58711213bc54572ea7f1e6525707fd193a000235
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173721
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2020-12-11 15:35:48 +00:00
Vyacheslav Egorov 5f490fabf7 [vm/compiler] Track LR state in ARM/ARM64 backends
Assembler now always knows whether LR contains return address
or can be safely cloberred.

TEST=tested through normal test suite

Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-ffi-android-release-arm64-try,vm-ffi-android-release-arm-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-android-release-arm64-try
Change-Id: I0b436509389cfd29ee413fd28930fb2d6b07616e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174468
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-12-10 15:51:27 +00:00
Daco Harkes 4adebc6d2a [vm] remove unecessary store of x18 to Thread
Related issue: https://github.com/dart-lang/sdk/issues/44435

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

Change-Id: Ibea3662ba2ef563702288b7a52f816df3217aa41
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/175367
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2020-12-09 20:08:00 +00:00
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
Vyacheslav Egorov a2acd59d73 [vm/ffi] Fix LR clobber in JumpToFrame stub on ARM
Both ARM and ARM64 variants did not account for the
fact that TransitionNativeToGenerated will clobber
LR on slow path.

TEST=tests/ffi/regress_jump_to_frame_test.dart

Cq-Include-Trybots: luci.dart.try:vm-ffi-android-release-arm-try,vm-ffi-android-release-arm64-try,vm-kernel-linux-release-simarm64-try,vm-kernel-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try
Change-Id: I40d48b720b2a7f31ff20903a887295ab2034662c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/173962
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-11-27 09:11:49 +00:00
Tess Strickland 4f73b3374b [vm] Add type slot to SubtypeTestCache.
This CL extends SubtypeTestCache entries with an additional slot that
contains the type being checked, to allow for future uses where
different runtime types can flow through a single checkpoint. This
change is separated from those future uses to determine the impact of
these changes only.

Thus, most SubtypeTestCache checks require the type as an additional
argument, and now the destination type register in TypeTestABI is now
untouched in SubtypeTestCache checks. Since there are currently no plans
for a dynamic InstanceOf test, the one argument SubtypeTestCache is left
unchanged.

Until we add cases in later CLs where the type can differ at the same
AssertAssignable instruction, we could check the type last since it is
currently guaranteed to be the same each time. However, we instead check
it after the instance, which is when it should be checked once we have
AssertAssignable instructions with types only known at runtime.  This
avoids having to change it later, but also ensures the measured impact
of these changes can be compared to the impact of later changes.

In addition, this CL also unifies most of the code used by
GenerateInstanceOf (and also GenerateAssertAssignable via
GenerateInlineInstanceof on IA32). This is possible since register use
changes in the helper functions has eliminated the need to push the
instantiator and function type argument registers from TypeTestABI on
non-X64 architectures. By unifying these methods, we ensure that all
architectures appropriately set TypeTestABI::kDstTypeReg when necessary.

TEST=Existing tests on all architectures, change in object_test.cc.

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

This CL also:

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

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

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

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

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

TEST=Run on trybots of all architectures.

Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-nnbd-linux-debug-simarm_x64-try,vm-kernel-precomp-nnbd-linux-debug-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try
Change-Id: Ia930613e96db4d1ab324c5a355dca8994d2a77f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/172160
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-11-17 15:09:47 +00:00
Tess Strickland cd7d31950e [vm/compiler] Perform cleanups in subtype test cache stubs.
This CL adds the result register used for subtype test cache stubs to
TypeTestABI. This avoids the hardcoding of the register per-architecture
and allows GenerateCallSubtypeTestStub to be unified into a single
implementation for non-IA32 architectures.

Since the register arguments to GenerateCallSubtypeTestStub were always
either kNoRegister or the same TypeTestABI register across all calls,
those arguments are removed and the appropriate TypeTestABI registers
are considered hardcoded input registers and either implicitly (for
non-IA32) or explicitly (via the stack on IA32) passed to the subtype
tests cache stub being called.

TEST=Tested using our existing test cases, running debug (if available)
or release (if no debug available) trybots for all architectures.

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

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

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

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

Change-Id: Ia12c1efec0871a2fd7acc6db75f255853af52d0f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/168993
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-10-26 18:55:26 +00:00
Martin Kustermann dd3642b211 [vm] Ensure simarm/simarm64 restore fixed registers on exceptional control flow
A follow-up CL will add changes which makes us trigger this bug.

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

Change-Id: I22dbe9199b47bfa7eff48c01ea163b318e9f2e37
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/169082
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-10-26 16:51:46 +00:00
Regis Crelier 037cff952c [VM/assembler] Use correct operand size in FieldAddress on arm64.
This change prevents the scaled addressing mode to be wrongly applied by the assembler.

Let's illustrate with an example:

__ ldr(R1, FieldAddress(R1, target::Type::nullability_offset()), kUnsignedByte);

Let's assume that target::Type::nullability_offset() == 57 (it is currently 61, but will be 57 in a forthcoming CL).
FieldAddress substracts 1 and builds an Address with offset 56.
The default operand size passed to Address is kDoubleWord, i.e. a scaling factor of 3.
Because 56 == (56 >> 3) << 3, the scaled addressing mode is chosen with a scaled offset of 7, which would be correct for a kDoubleWord access, but not for a kUnsignedByte access.

It is important to specify the same operand size in the instruction as in FieldAddress:
__ ldr(R1, FieldAddress(R1, target::Type::nullability_offset(), kByte), kUnsignedByte);

Change-Id: I46cf2b6ac103b2acec723189c88e211567b795af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/167900
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Régis Crelier <regis@google.com>
2020-10-19 18:54:37 +00:00
Daco Harkes a80f9d7da8 [vm/ffi] Stop using R8 in FFI calls, callbacks and stubs on arm64
R8 is used for passing the address when returning structs by value
in the native ABI.

Separated out from https://dart-review.googlesource.com/c/sdk/+/140290

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

Change-Id: I35187d35b8cd1b9fe6852faf0cd02a5f51e9f358
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-linux-debug-ia32-try,vm-kernel-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163204
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
2020-09-17 21:08:13 +00:00
Alexander Markov 13aaaae1b2 [vm/compiler] Introduce AllocateTypedData IL instruction
This is the first step towards optimizing typed data array allocations,
which is useful for e.g. package:vector_math.

Opaque call to a typed data factory constructor is replaced with IL
instruction which doesn't have side-effects and doesn't prevent
other optimizations (e.g. load forwarding) from happening.

Asm intrinsics for typed data factories are replaced with stubs.

Issue: https://github.com/dart-lang/sdk/issues/43228
Change-Id: Icc7d4863f2f94ea5d8bb4620d041f7b6fe664098
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/161840
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-09-16 03:16:42 +00:00
Vyacheslav Egorov 62354c1540 [vm/arm64] Refactor leaf runtime call sequence.
Leaf runtime calls a silently clobbering R23 and R25 registers, which
causes bugs when these calls happen from write barriers (which are not
expected to clobber anything outside of R25).

We introduce a special helper class to handle saving and restoring
necessary registers.

The bug originally reported by Joe Lin <zuojian.lzj@alibaba-inc.com>
who proposed a fix[1]. This CL builds on top of that fix and tries to
make it more safe by forcing users to use a more strict API.

[1] https://dart-review.googlesource.com/c/sdk/+/162300

TEST=vm/dart/write_barrier_register_clobber_test

Change-Id: I93e0a13a3c4c38ad28210b35750a66e615e3e44a
Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/162191
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
2020-09-11 07:37:51 +00:00
Martin Kustermann f6906f856e [vm/compiler] Add type testing stubs to allow TypeParameter types to be called indirectly
Right now AssertAssignable will not call the TTS of a TypeParameter but
instead load the value for the type parameter inline and then call it's
TTS.

To prepare for future changes where we want to call TTS of an arbitrary
type object, we need to be able to install a functioning TTS on
TypeParameter, which this CL does.

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

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

--use_table_dispatch still not yet supported.

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

Bug: https://github.com/dart-lang/sdk/issues/41974
Change-Id: I51052ebc7b4968b554897d1710135a6c41821302
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/157820
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2020-08-12 17:23:14 +00:00
Martin Kustermann 61a944ca6a [vm/compiler] Align BoxInt64 implementation on x64 with arm/arm64 by calling a shared slow path
Change-Id: I3dcdc922e00898e49bf00b985cb2af747005d35f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142623
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-07-27 19:22:03 +00:00
Tess Strickland 31d4511ad6 [vm/compiler] Fix handling of runtime offsets.
Before this, we had to use PRECOMP_NO_CHECK() for any entries that
involved field offsets that came after NOT_IN_PRECOMPILED() fields,
because the offsets would differ between JIT and AOT. That removed
the check in dart.cc that the offsets match, but that just meant
that precompiled code that used these offsets were wrong.

One possible workaround is to just lift any field definitions whose
offset might be used in precompiled code before any NOT_IN_PRECOMPILED()
defined fields, but this means otherwise unnecessary changes in the
Layout classes.

Instead, just fix the runtime offset generation/retrieval by splitting
the list of offsets into two parts: offsets common to all modes and
offsets only valid in JIT mode.  While this complicates the code that
generates and imports these offsets, it ensures that our code generation
actually uses the right offsets for the target mode.

In addition, by doing this split we can add checks for uses of JIT-only
offsets when in precompiled mode. Adding these checks found some uses of
JIT-only field offsets in code compiled in precompiled mode.  (These
uses may have been benign if the stubs that included the uses were never
called in the precompiled runtime, but now there's explicitly a check
for precompiled mode around these uses.)

Also remove the unused ARRAY_STRUCTFIELD type from offset lists.

Change-Id: I083ab5997d3a5245b5f1487b614b62faee47d405
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155780
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-07-27 13:44:19 +00:00
Ryan Macnak c5a94db091 [vm] Initial implementation of deferred loading.
(Assignment of libraries to loading units is already done in the kernel generation step.)

After compiling and before serializing, we walk the program and for each Code we assign its Instructions, CodeSourceMap and CompressedStackMap to the loading unit of that Code's defining library. Deduplication may cause Instructions, CodeSourceMaps and CompressedStackMaps to belong to more than one loading unit; in this case the objects are assigned to the root loading unit. Later they can be more precisely assigned to the dominating loading unit.

All objects except some Instructions, CodeSourceMaps and CompressedStackMaps belong to the root loading unit's snapshot. This snapshot is written like an unsplit snapshot, except that when serializing Code, we will write a reference to a stub or null when the Code's Instructions, CodeSourceMap or CompressedStackMap belongs to a non-root loading unit. The snapshots of non-root loading units contain these deferred objects and references to the corresponding Code objects to patch. The types of objects we defer (Instructions, CodeSourceMaps and CompressedStackMaps) usually represent 70+% of the snapshot size.

Bare instructions mode must be disabled when splitting because we cannot have PC-relative calls between loading units. Later we can re-enable this for calls within loading units.

Broken: Compactor probably crashes we can now have an unbounded number of image pages and the compactor assumes a fixed number.

Embedder's guide:

At compile-time, gen_snapshot should be passed --loading_unit_manifest with a path, which will enable splitting and output a mapping from loading unit ids to snapshot output paths.

At runtime, sometime during isolate startup, an embedder should call Dart_SetDeferredLoadHandler, probably near an existing call to Dart_SetLibraryTagHandler. The callback is given a loading unit id, and should eventually call Dart_DeferredLoadComplete[Error].

Bug: https://github.com/dart-lang/sdk/issues/41974
Change-Id: Ib597eb87c8cd634416d5ee1f00629c5550aebb00
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152427
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-07-17 19:29:47 +00:00
Alexander Markov 06a8cc8dea [vm/nnbd] Use separate runtime entry for throwing _CastError in null check operator
Previously, NullError runtime entry was used both to throw
NoSuchMethodError and _CastError. _CastError was used if selector is
null. However, with --dwarf-stack-traces CodeSourceMap is not preserved
and selector is not available, so wrong exception type was thrown.

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

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

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

Change-Id: I4f2b34ad2b161459491de60d8737bb4f87117336
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153040
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2020-07-01 20:52:34 +00:00
Ryan Macnak ea87c9b01a [vm] Remove the Stop stub and runtime entry.
Assembler::Stop("message") used to pass a C string pointer to the runtime to print. This mechanism did not account for relocation needed by AppJIT and AppAOT, and now only a trap instruction is used.

Change-Id: I70f3374abb9f9e649027f7417c66d7079c56ff63
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/152582
Reviewed-by: Régis Crelier <regis@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2020-06-25 23:22:02 +00:00
Martin Kustermann 142e15c2af [vm/compiler] Use unboxed index/length for GenericCheckBoundInstr on 64-bit architectures
flutter-release:

  * flutter_app_so_size: -0.47%
  * flutter_app_so_brotli_size: -0.48%
  * flutter_app_so_gzip_size: -0.57%

flutter-release-sizeopt:

  * flutter_app_so_size: -0.45%
  * flutter_app_so_brotli_size: -0.64%
  * flutter_app_so_gzip_size: -0.65%

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

Change-Id: If63b71e5d52f6ddb55fe05668a6480eb00a13303
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150300
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-06-22 19:55:36 +00:00
Daco Harkes 6544c69e23 [vm/ffi] Convert Objects to Dart_Handles in FFI calls
This includes support for calling Dart_PropagateError in native code
when doing FFI calls, and catching uncaught exceptions with Dart_IsError
when doing FFI callbacks.

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

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

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

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

Change-Id: Idfd7ff69132fb29cc730931a4113d914d4437396
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-mac-debug-x64-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-kernel-nnbd-linux-debug-x64-try,analyzer-nnbd-linux-release-try,front-end-nnbd-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/145591
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-06-12 11:14:22 +00:00
Martin Kustermann a2b5373eaa [vm/concurrency] Avoid stopping mutators when updating subtype test cache
To avoid stopping all mutators when updating subtype test caches, we
ensure that any updates to the subtype test cache will be visible in a
consistent way to mutators by adding a store-release barrier when
updating the backing array of the STC.

Since STCs are always grown by allocating a new array with size+1, there
is no need to actually add barriers when accessing the individual
entries of the backing store.

To prevent multiple writers creating STCs and patching the pool or
updating a STC we add a mutex.

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

Change-Id: Ic705619fe16772565ac11438fd15d3977cbb49c0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/149164
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2020-05-29 04:47:22 +00:00
Martin Kustermann 4cf584d4fe [vm/concurrency] Move locks up from Isolate to IsolateGroup
In --enable-isolate group is

  * turned off, then we have 1<->1 mapping between isolate and isolate
    group, so moving the locks should have no impact

  * turned on, then we have N<->1 mapping between isolates and isolate
    group, mutators need to use the same locks to guarantee exclusive
    access (e.g. to symbol table, type canonicalization, type arguments
    canonicalization, ...)

This is a follow-up to share the program structure in AOT mode across
multiple isoltes.

In order to move the existing `Isolate::type_canonicalization_mutex_` to
`IsolateGroup` (and thereby make all mutators use the same lock), we need
to remove the `RunWithMutatorsStopped()` usage in the runtime entry.

  => Without this it can lead to deadlocks.

In order to remove usage of `RunWithMutatorsStopped()` we will change
access to the cached type arguments array to use load-acquire barriers
in generated code and store-release barriers in runtime code.

A nice side effect is that it reduces `sizeof(dart::Isolate)`.

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

Change-Id: Ifd42691524fe41ffe8bb4e2623c5b8c1151de973
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148539
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-05-27 17:04:30 +00:00
Ryan Macnak 2fa4d3e4d8 [vm, gc] Account for AllocateArray or CloneContext returning objects that have already been added to the remembered set.
Bug: b/156940113
Change-Id: Id212f9826b83981346ea4fbb1ef80a115e831a10
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148506
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-05-19 17:47:11 +00:00
Ryan Macnak 6b91f92154 [vm] Move megamorphic miss handling into the megamorphic call stub.
This removes the only stub code with a function owner.

Change-Id: I629eb3a1b231430afaf0a2777032bba8eaddd2aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/148124
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2020-05-15 20:28:21 +00:00
Ryan Macnak 5241586246 [vm, gc] Rename HeapPage to OldPage for symmetry.
Change-Id: I282eaf894fad17a731dbfc76873468b04117cebd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/147324
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2020-05-08 18:28:06 +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
Martin Kustermann bc59a40918 [vm/compiler] Use PC-relative calls in AssertAssignable when calling TTS
Additionally the TTS itself will also use pc-relative tail-call to the
slow path.

This reduces AssertAssignable by 1 instruction and generated
type testing stubs by 2 instructions.

Flutter gallery total size:

  armv8: -0.3%
  armv7: -0.27%

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

Change-Id: Ib29ff9afd1df4034c8fa47f66c80c22e226c0979
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142988
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Aske Simon Christensen <askesc@google.com>
2020-04-18 20:27:38 +00:00
Vyacheslav Egorov beb7114861 [vm/compiler] Add check to prevent inclusion of compiler headers into AOT runtime
This relands commit b0a71d364c

Cq-Include-Trybots: dart/try:vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-linux-release-simarm-try,vm-kernel-precomp-linux-release-x64-try
Change-Id: I1d32e5d0d44f4e422d188643b548ed81859f7d74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143807
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2020-04-17 13:11:08 +00:00
Alexander Aprelev c7861f309f Revert "[vm/compiler] Add check to prevent inclusion of compiler headers into AOT runtime"
This reverts commit b0a71d364c as it broke precomp builds.

Change-Id: Ieb776739b8d3e9ac74794e05fc20a793625e5f09
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143865
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-04-16 23:51:09 +00:00
Vyacheslav Egorov b0a71d364c [vm/compiler] Add check to prevent inclusion of compiler headers into AOT runtime
#if defined(DART_PRECOMPILED_RUNTIME)
  #error "AOT runtime should not use compiler sources (including header files)"
  #endif  // defined(DART_PRECOMPILED_RUNTIME)

Remove #if defined(DART_PRECOMPILED_RUNTIME) from most compiler sources.

Change-Id: Id175c83fdbea38d9d5e1371ff433e3888f2afe8a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/143523
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-04-16 22:59:03 +00:00
Vyacheslav Egorov a41a1dc917 [vm/compiler] Split compiler sources out of normal VM sources.
Make them form its own source set (libdart_compiler) and completely exclude
them from AOT runtime targets.

Previously we had some inconsistencies, with some files were using
DART_PRECOMPILED_RUNTIME to fully or partially exclude either contents
from their headers or from implementation, while other files did nothing
and relied on linker to throw their contents away.

This change tries to address this inconsistency.

A follow up change would include a check in most compiler headers which
would prohibit to use them while building AOT runtime.

Change-Id: Ief11b11cbc518b301d3e93fce80580a31bbad151
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142993
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2020-04-16 22:59:03 +00:00