Commit graph

487 commits

Author SHA1 Message Date
Vyacheslav Egorov 56ad16f4de [vm] Make VM strict about min required Mac OS X version.
Refuse to initialize VM if current Mac OS X version is below
MAC_OS_X_VERSION_MIN_REQUIRED, which was configured in build
time through mac_sdk_min GN argument.

TEST=tested manually by changing return value of MacOSXVersion

Cq-Include-Trybots: luci.dart.try:dart-sdk-mac-arm64-try
Bug: https://github.com/flutter/flutter/issues/121739
Change-Id: I9d913516077dbb196e8d6ebd7fe9f3914de7c748
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286932
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2023-03-08 09:08:39 +00:00
Ryan Macnak 63e6041ca9 [vm] Update to variadic FATAL.
TEST=ci
Change-Id: Ic6bc784605e10760bb28ea6df34242336a33b4d0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286947
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-03-06 22:06:59 +00:00
Oleh Prypin 2e01df50e9 Revert "[VM] Begin supporting Perfetto file recorder"
This reverts commit 7424295ce9.

Reason for revert: Causes VM crash in internal tests - b/271081079

Original change's description:
> [VM] Begin supporting Perfetto file recorder
>
> This CL adds the `TimelineEventPerfettoFileRecorder` class, which is a
> timeline recorder that writes a trace to file in Perfetto's proto
> format. This CL supports the recording of all types of timeline events
> except flow events. Support for flow events will be added in a future
> CL.
>
> TEST=Recorded traces with the Perfetto file recorder and explored them
> in Perfetto's trace viewer, CI
>
> Change-Id: Iaa2051e536589a473c5e15f9de9bb9c251f13d38
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278942
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Derek Xu <derekx@google.com>

Change-Id: I1c4b0b78be3748b525b82ea66079dd95d412d82e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285906
Auto-Submit: Oleh Prypin <oprypin@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-02-28 12:41:00 +00:00
Derek Xu 7424295ce9 [VM] Begin supporting Perfetto file recorder
This CL adds the `TimelineEventPerfettoFileRecorder` class, which is a
timeline recorder that writes a trace to file in Perfetto's proto
format. This CL supports the recording of all types of timeline events
except flow events. Support for flow events will be added in a future
CL.

TEST=Recorded traces with the Perfetto file recorder and explored them
in Perfetto's trace viewer, CI

Change-Id: Iaa2051e536589a473c5e15f9de9bb9c251f13d38
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278942
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-02-27 18:37:48 +00:00
Ryan Macnak f56c45eb37 [vm] Speed up JSON encoding.
TEST=ci
Change-Id: I8bfe00472f3a5e4e6680de631072cea0dacc3f55
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/283980
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-02-21 18:58:42 +00:00
Josh Soref 01b28894e7 Spelling pkg dev compiler
Closes https://github.com/dart-lang/sdk/pull/50861

GitOrigin-RevId: 71005e6f5bf5a151cb5c1aefb6a2a300fc40f592
Change-Id: Iadfafb5787a62e9a379437f6a3763d31f99ba7c6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/277743
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-01-26 09:12:41 +00:00
Josh Soref ef42a0b110 Spelling pkg analyzer lib
Closes https://github.com/dart-lang/sdk/pull/50860

GitOrigin-RevId: b27066c37f93c8c6d1123d6ebd6a4c0afcf59844
Change-Id: I15fa4aea1dad45daf168e34d1c4450320ec9b40a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/277742
Commit-Queue: Alexander Thomas <athom@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
2023-01-25 14:08:27 +00:00
Josh Soref f7a2ea5e06 Spelling
Closes https://github.com/dart-lang/sdk/pull/50922

GitOrigin-RevId: 58fd7cfd5ef470a65a52ea28e0407244d853c917
Change-Id: I2e5a5ed991cb05270170a18b8f0169daa9eabdb7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278537
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-01-24 18:00:25 +00:00
Josh Soref 84e3c8b50f Spelling tests
Closes https://github.com/dart-lang/sdk/pull/50920

