Commit Graph

270 Commits

Author SHA1 Message Date
Modestas Valauskas c5d547fdb8 [vm/compiler] Preset far_branch_level for huge JIT-optimized functions.
When the unoptimized code of a function exceeds 1 MB, start its
optimized compile with far_branch_level=1 instead of 0. Without this,
the assembler fails on out-of-range conditional branches at level=0,
longjmps out of the optimizing pipeline, and the whole pipeline reruns
at level=1 from scratch.

Measured on a naive 49 KLOC generated lexer with --huge_method_cutoff
gates lifted: JIT compile drops from ~26.6s to ~13.2s (about 50%).

Work towards https://github.com/dart-lang/sdk/issues/63230

TEST=ci

Change-Id: I2608a23ef899603a46b401b71be7322b7a8dd44b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/506120
Auto-Submit: Modestas Valauskas <valauskasmodestas@gmail.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2026-05-26 08:10:15 -07:00
Ryan Macnak 55f91b69a5 [vm] Remove unneeded HandleScope immediately after StackZone.
There's no point in unwinding the zone's scoped handle blocks just before deleting the entire zone.

TEST=ci
Change-Id: I364c717bffd16f727d6f2427a7b9693a83d74c13
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/499400
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-04-29 15:36:54 -07:00
Ryan Macnak e443b89f23 [vm] Update Irregexp to V8 commit 254cc758346f10be2a7e22e55d90d4defe9cad74.
Includes support for modifier spans and duplicate named capture groups.

Drops the flow graph implementation to ease maintenance.

TEST=corelib/regexp
Bug: https://github.com/dart-lang/sdk/issues/56573
Bug: https://github.com/dart-lang/sdk/issues/61337
Bug: https://github.com/dart-lang/sdk/issues/62349
Bug: https://github.com/dart-lang/sdk/issues/62708
Change-Id: I05640ba945a4fa5476e7ad463738f4f39d842c14
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480121
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-02-23 09:54:47 -08:00
Alexander Markov 7d64093234 [vm,dyn_modules] Skip vm/cc tests which are not relevant to bytecode
TEST=ci

Change-Id: I573d9266583e61114fd7b9df806e51fec8e03e51
Cq-Include-Trybots: luci.dart.try:vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try,vm-dyn-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/442281
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2025-07-28 07:31:45 -07:00
Ryan Macnak 4eeb8cfbe6 [vm, gc] Remove force_growth option from RunWithStoppedMutators.
Adjust wait for sweeper to account for whether we're already under a safepoint operation.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/61019
Change-Id: Ic30500a1348dc8a719e72be64d69e496986107aa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/437901
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-06-30 15:50:40 -07:00
Ryan Macnak b916392008 [vm] Move handle check after barrier in CompileFunction runtime entry.
Remove redundant AOT runtime guard against compilation.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/53718
Change-Id: I1f1b5b0f01cfa08c13b3d3b7695297fac02c9cce
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431300
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-05-27 10:58:19 -07:00
Ryan Macnak 18aa7d3678 [vm] Refactor runtime entries.
- Reduce header surface area.
- Remove runtime_entry_<arch>.cc, which no longer include code generation.
- Fix signature of DLRT_Enter/ExitSafepoint.
- Give non-leaf runtime functions C linkage, as C++ does not have a defined ABI.

TEST=ci
Change-Id: I21e21a50ad9e4f9b32b1204d755bfa69a2ae9b17
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430981
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-05-27 10:46:24 -07:00
Alexander Markov 1f4707ae0c [vm,dyn_modules] Avoid static calls to bytecode functions from optimized JIT code
Static (direct) calls in the optimized JIT are performed through Code
objects without passing Function objects. This is not compatible with
bytecode interpreter calling conventions, so optimized JIT should
avoid static calls to bytecode functions.

This change disables devirtualized and guarded static calls to
functions declared in bytecode.

TEST=ci

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