GitOrigin-RevId: fa87531bd0f52b69485c9d02ff9e44a4a29c6a91
Change-Id: I0ae8574a5b77087895e004079f221201bb550cf3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278535
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-01-19 16:24:29 +00:00
Ryan Macnak 8a37b70a53 [vm, compiler] More consistently support large load/store offsets.
TEST=ci
Change-Id: I7691808679c57c6f16f3859641cf52b9e606e304
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/275381
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-12-14 22:17:35 +00:00
Vyacheslav Egorov c704e11ee2 [vm/api] Introduce Dart_WriteHeapSnapshot API
Allows embedders to programmatically request heap snapshot from a
running isolate group instead of relying on a vm-service or hidden
internal Dart APIs

Additionally we allow to include snapshot writing functionality into
PRODUCT builds using DART_ENABLE_HEAP_SNAPSHOT_WRITER define.

TEST=vm/cc/DartAPI_WriteHeapSnapshot

Bug: b/259115846
Change-Id: Ic3ef76e5fb9adcf8f23a1959f5238742b64ecde2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273181
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2022-12-01 14:38:44 +00:00
Tess Strickland 4f925105cf [vm] Use a hash map for larger type argument instantiation caches.
Previously, the VM used a linear array to cache previous instantiations
of a type arguments object. Now once the cache hits a certain number
of occupied entries, the VM changes to using a hash-based approach.

The InstantiateTypeArguments stubs have not yet been updated to
traverse the hash-based cache, so once the cache has grown too large,
all attempts at instantiations, even those that are in the cache, go to
the runtime. Thus, until the stubs are updated, this is only an
improvement if the cost of traversing the linear cache dominates the
cost of making a runtime call. Our benchmarks see a ~40% performance
regression for hash-based caches of size 100 but a ~400% performance
improvement for hash-based caches of size 1000. Thus, we currently
split the difference and set the maximum size of linear caches to 500.

TEST=vm/cc/TypeArguments_Cache_ManyInstantiations

Bug: https://github.com/dart-lang/sdk/issues/48344
Change-Id: I7f1376943523bb5bcd8b175cfb1936779ea73d60
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-precomp-nnbd-linux-release-simarm_x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try,vm-kernel-precomp-nnbd-linux-debug-simriscv64-try,vm-kernel-precomp-tsan-linux-release-x64-try,vm-kernel-tsan-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/265325
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2022-11-28 15:00:20 +00:00
Ryan Macnak 28c4d87b34 [vm, gc] Extend alignment helpers to work with alignment offsets.
TEST=ci
Change-Id: I02bad1feba3a16360aa52414c94cdef81b158ed6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262000
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2022-10-06 00:50:45 +00:00
Tess Strickland b0c4ddf919 [pkg/dart2native] Avoid overwriting section contents in MachO files.
To create a Dart standalone executable on MacOS, we modify the
dartaotruntime executable to add the snapshot contents, and the
VM looks into the executable on disk to find the snapshot to load.

Previously, we did this by adding a new 64-bit segment load command
with a single section, where the section's file offset and size
describes the inserted snapshot. This meant the Mach-O header size increased by 152 bytes.

Originally, this wasn't an issue as there was plenty of padding, but
later clang updates removed most of this padding, and so writing the
new header actually overwrote the initial contents of the first section
in the file, which happens to be the __text section. In addition, since
the first section's offset was now declared to be within the header,
utilities that strictly validated the Mach-O format, like codesign,
would report errors.

This CL changes it so that we actually reserve space in the
dartaotruntime header using the -add_empty_section flag to the linker.
In addition, we change from using a segment load command to using a
(40 byte) note load command. This is because a segment load command
specifies that the contents should be loaded in memory, but we don't
use that loaded version. Instead, the VM reloads it from the executable
on disk so it can appropriately mmap the different parts of the
snapshot. A note section instead just declares a section of the
executable as arbitrary data that the owner can read from the file
and use as desired, which is semantically closer to our current usage.

This CL also adds a test to pkg/dartdev/test/commands/compile_test to
ensure that corrupting a random part of the snapshot in the executable
causes signature verification to fail.

This CL also reverts CL 256208, thus relanding the clang changes
starting from June that originally raised awareness of the issue by
greatly reduced the amount of padding after the load commands.

TEST=pkg/dartdev/test/commands/compile_test