Change-Id: I95e4fa0706f376355f4fa7aea7fddf44f303e0a0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428340
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-05-15 07:11:23 -07:00
Ryan Macnak 81a7f3e131 [vm, gc] Remove some dead code.
- Serial scavenge
- Serial marking
- Redudant safepoint operation scope
- Redudant Thread::Current
- Unused HandleVisitor::thread_
- Profile tag updates in PRODUCT mode
- Freelist printing

TEST=ci
Change-Id: I2de4c50df37c7ebe9d267514bcbd548dd61a5a57
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426582
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-05-05 15:21:13 -07:00
Alexander Aprelev 1a6755cbf4 [vm] Clean up bool return value for EnterIsolate methods.
Effectively these methods always succeed, so return value checking just can be source of confusion.

TEST=ci
Change-Id: I0a93f130b03c0f66be733c939a1d795d704291d1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/423963
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-04-24 08:33:05 -07:00
Ryan Macnak 4dd09f9662 [vm] Multiple threads might race to lazily compute local var descriptors.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/53248
Change-Id: I4380ed4d7fbfee73d9dc0396541387fa1bb4e1ab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415104
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-03-12 17:47:49 -07:00
Ryan Macnak 101516eb18 [vm] Allow reload during FFI and native calls.
TEST=many_isolates_blocked_* under reload stress testing
Bug: https://github.com/dart-lang/sdk/issues/60098
Change-Id: Ifb9838735e1846236e30820d7d957e3a51fd9e99
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/410960
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-03-12 12:33:50 -07:00
Alexander Markov ebb7e1061c [vm] Use _setjmp instead of setjmp on MacOS/iOS
setjmp is extremely expensive on MacOS/iOS as it always saves
signal mask.

Introduce DART_SETJMP / DART_LONGJMP macros to use _setjmp instead of
setjmp on MacOS/iOS.

DeltaBlue on Mac/arm64 on the interpreter:
179585.3 us -> 58347.9 us. (3x faster)

TEST=ci
Issue: https://github.com/dart-lang/sdk/issues/60205

Change-Id: I2122f2eb4d5de66ae2ef904a7034af1ed09f1d07
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412320
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-02-26 14:01:44 -08:00
Alexander Aprelev 4093bdaf5a [vm] Change try-catch IL representation.
Previously catch blocks were hanging off the function entry blocks being effectively an alternative entry-point into the function. Now catch blocks are hanging off the try-entry blocks.
  Previously all the variables that are used in the catch block and beyond were declared as parameters to catch block. Now only those that have their definitions not dominating catch entry will become parameters (for example, if a variable is assigned in the try-block, it becomes a parameter to catch block).
  During OSR, if OSR target entry point is inside some try-blocks, then all of corresponding try-entry/catch-blocks are pulled up to the OSR entry forming a chain that ends with a jump to the OSR target entry.

TEST=vm/dart/trycatch*, ci
Change-Id: Iae20c6548d5d65c63be6d7a53c1b0d2adac7ac31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/356311
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-12-18 09:30:10 -08:00
Alexander Markov 4c3ab23046 [vm,compiler] Avoid passing anything except flow graph to code generation
This is a preparation to detach code generation from flow graph
building and optimization passes.

Extra inlining info (inline_id_to_function, inline_id_to_token_pos and
caller_inline_id) is now added to FlowGraph and can be serialized and
deserialized.

ic_data_array is not needed for optimized compilation and is no longer
passed.

A separate CompilerPassState is created for code generation.

TEST=ci (refactoring)

Change-Id: Ib61af47c2ddde1353b9a0fe24995d29d6e85acad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399883
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-12-11 06:50:40 -08:00
Alexander Markov 21db850e54 [vm/compiler] Remove speculative inlining from AOT
TEST=ci

Change-Id: I43817742de295dbbd8c3166d88cecb89b5dfbcf7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398581
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-12-09 15:10:52 +00:00
Alexander Markov 4c1d453522 [vm/compiler] Cleanup outdated CompilationPipeline
TEST=ci