Bug: https://github.com/dart-lang/sdk/issues/49783
Change-Id: Iee554d87b0eabaecd7a534ca4e4facfefbce6385
Cq-Include-Trybots: luci.dart.try:analyzer-mac-release-try,dart-sdk-mac-arm64-try,dart-sdk-mac-try,pkg-mac-release-arm64-try,pkg-mac-release-try,vm-kernel-precomp-mac-product-x64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/260108
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2022-09-29 08:32:47 +00:00
Ryan Macnak cba1a09e5c [vm, compiler] Inform MSan about parameters coming from FFI.
- Mark the outgoing arguments stack area as initialized.
 - Mark the trampoline's incoming parameter slots as initialized in case they are used as local handles.
 - Mark the outgoing register arguments as initialized.

TEST=msan
Bug: https://github.com/dart-lang/sdk/issues/42314
Bug: https://github.com/dart-lang/sdk/issues/49298
Bug: https://github.com/dart-lang/sdk/issues/49957
Change-Id: Ifa978e1b905a424ec9f64b89879cea6e82f70d12
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/259102
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-09-23 21:31:14 +00:00
Vyacheslav Egorov 83ab5d5ca3 [vm] Remove dynamic field unboxing in JIT
Instead apply the same approach as we do in AOT: unbox based on the
static type information. There are no TFA results available in JIT,
but we could still unbox fields when running in sound null-safety.

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-kernel-reload-linux-release-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-rollback-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-simarm64-try,vm-kernel-linux-debug-simriscv64-try,vm-kernel-precomp-linux-debug-simriscv64-try,vm-kernel-nnbd-linux-release-ia32-try,vm-kernel-nnbd-linux-debug-x64-try,vm-kernel-nnbd-linux-debug-ia32-try,vm-kernel-nnbd-linux-release-simarm-try,vm-kernel-nnbd-linux-release-simarm64-try
Change-Id: Ide2e78c6659261ef8d245a4586cf699ea0fbb459
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/256211
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2022-09-20 13:42:45 +00:00
Vyacheslav Egorov 4a4eedd860 [vm] Clean up ClassTable
* Merge ClassTable and SharedClassTable back together;
* Simplify handling of multiple arrays growing in sync;
* Refactor how reload deals with ClassTable.

The last change is the most important because it makes it
much easier to reason about the code. We move away from
copying bits and pieces of the class table and shared
class table into reload contexts.

Having two class table fields in the isolate group makes
it easier to reason about. One field contains program
class table (one modified by kernel loader and accessed
by various program structure cid lookups) and heap
walk class table (used by GC visitors). Normally these
two fields point to the same class table, but during
hot reload we temporary split them apart: original
class table is kept as a heap walk class table, while
program class table is replaced by a clone and updated
by reload.

If reload succeeds we drop original class table and
set program class table as heap walk one.

If reload fails we drop the program class table and
restore original one from heap walk table.

TEST=ci

Cq-Include-Trybots: luci.dart.try:vm-kernel-reload-linux-release-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-reload-rollback-linux-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-tsan-linux-release-x64-try,vm-kernel-tsan-linux-release-x64-try,vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-asan-linux-release-x64-try
Change-Id: I8b66259fcc474dea7dd2af063e4772df99be06c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/258361
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2022-09-10 15:12:35 +00:00
Vyacheslav Egorov afb34fb9e3 [vm] Fix kNumberOfReservedCpuRegisters on ARM64
Instead of using an integer literal use constexpr popcount
function instead.

The misalignment causes an incorrect generation of a call
to a shared write barrier stub for the last allocatable register
on ARM64.

Reported by Lin Zuojian <zuojian.lzj@alibaba-inc.com>

TEST=ci

Change-Id: I69ce32da958573be0ec8967e462f8a378a778a28
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/254401
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2022-08-10 18:04:09 +00:00
Tess Strickland 24683da915 [vm] Add OS and architecture to non-symbolic stack traces.
Examples of the new line added to non-symbolic stack traces:

os: linux arch: x64 comp: yes sim: no
(Running on linux-x64c)

os: macos arch: arm64 comp: no sim: yes
(Running on mac-simarm64)

This CL also abstracts out the separate hardcoded strings across
the codebase for host and target OS and architecture into
definitions in platform/globals.h to ensure that they stay
in sync across different uses.

TEST=vm/dart{,_2}/use_dwarf_stack_traces_flag

Issue: https://github.com/flutter/flutter/pull/101586
Change-Id: Ifdfea5138dd1003f561da0174e89aebc165bf9b0
Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-mac-product-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-simarm_x64-try,vm-kernel-precomp-win-release-x64-try,vm-kernel-precomp-nnbd-mac-release-arm64-try,vm-kernel-precomp-mac-release-simarm64-try,vm-ffi-android-release-arm-try,vm-ffi-android-release-arm64c-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/253283
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2022-08-05 11:53:37 +00:00
Kapandaria 7fa9a6776a [vm] Update bit algorithms in utils.cc
Closes https://github.com/dart-lang/sdk/pull/48942

GitOrigin-RevId: 484c201343c546abdfdc8669f87e844c26c0fd43
Change-Id: Ib918e0deca4cccbeef2cc6a17a84ec95a74e80f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243361
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2022-05-16 07:30:40 +00:00
Ryan Macnak 3c01efcbb0 Reland "[build] Fix Android build for ARM64 Mac."
Account for simarm_x64 in TargetCpuForArch.

TEST=local
Bug: https://github.com/dart-lang/sdk/issues/48792
Change-Id: I820cb49ee8925c50196cb2472266f9e248c9089d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243642
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-05-10 16:11:53 +00:00
Ryan Macnak 5f1bda06ee Revert "[build] Fix Android build for ARM64 Mac."
This reverts commit b50396740f.

Reason for revert: vm-kernel-precomp-linux-debug-simarm_x64

Original change's description:
> [build] Fix Android build for ARM64 Mac.
>
> TEST=local
> Bug: https://github.com/dart-lang/sdk/issues/48792
> Change-Id: Ia43dd46f90ef5f592e324bb889c20c221f69998a
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241102
> Reviewed-by: Daco Harkes <dacoharkes@google.com>
> Reviewed-by: William Hesse <whesse@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

TBR=whesse@google.com,rmacnak@google.com,dacoharkes@google.com

Change-Id: I0cfdb5653dff7675afdb005df0c37f7560b26ee3
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: https://github.com/dart-lang/sdk/issues/48792
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241860
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-04-20 23:13:29 +00:00
Ryan Macnak b50396740f [build] Fix Android build for ARM64 Mac.
TEST=local
Bug: https://github.com/dart-lang/sdk/issues/48792
Change-Id: Ia43dd46f90ef5f592e324bb889c20c221f69998a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241102
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: William Hesse <whesse@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-04-20 17:15:48 +00:00
Ryan Macnak 32715d1d5b [vm] Mark ELF libraries produced directly by the VM as not requiring an executable stack.
Even if the main program disables executable stacks, dlopen'ing a library that doesn't itself disable executable stack will switch the stack to executable. (Presumably in the name of compatability with GNU nested functions.)

Dart does not need executable stacks, and executable stacks are an additional attack surface.

TEST=readelf
Bug: b/229648756
Change-Id: Ia8c234ebc6178a26528d37b1359a10dd42039a9b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241540
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-04-19 18:51:47 +00:00
Ryan Macnak f76b6a8cc1 Reland "[vm] Add a timeline recorder that streams to a file."
Adjust TimelineEvent::PrintJSON to use JSONWriter for compatibility with PRODUCT mode.

TEST=ci
Change-Id: I694889c655719371364012b4324b7947d7b2d5e5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240911
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-04-19 00:56:46 +00:00
Ryan Macnak e8df2987c7 Revert "[vm] Add a timeline recorder that streams to a file."
This reverts commit 398ef5d693.

Reason for revert: Failures on Android and Fuchsia product builds

Original change's description:
> [vm] Add a timeline recorder that streams to a file.
>
> TEST=ci
> Change-Id: If527a7c7f5dfa11fe6572452e382779b76b16638
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241100
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

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

Change-Id: Iccbcc9084a6a4a7e530f3f53c0b6c0fd424a8cdd
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240910
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-04-14 20:11:15 +00:00
Ryan Macnak 398ef5d693 [vm] Add a timeline recorder that streams to a file.
TEST=ci
Change-Id: If527a7c7f5dfa11fe6572452e382779b76b16638
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241100
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-04-14 18:50:53 +00:00
Ryan Macnak f2d3051598 [vm] Some pieces for Windows ARM support.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/47824
Change-Id: Iaf401f4d25fc5bf171170728d4a5d3ae6ef17527
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/239369
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-03-30 19:01:33 +00:00
Tess Strickland cdb703859a [dart2native] Allow for signing of Windows standalone executables.
Instead of simply concatenating the dartaotruntime executable and the
ELF snapshot, we instead insert the ELF snapshot as a COFF section,
so the resulting PE file can be signed.