Change-Id: Ia817aab0d607b1259ab2d3398a0a2cb97267753c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398586
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-12-04 00:16:19 +00:00
Ryan Macnak 0a238b3828 [vm] Update to C++20.
- There is no C20, so that stays at C17
 - Math between different enum types disallowed, use explicit cast
 - operator++ removed from volatile types
 - stream print for wchar_t removed

TEST=build
Bug: https://github.com/dart-lang/sdk/issues/42074
Change-Id: Ie552b0bf24f8ac8991336c61fd4bd4913da42909
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/393622
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2024-11-12 20:28:50 +00:00
Ryan Macnak 262b759e06 [vm] Place regexp sources in their own directory.
This makes it easier to see their cost in binary size tools.

TEST=ci
Change-Id: I6079ad9fb9b7c9450bb8d255e9a794a38ec9ae62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/388641
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-08 17:28:49 +00:00
Alexander Markov 0c9067c626 [vm,aot] Preliminary support for dynamic interface in AOT
TEST=runtime/tests/vm/dart/dynamic_module_pragmas_il_test.dart

Change-Id: I6efd24f55726db858711d5f77beabf5659e288a4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/371563
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-06-18 14:31:24 +00:00
Tess Strickland d06d627c79 [vm] Remove --[no-]lazy-dispatchers flag.
No client of the VM uses this flag, only tests, and this flag was always
set to false in AOT mode. Thus, remove uses of this flag and instead
always lazily create dispatchers as needed when resolving method names
in JIT mode.

Remove the implicit value of `allow_add` for some Resolver
static methods. For callers that previously depended on the implicit
`true` value (which includes the AOT precompilier), pass `true` for
uses in the compiler and pass `!FLAG_precompiled_mode` for uses in the
runtime. Assert that `allow_add` is false when these methods are invoked
from the precompiled runtime.

Remove Resolver static methods that are no longer used.

TEST=ci

Change-Id: Ib6a7354f7a859e86743c381513a4129c14895753
Cq-Include-Trybots: luci.dart.try:vm-linux-debug-x64-try,vm-linux-release-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-mac-release-arm64-try,vm-mac-debug-arm64-try,vm-mac-release-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/366668
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-06-06 10:56:12 +00:00
Alexander Markov 7a13b55806 Reland "[vm/compiler] Move handling of recognized methods from inliner to call specializer"
This change relands https://dart-review.googlesource.com/c/sdk/+/358221
without extra changes (modulo rebase).

Performance regressions are addressed in
https://dart-review.googlesource.com/c/sdk/+/360560.

TEST=ci

Change-Id: I587efb6b8e5f8929bc42a4170871cb5efc8e99df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360282
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-04-22 15:29:22 +00:00
Daco Harkes f98a2138b7 [vm] Run clang-format on code base
When uploading CLs, the presubmit checks verify that the lines in the
diff are formatted correctly according to `git cl format runtime`.

However, when `buildtools/<os>-<arch>/clang/bin/clang-format` is
updated, it does not force reformatting of files that would be
reformatted.

This leads to two issues:
* Inconsistent style within the code base and within a single file.
* Spurious reformatting in CLs when (1) clang-format is used on the
  whole file, or (2) the diff lines overlap.

`clang-format` doesn't change that frequently, so in general this is
not a large issue, but I've seen a bit too many "spurious formatting,
please revert" comments on CLs recently.

This CL formats the runtime to be in line with the current pinned
`clang-format`:

```
$ find runtime/ -iname *.h -o -iname *.cc | xargs buildtools/mac-arm64/clang/bin/clang-format -i
```

`git cl format` (which only formats changed lines, and does so with
`clang-format`) seems to not agree with itself, or clang-format, or
cpplint in a handful of places. This CL adds `// clang-format off`
for these. (See previous patchsets for the specific instances.)

TEST=A variety of bots including GCC, MacOS and Windows.

Change-Id: I470892e898971899fda14bb3b8f2c8efefd67686
Cq-Include-Trybots: luci.dart.try:vm-gcc-linux-try,vm-ffi-qemu-linux-release-riscv64-try,vm-ffi-qemu-linux-release-arm-try,vm-aot-win-debug-x64-try,vm-win-debug-x64c-try,vm-mac-debug-x64-try,vm-mac-debug-arm64-try,vm-aot-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362780
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2024-04-17 19:14:41 +00:00
Alexander Markov 9303ecafc7 [vm/compiler] Unify force-optimized compiler passes with ordinary optimized functions
Specialized compiler pipeline for force-optimized functions is not
needed (force-optimized functions can be inlined into the arbitrary
functions and optimized using ordinary pipeline anyway) and error-prone
(certain optimizations could be missing by mistake).

This change unifies the pipelines by using ordinary pipeline for
force-optimized functions.

TEST=ci

Change-Id: Ia315abded61954e06acfc209d31ccce45c286437
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/360960
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-04-04 18:46:06 +00:00
Alexander Markov 28258e54fd Revert "[vm/compiler] Move handling of recognized methods from inliner to call specializer"
This reverts commit eebc219bab.

Reason for revert: performance regressions

Original change's description:
> [vm/compiler] Move handling of recognized methods from inliner to call specializer
>
> This refactoring reduces number of places where recognized methods are
> handled and cleans up general-purpose inliner pass.
>
> The code is mostly moved as is to simplify reviewing, with a notable
> exception: in a few places handling of recognized method calls is
> removed as it duplicates handling performed during call specialization
> passes (ApplyClassIds and ApplyICData) which run both before and after
> inlining.
>
> TEST=ci
>
> Change-Id: I8d53d23587beb09e6edf64ee95524f6ad3e060de
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358221
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Commit-Queue: Alexander Markov <alexmarkov@google.com>

Change-Id: I9576bc4b385b5d0e0b728556defedb4962ec0a8a
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/359842
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
2024-03-26 14:25:38 +00:00
Alexander Markov eebc219bab [vm/compiler] Move handling of recognized methods from inliner to call specializer
This refactoring reduces number of places where recognized methods are
handled and cleans up general-purpose inliner pass.

The code is mostly moved as is to simplify reviewing, with a notable
exception: in a few places handling of recognized method calls is
removed as it duplicates handling performed during call specialization
passes (ApplyClassIds and ApplyICData) which run both before and after
inlining.

TEST=ci

Change-Id: I8d53d23587beb09e6edf64ee95524f6ad3e060de
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358221
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-03-25 20:58:15 +00:00
Vyacheslav Egorov bebee99b23 [vm/compiler] Move reorder_blocks onto the graph.
Make FlowGraph constructor compute whether we are planning to reorder
blocks before code generation or not. This makes the state of the
graph at the end of the compilation more clear.

This is just a refactoring without any functional changes.

TEST=ci

Change-Id: Ieefb02237cc1ebd69d5d2b217bdc8ebbfdbf15c7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/358446
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2024-03-20 21:18:10 +00:00
Alexander Markov dcdfcc2b8d Reland "[vm/ffi] Express FFI call closures explicitly in AST"
This reverts commit 1800039c2a.

The changes fd2e9b9f1a and
c20f9eaf6f are relanded as is.

Reason for revert was fixed separately in
https://dart-review.googlesource.com/c/sdk/+/341621

TEST=ci

CoreLibraryReviewExempt: Implementation change only.
Issue: https://github.com/dart-lang/sdk/issues/54172
Issue: https://github.com/dart-lang/sdk/issues/39692
Change-Id: I1a2324768502e5ffbce328127938c0d3c96c38ba
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341642
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2023-12-15 15:25:29 +00:00
Alexander Markov 1800039c2a Revert "[vm/ffi] Express FFI call closures explicitly in AST"
This reverts commit fd2e9b9f1a.

Revert "[vm/ffi] Cleanup FFI call trampolines"

This reverts commit c20f9eaf6f.