TEST=pkg/dartdev/test/commands/compile_test

Bug: https://github.com/dart-lang/sdk/issues/39106
Change-Id: Iaafb5833fcb9c69c0dd374b64769f22b8b9f53a2
Cq-Include-Trybots: luci.dart.try:pkg-win-release-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/236100
Reviewed-by: Aske Simon Christensen <askesc@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2022-03-24 10:08:01 +00:00
Vyacheslav Egorov 47ec77122a [vm] Improve crash reporting for gen_snapshot
* Use CompilerPass::GenerateCode in AOT to ensure we print
the graph if the code generation crashes.
* Enable Dart_DumpNativeStackTrace in gen_snapshot even in
PRODUCT builds.

Additionally enable disassembler in gen_snapshot even in
PRODUCT builds.

TEST=tested manually

Change-Id: I951d62ca07c7882fa1d8e765d4b5ffd26edd9456
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/233880
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2022-03-11 09:20:36 +00:00
Tess Strickland 6ef426d7df MacOS-Signable Compiled Dart Scripts
This CL implements a slightly altered compilation process for `dart
compile` on MacOS. Instead of the traditional approach of
concatenating a dart snapshot with the dart runtime, this new
implementation uses a new MachO segment to store the snapshot. Doing
so ensure users can properly sign the resulting binaries.

The dart runtime has also been updated to look for the snapshots in
this new segment.

There are new unit tests ensuring the dart runtime can correctly
identify MachO-formatted executables and an end-to-end test ensuring
`dart compile` produces code that has the new segment and produces
code that can be signed.

TEST=pkg/dartdev/test/commands/compile_test

Change-Id: Ibdce80455e02bc2b6fd345d80be8d75f989a9c28
Cq-Include-Trybots: luci.dart.try:analyzer-mac-release-try,dart-sdk-mac-arm64-try,dart-sdk-mac-try,pkg-mac-release-arm64-try,pkg-mac-release-try,vm-kernel-mac-debug-x64-try,vm-kernel-mac-product-x64-try,vm-kernel-mac-release-arm64-try,vm-kernel-mac-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/228080
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2022-03-09 18:02:34 +00:00
Alexander Markov 211da364be [vm] Experimental ability to spawn isolate from kernel blob in memory
TEST=runtime/tests/vm/dart/spawn_uri_from_kernel_blob_test.dart

Change-Id: Ieb327f0350d5d8ea1d344c64aa3dd217125da5fe
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/232682
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2022-02-23 16:55:52 +00:00
Vyacheslav Egorov 72eb59f32a [vm/compiler] Allow WB elimination for small arrays.
Previously all arrays were excluded from WB elimination pass
to avoid invariant restoration code creating excessive work
for the GC and to avoid dealing with card marking in the
invariant restoration code.

It seems reasonable to enable this for small arrays of up to 8
elements. The cut of point of 8 elements was chosen based on the
cut of point for literal<N> specialisations provided by the
core library for creating small literal arrays.

TEST=vm/cc/IRTest_WriteBarrierElimination_Arrays

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-dwarf-linux-product-x64-try,vm-kernel-precomp-linux-debug-simarm_x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-precomp-linux-debug-x64c-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-precomp-linux-release-simarm-try,vm-kernel-precomp-linux-release-simarm64-try,vm-kernel-precomp-linux-release-simarm_x64-try,vm-kernel-precomp-linux-release-x64-try
Change-Id: I2b3169865f07c3ff95820c1bc6718943e96bd33b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/229903
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2022-02-07 10:47:12 +00:00
Ryan Macnak 04ba20aa98 [vm] Support RISC-V.
Implements a backend targeting RV32GC and RV64GC, based on Linux standardizing around GC. The assembler is written to make it easy to disable usage of C, but because the sizes of some instruction sequences are compile-time constants, an additional build configuration would need to be defined to make use of it.

The assembler and disassembler cover every RV32/64GC instruction. The simulator covers all instructions except accessing CSRs and the floating point state accessible through such, include accrued exceptions and dynamic rounding mode.