Reason: https://github.com/flutter/flutter/issues/140074
TEST=ci
CoreLibraryReviewExempt: Implementation change only.
Change-Id: Ib193d8f015fc66461fe3cc90550a92e1ba65f236
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/341620
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2023-12-14 01:14:58 +00:00
Alexander Markov c20f9eaf6f [vm/ffi] Cleanup FFI call trampolines
After [1], FFI call sequence is generated inside a Dart closure
function and separate FFI call trampolines are no longer used.
This change removes all code related to FFI call trampolines.

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

TEST=existing

Change-Id: I0af0be6441009fb4db885ee172b0487f4796fd18
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340302
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-12-12 19:19:45 +00:00
Liam Appelbe e8d7425c4e [vm/ffi] Closure callbacks for sync callbacks
Bug: https://github.com/dart-lang/sdk/issues/52689
Change-Id: I54be397cfbf8519fe5b5a51b793fe46d602124d9
Fixes: https://github.com/dart-lang/sdk/issues/52689
Bug: https://github.com/dart-lang/sdk/issues/53096
TEST=isolate_local_function_callbacks_test.dart, plus generated tests and additions to existing tests
CoreLibraryReviewExempt: The isolate and FFI packages are VM-only
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/317060
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-08-25 03:35:44 +00:00
Liam Appelbe edeac698c2 [vm/ffi] Closure callbacks for async callbacks
This change is almost trivial. The closure is stored on the callback's
RawReceivePort, not in the VM. So we can basically just remove the CFE
check and it pretty much works. The only problem is that we can't set
function.FfiCallbackTarget anymore, so most of the CL is dealing with
that.

A few places were deciding whether an FFI trampoline was a call or a
callback based on whether function.FfiCallbackTarget() was null. But
now the target will be null for async callbacks. So instead I've added
a new value to the FfiCallbackKind enum (and renamed it), and changed
those checks.

Sync callback closures will be a separate CL, because they're more
complicated.

Bug: https://github.com/dart-lang/sdk/issues/52689
Change-Id: I8e5dfb557362e679f66195b735c3c382e6792840
TEST=async_void_function_callbacks_test.dart
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/316160
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2023-07-26 23:23:26 +00:00
Martin Kustermann 95492b9f48 [vm] Avoid having two [Code] objects for same force-optimized [Function] around
Force-optimized functions cannot deoptimize & reoptimize. Compiling them
always produces the same code.

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

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

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

TEST=ci

Change-Id: I922728795943f006406feeca2e7a9f899859e800
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305920
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2023-05-26 08:50:45 +00:00
Martin Kustermann 2d230aa0b5 [vm/ffi] Move ffi-callback related state from Thread to ObjectStore, move jit trampolines from Isolate to IsolateGroup
The ffi-callback related information on the [Thread] object is metadata
corresponding to ffi-callback-trampoline [Function] objects. There is
nothing thread or isolate specific about it.

Moving it away from [Thread] is needed because an [Isolate] can
have different [Thread] objects across its lifetime (see [0]): When
the stack of an isolate is empty, we reserve now the right to
re-cycle the [Thread]. If the isolate later runs again, it may
get a new [Thread] object.

This CL moves this information from [Thread] to the [ObjectStore]. In
addition we make the compiler be responsible for populating this
metadata - instead of doing this per-call site of
`Pointer.fromFunction()`. It will be preserved across snapshot writing
& snapshot reading (for AppJIT as well as AppAOT).

Similarly the JIT trampolines that are on Isolate aren't isolate
specific and can go to [IsolateGroup]. This simplifies doing the above
as the compiler can allocate those as well.

The effect is that [Thread] object gets smaller, GC doesn't have to
visit the 2 slots per-thread. It comes at expense of 2 more loads
when invoking the callback.

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

TEST=Regression test is vm/ffi{,_2}/invoke_callback_after_suspension_test