Quirks:
  - RISC-V is a compare-and-branch architecture, but some existing "architecture-independent" parts of the Dart compiler assume a condition code architecture. To avoid rewriting these parts, we use a peephole in the assembler to map to compare-and-branch. See Assembler::BranchIf. Luckily nothing depended on taking multiple branches on the same condition code set.
  - There are no hardware overflow checks, so we must use Hacker's Delight style software checks. Often these are very cheap: if the sign of one operand is known, a single branch is needed.
  - The ranges of RISC-V branches and jumps are such that we use 3 levels of generation for forward branches, instead of the 2 levels of near and far branches used on ARM[64]. Nearly all code is handled by the first two levels with 20-bits of range, with enormous regex matchers triggering the third level that uses aupic+jalr to get 32-bits of range.
  - For PC-relative calls in AOT, we always generate auipc+jalr pairs with 32-bits of range, so we never generate trampolines.
  - Only a subset of registers are available in some compressed instructions, so we assign the most popular uses to these registers. In particular, THR, TMP[2], CODE and PP. This has the effect of assigning CODE and PP to volatile registers in the C calling convention, whereas they are assigned preserved registers on the other architectures. As on ARM64, PP is untagged; this is so short indices can be accessed with a compressed instruction.
  - There are no push or pop instructions, so combining pushes and pops is preferred so we can update SP once.
  - The C calling convention has a strongly aligned stack, but unlike on ARM64 we don't need to use an alternate stack pointer. The author ensured language was added to the RISC-V psABI making the OS responsible for realigning the stack pointer for signal handlers, allowing Dart to leave the stack pointer misaligned from the C calling convention's point of view until a foreign call.
  - We don't bother with the link register tracking done on ARM[64]. Instead we make use of an alternate link register to avoid inline spilling in the write barrier.

Unimplemented:
 - non-trivial FFI cases
 - Compressed pointers - No intention to implement.
 - Unboxed SIMD - We might make use of the V extension registers when the V extension is ratified.
 - BigInt intrinsics

TEST=existing tests for IL level, new tests for assembler/disassembler/simulator
Bug: https://github.com/dart-lang/sdk/issues/38587
Bug: https://github.com/dart-lang/sdk/issues/48164
Change-Id: I991d1df4be5bf55efec5371b767b332d37dfa3e0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217289
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-01-20 00:57:57 +00:00
Ryan Macnak 0ec95bf5ee [vm] Define kFpuRegisterSize based on the target architecture, not the host architecture.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/47802
Change-Id: Icf4522df4109dd653727aa988ba4dccd8f939ae2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226420
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-01-05 22:03:44 +00:00
Vyacheslav Egorov f999e15653 [vm] Avoid UB in CompressedStackMap payloads
Having uint32_t field in UntaggedCompressedStackMaps::Payload
implies 4 byte alignment of the whole structure and the field
itself. We would prefer, however, to avoid this requirement because
we are packing these structures tight in AOT snapshots without any
padding in between.

This change rewrites the implementation to use `memcpy(...)` to remove
any alignment requirements. Note that this `memcpy(...)` will
be optimized down to a single memory move on all platforms we currently
support as they support necessary unaligned load/store instructions.

This also means that the original code worked just fine, except when
running under UBSAN.

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

TEST=ubsan bots

Cq-Include-Trybots: luci.dart.try:vm-kernel-precomp-ubsan-linux-release-x64-try,vm-kernel-ubsan-linux-release-x64-try
Change-Id: I26a30123fcbc6d2c711f039f15f749913ce4d7bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226100
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2022-01-04 08:33:15 +00:00
Ryan Macnak 4b2309c15a [standalone] Fix reuse of va_list in syslog_android.cc.
Also add some missing va_end.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/47939
Change-Id: Iadfbf72493d987dfb1d102922db1b353249a4728
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224240
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-12-15 22:22:36 +00:00
Tess Strickland f9939de8b8 [gardening] Fix MSAN failure in assert.h.
The failure is within std::ostringstream without any obvious errors
on our side, but just appending to std::string instead should be
fine for a failure case.

TEST=vm/cc/IsolateReload_PendingUnqualifiedCall_StaticToInstance on MSAN trybot