Change-Id: Ifde46a9f6e79819b5c0e359c3d3998d1d93b9b1e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/303700
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-05-17 11:23:28 +00:00
Martin Kustermann 9bdd2ff1de [vm] Cleanup unused include, unnecessary fields on [Thread], rename mutator thread, ensure setjmp drains sticky error
Some cleanups factored out of a larger CL (which refactors enter/exit of threads):

  * remove unused `#include "vm/thread_registry.h"`
  * remove unused/unnecessary fields from [Thread] object
  * rename IsMutator() -> IsDartMutator()
  * make tests using setjmp() drain the sticky error
    => to ensure there's no sticky error on isolate shutdown

TEST=ci

Change-Id: I53935e8bd0628ab3768627d6d5e01c3f0e3a57ad
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/296582
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2023-04-20 17:42:06 +00:00
Martin Kustermann fb43937e20 [vm] Make Thread::IsAtSafepoint() only be true if thread is blocked at a "safe" point
During safepoint we can distinguish between

  * owner of the safepoint operation (which is running code)
  * everyone else (which are all blocked

Currently `Thread::IsAtSafepoint()` will return true for both. Since the
thread owning the safepoint operation is running, it's not actually
guaranteed that it's at "safe" point (e.g. to GC or to deopt) - it
really depends on what it's doing.

=> This CL will change it so that only actually parked threads will
have `Thread::IsAtSafepoint()`.

In order to do that we change varrious usages of `IsAtSafepoint()` to be
more precise:

  * `Thread::OwnsSafepoint()`: True if this thread owns the
    active safepoint. The thread is running.

  * `Thread::OwnsGCSafepoint()`: True if the active safepoint is a GC
    (or Deopt) safepoint and this thread owns it. The thread is running.

  * `Thread::OwnsDeoptSafepoint()`: True if the active safepoint is a
    Deopt safepoint and this thread owns it. The thread is running.

  * `Thread::CanAcquireSafepointLocks()`: True if the thread is allowed
    to acquire safepoint locks.

  * `Thread::IsAtSafepoint()`: true if this thread is parked at a
    safepoint

TEST=ci

Change-Id: I1a5a6727e84843ae79e0a344c438da19b7d6d916
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295781
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-04-19 08:47:31 +00:00
Ryan Macnak 5941defa81 [vm] Update to constexpr in runtime/vm/compiler.
TEST=build
Change-Id: Idf0a05cf8c27164834b5d8464b230cd334a06835
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293082
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-04-11 21:50:56 +00:00
Ryan Macnak de2abc6091 [vm] Update NULL to nullptr in runtime/vm/compiler.
TEST=build
Change-Id: I54cd75bbc942e11c4d719edcc64640da67077634
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/291965
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-03-30 18:23:53 +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
Josh Soref 9e4dc755cb Spelling pkg
Closes https://github.com/dart-lang/sdk/pull/50921

GitOrigin-RevId: 6b1ca502b6722b0a987f33ace66f65cbd2c24e23
Change-Id: I74e4ff3c8e759c576036d6b791bd7734ebd215d8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278536
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
2023-01-19 10:06:29 +00:00
Martin Kustermann 163f30f1b5 [vm] Ensure unoptimized compilations do not have an active isolate
Our compiler shouldn't depend on current isolate, since it can
run on any isolate within an IG.

Doing this change, reveals two existing dependencies on current
isolate from compiler
- resolving native symbols in unoptimized compilations
- issuing of debug events for breakpoints

For the former we'll re-enter the currently active isolate that
triggered unoptimized compilation.
=> We may want to change that embedder API to not be based on
   handles and instead give embedder a simple `const char*`.

For the ladder we'll enter the isolate corresponding to the
breakpoint debug event to be issued. We are at place where
all mutators are stopped, so that does seem okish.
=> Future could remove this by making Object Id Ring per-IG

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

TEST=service_2/break_on_function_many_child_isolates_test/dds

Change-Id: Id246db5972ae505e82f637ce04bb2302bed76257
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278901
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-01-18 08:45:31 +00:00
Martin Kustermann 23d3e86f95 [vm/compiler] Ensure the compiler runs without an active isolate
The compiler should not depend on isolate specific details since
compiled code is shared across isolates in an isolate group.

TEST=ci

Change-Id: I77332c2dea6b5a8e75c1a3be544d1b73a7a69497
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/278900
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2023-01-13 14:38:41 +00:00
Ryan Macnak fa2e1c70ca [vm] Fix various scaling limitations.
- Quadratic behavior recording field guards
 - Quadratic behavior looking up dynamic invocation forwarders
 - Incorrect limit generating allocation stubs

TEST=class with 64k fields
Change-Id: I7a9aba617e71eff9b28711e99c689cb04be0dde7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/273285
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2022-12-13 19:28:37 +00:00
Martin Kustermann ef8a308669 [gardening] Make --optimization-counter-threshold= not affect system isolates
We have many tests that explicitly use --optimization-counter-threshold=
flag. We also have a CI builder that uses this flag for all tests.

This is an issue for cases where `kernel-isolate` is not AppJIT'ed,
which is the case for simulators and ia32. Especially in debug builds
this causes a very-very slow time-to main due to JIT'ing the CFE code in
`kernel-isolate` and running flow graph checker etc (in debug mode).

This causes various tests to sporadically hit the timeout limit, become
flaky and require gardening attention.

As workarounds: the actual threshold was modified in tests, status files
were updated to mark tests as Pass,Slow etc.

=> This Cl will make `kernel-isolate` no longer be affected by the
   `--optimization-counter-threshold`
=> This should make the cycle times faster on those modes and avoid
   flaky timeouts that gardeners constantly have to pay attention to.

TEST=ci

Change-Id: Ia58e807b22f69f924315a43c6764427afe398ee6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/266683
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2022-10-31 14:38:44 +00:00
Ryan Macnak fb84b13e55 [vm, compiler] Rename StoreInstanceFieldInstr to StoreFieldInstr to match LoadFieldInstr and GuardFieldXYZInstr.
TEST=ci
Change-Id: I3161cad413f2d7be2bd8269306a51b5ae6a7384d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/252780
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2022-07-27 20:00:49 +00:00
Alexander Markov de43a7c16a [vm] Cleanup --lazy-async-stacks VM option
This option was enabled by default in https://dart-review.googlesource.com/c/sdk/+/149288
This change removes old logic behind --no-lazy-async-stacks
and makes --lazy-async-stacks/--no-lazy-async-stacks options no-op.

TEST=ci

Change-Id: I5726690e90e78dd2ac37d8c5944e388042fc3acf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/247780
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2022-06-10 13:41:24 +00:00
Alexander Markov 76167c002d [vm/aot] Issue warning when compiling huge functions
Certain optimizations are disabled when compiling huge functions.
Also, compiling large functions may cause out of memory in compiler.

This change adds a warning in order to make it easier for users to
find out about huge functions in their programs and diagnose OOM
during compilation.

TEST=ci
Issue: https://github.com/flutter/flutter/issues/94461

Change-Id: Ibc7fb69df21fa96b8159d24c1b71ef8d690b23df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/230160
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2022-01-27 16:35:20 +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
Alexander Aprelev 8159c38d65 [vm/jit/unboxed] Remove heuristic that transitions unboxed fields back to boxed.
The heuristic was introduced in b870dafa4f, but gets in the way of maintaining Slot(extended with field guard information) immutable during compilation.

Existing set of benchmarks doesn't seem to show any reasonable regression with this heuristic removed.

Bug: https://github.com/dart-lang/sdk/issues/47722
Change-Id: Ie94050d96852b7ffef2dc81248cda23e84d41f4b
TEST=ci
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/221544
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2021-11-30 08:10:25 +00:00
Vyacheslav Egorov 6401220bc1 [vm] Include compiler state in crash reports.
This changes Profiler::DumpStackTrace to include information available
in the CompilerState attached to the thread into the crash report.

This includes the name of the function being compiled, compilation mode,
current phase, flow graph, instruction being compiled.

TEST=manually by causing compiler to crash

Change-Id: I310629f032a86781e30f0a5e218d21df7d27528e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/220001
Auto-Submit: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2021-11-11 14:30:52 +00:00