Change-Id: I36e91c4ba4019856c709834d29ce9c4595e6a336
Cq-Include-Trybots: luci.dart.try:vm-kernel-msan-linux-release-x64-try
Bug: https://github.com/dart-lang/sdk/issues/47933
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/224200
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2021-12-15 13:49:56 +00:00
Ryan Macnak 98baaa0ee3 [vm, compiler] Add missing tests for ARM64 disassembly.
- Fix disassembly of 32-bit stxr/ldxr/stlr/ldar.
 - Add missing disassembly of rbit.
 - Use the standard names for arithmetic/logical ops with immediates.
 - Fix name of csel.
 - Fix operand ordering for conditional moves.
 - Add preferred disassembly 'ret lr' -> 'ret'.
 - Add preferred disassembly 'ands zr, a, b' -> 'tst a, b'.
 - Add preferred disassembly 'sub a, zr, b' -> 'neg a, b'.

Overall our disassembly is nearly the same as standard A64 disassembly, except we use a "w" suffix for 32-bit operations instead of using "w" versus "x" register names, and we use our own register names.

TEST=ci
Change-Id: Ifb4e587b5cc490beb4c6a09145149d95b09d412d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/223680
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-12-14 18:17:34 +00:00
asiva 0b7c7e09b0 [VM / Runtime] Fix GetLastErrorAsString to use the correct status on
Windows

TEST=cq

Bug:47911
Change-Id: I52184d34d8dc61a98416b3836cc994e3090b2f04
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/223742
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2021-12-14 16:27:44 +00:00
Martin Kustermann 228c52ed4a Reland "[vm] When run under TSAN use longjmp() to skip over C++ frames before manually unwinding to the catch entry"
TSAN instruments C++ code by adding prologue/epilogue code which
maintains a shadow stack. Using setjmp()/longjmp() is intercepted by
TSAN and correspondingly unwinds the shadow stack.

When Dart VM throws exceptions we call the JumpToFrame stub
from C++ which will directly reset the stack to the exception handler
catch entry. This leaves the TSAN shadow stack unchanged.

This means whenever an exception is thrown we leak frames in TSAN's
shadow stack. Due to using a fixed-size shadow stack, it will cause a
buffer-overflow in TSAN when too many such frame leaks happen. This can
cause arbitrary memory to be overriden, leading to awkward crashes.

This is especially an issue on the "iso-stres" builder because it
launches - in the same process - *many* small tests, more easily hitting
that limit.

This CL will workaround the TSAN issue by making runtime call save it's
state via setjmp() and make exception throughing process go via
longjmp() (which TSAN will intercept) before actually calling the
JumpToFrame stub.

=> This will ensure the TSAN shadow stack is correctly maintained.

The [jmp_buf]'s encoding of register state is non-trivial (e.g. it uses
XOR'ing of the actual saved state under certain glibc versions). So we
store any state we need to pass to the target of the `longjmp()` on the
[Thread] instead of overriding the [jmp_buf]s register state with the
arguments.

Issue https://github.com/dart-lang/sdk/issues/47472#issuecomment-948235479

TEST=vm/dart{,_2}/regress47472_test.dart

Change-Id: Ifbf6580aa15bcce54d0584cdc3cd18cc19be0a9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/222300
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2021-12-08 20:41:18 +00:00
Vyacheslav Egorov 3d34ec1dbf Revert "[vm] When run under TSAN use longjmp() to skip over C++ frames before manually unwinding to the catch entry"
This reverts commit 20e6a4dc92.


Revert "[gardening] Fix Product TSAN build by fixing accidental ReleaseTSANX64 -> ProductTSANX64 issue"

This reverts commit e6c24f934e.

Reason for revert: to unblock Google3 roll.

TEST=revert

Change-Id: If22e17d514a81829a9eeb5585257fc477026ea63
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221465
Auto-Submit: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Emmanuel Pellereau <emmanuelp@google.com>
2021-11-29 09:34:23 +00:00
Martin Kustermann 20e6a4dc92 [vm] When run under TSAN use longjmp() to skip over C++ frames before manually unwinding to the catch entry
TSAN instruments C++ code by adding prologue/epilogue code which
maintains a shadow stack. Using setjmp()/longjmp() is intercepted by
TSAN and correspondingly unwinds the shadow stack.

When Dart VM throws exceptions we call the JumpToFrame stub
from C++ which will directly reset the stack to the exception handler
catch entry. This leaves the TSAN shadow stack unchanged.

This means whenever an exception is thrown we leak frames in TSAN's
shadow stack. Due to using a fixed-size shadow stack, it will cause a
buffer-overflow in TSAN when too many such frame leaks happen. This can
cause arbitrary memory to be overriden, leading to awkward crashes.

This is especially an issue on the "iso-stres" builder because it
launches - in the same process - *many* small tests, more easily hitting
that limit.

This CL will workaround the TSAN issue by making runtime call save it's
state via setjmp() and make exception throughing process go via
longjmp() (which TSAN will intercept) before actually calling the
JumpToFrame stub.

=> This will ensure the TSAN shadow stack is correctly maintained.

The [jmp_buf]'s encoding of register state is non-trivial (e.g. it uses
XOR'ing of the actual saved state under certain glibc versions). So we
store any state we need to pass to the target of the `longjmp()` on the
[Thread] instead of overriding the [jmp_buf]s register state with the
arguments.

Issue https://github.com/dart-lang/sdk/issues/47472#issuecomment-948235479

TEST=vm/dart{,_2}/regress47472_test.dart

Change-Id: I4b6f0d4eacef85487c55999021d72a6d932facad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221083
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2021-11-26 12:57:04 +00:00
Ryan Macnak 12bf51a466 [vm, gc] Include starting concurrent marking in --verbose_gc output.
Measure sizes in MB instead of kB.

TEST=--verbose_gc
Change-Id: I5d2b45a31d2eb91665c175d8abf016329ce0f07d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/217740
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-10-28 18:20:18 +00:00
Ryan Macnak 67c1f75d2b [vm] Give a better error if one tries to build simia32 or simx64.
TEST=build
Bug: https://github.com/flutter/flutter/issues/90769
Change-Id: Ib613538efab60f3c688824e939a8f0bc41b83c58
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/214681
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2021-09-27 23:45:45 +00:00
Vyacheslav Egorov bda70c8489 [vm] Remove support for dart-ext: imports
Per breaking change #45451 we are removing support for dart-ext:
style native extensions from the Dart VM.

This CL removes the associated VM code, tests and samples. It also ports
a single test which used dart-ext: import to use FFI instead.

TEST=ci

Bug: https://github.com/dart-lang/sdk/issues/45451
Change-Id: Iae984bce32baf29a950b5de1323939006a217b94
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/212050
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-09-02 14:14:35 +00:00
Tess Strickland 431ed5183f [vm/compiler] Reduce number of subtype comparisons in AOT.
Previously when building subtype class id ranges for a class in AOT, we
looped over the entire class table, even though in most cases, the
number of actual subclasses and implementors of the class is a small
subset of all loaded classes.

Instead, use the same hierarchy information in both JIT and AOT, only
falling back to traversing the entire class table in cases where the
hierarchy information is missing.

Additional changes:
* Do not generate unused type argument checks if the subtype class id
  range to check is empty.
* Only generate a nullability check when checking that an instance
  type argument is a subtype of non-nullable Object in null safe mode.
* Fix AbstractType::IsSubtypeOf so _Closure <: Function.

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

TEST=vm/cc/HierarchyInfo

Cq-Include-Trybots: luci.dart.try:vm-kernel-linux-release-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-kernel-precomp-nnbd-linux-release-x64-try,vm-kernel-nnbd-linux-release-x64-try,vm-kernel-tsan-linux-release-x64-try,vm-kernel-linux-product-x64-try,vm-kernel-precomp-linux-product-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try
Change-Id: Ic0310208d271ef04e778f070f420ae0abbdd47d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/210581
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2021-08-19 18:32:01 +00:00
Daco Harkes 6c21348008 [vm] Introduce HAS_SMI_63_BITS
TEST=This is a refactoring, existing tests cover this.

Change-Id: I19c062bcf3d468814e2c2ecfacc9a65050925fc5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208650
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2021-08-03 13:19:01 +00:00
Tess Strickland c49560cd37 [platform] Make NBitMask, Bit, and TestBit constexpr.
Also make NBitMask generic, replace uses of SignedNBitMask
with generic NBitMask, and remove SignedNBitMask.

TEST=No changes to functionality for existing callers, so existing tests.

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
Change-Id: Ic33785e50be98123c75782c6e62ef32ec45f4191
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/208181
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2021-07-27 11:22:47 +00:00
Ben Konyi 4c9e322dd4 [ VM / Service ] Allow for CpuSamples to be streamed when samples are about to be overwritten.
TEST=pkg/vm_service/test/cpu_samples_stream_test.dart

Change-Id: I1fcb49b6a79cde725a1f0622d1327b9a86165ae9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/206920
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2021-07-16 20:50:58 +00:00