Commit Graph

3444 Commits

Author SHA1 Message Date
Alexander Markov 1164ea7f7e [vm,dyn_modules] Support collecting source positions for a script declared in bytecode
TEST=pkg/vm_service/

Change-Id: If9111373f4ddf08bded2a23ab4bb130f1f6ad4a4
Cq-Include-Trybots: luci.dart.try:vm-dyn-linux-debug-x64-try,vm-aot-dyn-linux-debug-x64-try,vm-aot-dyn-linux-product-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436680
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-06-26 08:08:20 -07:00
Alexander Aprelev cabc717e76 [vm/shared] Ensure shared initial field table is used with shared fields.
Fixes https://github.com/flutter/flutter/issues/170038
TEST=shared_static_final_test

Change-Id: Ia242b5d9c661782e5a6018ba96211a75cc47c1a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436200
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-06-23 14:17:40 -07:00
Vyacheslav Egorov c111f693c7 [vm] Fix freelist interaction with dual mapping
Freelist implementation was trying to mark pages executable (RX)
which does not respect possibility that it is working with RW mapping
which can't be directly marked as executable. It needed to use RO
permission instead if dual mapping is enabled.

This CL consolidates all code mentioning RX permission in one place:
VirtualMemory::WriteProtectCode so that we avoid this mistake in the future.

R=kustermann@google.com
TEST=tested by doing large reloads which cause more churn in code space

Change-Id: If99692cac3ce3ff54b907e4c43d7f26bae7439ff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435860
Commit-Queue: Martin Kustermann <kustermann@google.com>
Auto-Submit: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-06-20 03:29:19 -07:00
Ryan Macnak 7973eacdd0 [vm] Rename USING_SIMULATOR to DART_INCLUDE_SIMULATOR.
We now have a mode where the simulator is available but not always used.

TEST=ci
Change-Id: If271f334150e2a125a014a4baa2e03d726300d35
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435562
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-06-18 13:07:22 -07:00
Vyacheslav Egorov d194fcecaf [vm] Use dual mapping of code pages on certain OS versions
Heap references always point into R/RW mapping (this simplifies the
marker) and entry points are retargeted into RX.

To simplify implementation we assume that there are no image pages
created - which means we can always go from Instructions to the start of
the page and check where it is dual mapped to.

TEST=vm/dart/macos_dual_mapping_smoke_test and manually on physical
device

Change-Id: Idbe02b7b695b3c048072cf92f7d062f5ab6e1beb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433940
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-06-12 20:46:54 -07:00
Ben Konyi 60b217ff2d [ Observatory ] Remove Observatory from the Dart VM
Also cleans up some references to Observatory in various places.

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

TEST=N/A
CoreLibraryReviewExempt: Not modifying public core libraries.
Change-Id: I1f36b4e6f1fd9a59a579d719aafa599906eedb3f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429141
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2025-06-11 15:19:55 -07:00
Alexander Markov f9860f9db9 [dyn_modules] Add source positions to bytecode
dart2bytecode can optionally add source position information
(including line starts) to the generated bytecode
(when '--bytecode-options=source-positions' flag is specified).

If bytecode has source positions, they are now shown in stack traces
involving interpreter frames.

TEST=ci

Change-Id: I1ae3326bac21201040be32c712514e71e96f51e2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433760
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-06-10 12:15:25 -07:00
Alexander Aprelev ef4e39a6ef [vm/shared] Ensure exclusive execution of shared field initialization.
Add a mutex to guard execution of vm:shared field initialization.

TEST=isolate_group_shared_init_test
BUG=dartbug.com/60699

Change-Id: If544351fc26bfcc7fb9703954efe785989d488bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431742
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2025-06-05 14:12:33 -07:00
Ryan Macnak bc17496b00 [vm] Fix Google3 ClangTidy warnings.
TEST=presubmit
Change-Id: Ifa4e77cc4548729526a90683ee163c68517e87ef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/433001
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-06-04 15:14:15 -07:00
Tess Strickland 84a1b114cd [vm] Add base class for shared object writers.
This CL pulls out the refactorings used to support the new MachOWriter
in a followup CL to allow them to be reviewed separately.

Rename Elf -> ElfWriter. Also rename model classes used by ElfWriter
for concepts that exist both in ELF and Mach-O to ElfX. For example,
the old ELF-specific SymbolTable is renamed to ElfSymbolTable.

Adds SharedObjectWriter to serve as a base class for both ElfWriter
and the upcoming MachOWriter.

Adds a new AbstractWriteStream that serves as a common superclass
of both BaseWriteStream and SharedObjectWriter::WriteStream and
allows the creation of fully delegating WriteStreams that do not
maintain a local buffer.

Abstract the old Elf::SymbolData class into
SharedObjectWriter::SymbolData, which stores an enum value as the type
of the symbol instead of storing the ELF encoding of the type.

Rename the DwarfElfStream (which actually wasn't ELF specific, as
all the ELF-specific DWARF information is handled by ElfWriter) to
DwarfSharedObjectStream and put it in a separate header file.

Rename Image::compiled_to_elf() to Image::compiled_to_shared_object()
and add a separate Image::compiled_to_elf() that checks for the ELF
magic value at the DSO base. Also add Image::shared_object_start()
and Image::build_id_start() to return pointers to the DSO base and
the build ID note, respectively.

Refactor Image::build_id() and Image::build_id_length() to check
compiled_for_elf() prior to decoding the data pointed to by
build_id_start() as an ELF note section.

Create an AOTSnapshotType enum to specific the snapshot writer to use
in CreateAppAOTSnapshot instead of using an as_elf boolean.

TEST=refactorings, so existing tests on ci

Change-Id: Ia3ab37a4dff93b6e00390b123753be5a51fbdaaa
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-debug-x64-try,vm-mac-debug-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421301
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-05-21 01:36:22 -07:00
Alexander Markov b75b5dcbdd [vm] Cleanup unused Library::GetFunctionClosure
TEST=ci

Change-Id: I303ea1fc07c9a682f8c3b2800c9baebd78fc567f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428302
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-05-13 14:17:33 -07:00
Alexander Aprelev fddb38ecab [vm/shared] Introduce IsolateGroup.runSync()
Allow dart code execution on mutator thread, do not require an isolate.

It moves some states that was kept on an isolate to thread or isolate group.

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

TEST=run_isolate_group_run_test

CoreLibraryReviewExempt: only internal library is being updated
Change-Id: I99df09e23954755387ea6230bfd166493d78e989
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/418503
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-05 14:52:07 -07:00
Alexander Markov 5d0d9e467c [vm,dyn_modules] Fix creation of dynamic invocation forwarders for bytecode functions
TEST=ci

Change-Id: Id3e01591565c20fe8fe5f18438fdc66b61ac5e1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426521
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-05-05 12:56:11 -07:00
Alexander Aprelev 69485e9b28 [vm] Move origin_id from isolate to isolate group.
Isolates in one group share same origin_id anyway, so it makes sense to store it on the group too.


Remove isolate's _originNumber from service api - isolate group should be used instead.

Based on feedback from https://dart-review.git.corp.google.com/c/sdk/+/418503/21/runtime/lib/isolate.cc#107

TEST=ci
Change-Id: Iab4b6393a042c9302e911a276a6afc6dab63e70d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/424140
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-04-23 15:26:21 -07:00
Ryan Macnak e480c74d01 [vm] Fix corruption of null and following objects during OOM.
Array::New[Uninitialized] don't expect to get null from Object::Allocate. Using longjmp seems more robust than adding checks everywhere.

TEST=vm/dart/gc/scavenger_abort_test
Bug: https://github.com/dart-lang/sdk/issues/60552
Change-Id: I2750427c41751f8306d5c8dc28afaf052b6e9d74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422902
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-04-16 16:17:13 -07:00
Alexander Aprelev e0dc78bbf6 [vm/oom] If unable to create OOM stack trace, report OOM without stack trace.
Fixes flaky out_of_memory tests failures.

BUG=https://github.com/dart-lang/sdk/issues/60453
TEST=ci

Change-Id: I5c9192c6cc25660e83f6c03d4293360c353b02d1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419583
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-04-02 13:09:52 -07:00
Alexander Aprelev 4a46bed718 [vm/prealloc] Don't preallocate oom, unwind errors, stacktrace object during isolate startup.
For out-of-memory events vm reserves (and if used, then replenishes) small chunk of memory for handling those, so preallocation of oom and stacktrace is not needed.
Unwind error can be created once as part of vm launch, kept in vm isolate.

This should reduce overhead of starting new isolate.

TEST=ci

Change-Id: Ibe2c85f250a521a8e838cc5690984fe9fa287a98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/419261
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-03-31 11:17:18 -07:00
Alexander Markov a53d81e83c [vm] Fix out-of-bounds access to kernel library -1
Certain kinds of functions do not have corresponding kernel binary,
so Function::KernelLibraryIndex() returns -1 for them.

However, flow graph builder and scopes builder established reading of
kernel binary for those functions, which was based on a typed data
view created for a library -1 (treating some unrelated field from
kernel component index as library offset).

This change fixes this out-of-bounds access and avoids reading
any kernel for these functions.

TEST=ci
Fixes https://github.com/dart-lang/sdk/issues/60369

Change-Id: I91717ec6ad905b71bab49d7b3b3f636bda19afb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417102
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-03-20 17:34:39 -07:00
Ryan Macnak b591571935 [vm] Fix symbol creation during DeoptSafepointOperationScope.
TEST=reload stress mode
Bug: https://github.com/dart-lang/sdk/issues/60337
Change-Id: Ieb85a832b72f0940155b6c3480abb91d5c803805
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/416042
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-03-18 14:52:18 -07:00
Derek Xu dfb5f034a9 [VM/Debugger] Ignore uninitialized late variables when building scope in ActivationFrame::BuildParameters
Following the suggestion on
https://github.com/dart-lang/sdk/issues/57048 to plug the crash while
the CFE works on a better solution.

TEST=pkg/vm_service/test/evaluate_uninitialized_late_variable_test

Issue: https://github.com/dart-lang/sdk/issues/57048
Change-Id: I570631e26fb40971674732e4eac73e9fc1976322
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412960
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2025-02-28 13:49:04 -08:00
Alexander Markov f04f534507 [vm] Make FFI implementation less fragile wrt field order
Replace access of certain fields by hardcoded indices with
lookup by name. As number of fields in those classes is small,
the lookup should not take considerable time.

This fix is done in anticipation for the CFE change
https://dart-review.googlesource.com/c/sdk/+/412880
which may change order of declared fields if there are patches.

TEST=manually tested with CFE change

Change-Id: Ibf4ab6719ee263711fb7c6b21b038ea1dc5f9e7b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412803
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-02-28 10:43:19 -08:00
Ryan Macnak cb59df7acf [vm, ffi] Better handle errors that are not unhandled exceptions during FFI callbacks.
Before this change, an error reaching an FFI callback would attempt to execute the normal invocation stub from the beginning in the FFI callback's frame, which quickly crashes. After this change, the runtime recognizes this marker use of the invocation stub and returns to the FFI callback function instead.

TEST=ffi/unwind
Bug: https://github.com/dart-lang/sdk/issues/39487
Change-Id: I477cfcfc236e6cf518ebfe52860ba49e466ebf8b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409562
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-02-19 09:40:34 -08:00
Alexander Markov 223c3a1c60 [vm, dynamic_modules] Inherit IsDynamicallyOverridden when creating method extractor
A method extractor (implementing get:foo for a method foo()) can be
used as an interface target. If original method can be overridden in
a dynamic module, then method extractor can be overridden too.
So IsDynamicallyOverridden flag should be copied when creating
a method extractor.

TEST=dynamic_modules_suite/tearoff_no_concrete_impl
Fixes https://github.com/dart-lang/sdk/issues/60116

Change-Id: I54439426645b3daf308d18da6e0d06602b9ec30f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409360
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-02-12 10:38:48 -08:00
Ryan Macnak 9e8a21bf52 [vm] Improve the hash for function type parameters.
AOT compiling the isolate stress test spends the majority of its time canonicalizing function types.

In release mode, 2:45 -> 1:43 (-38%)

TEST=ci
Change-Id: I58ef0157612930d582784c7bea7de177c1219a0d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/408941
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-02-10 16:02:30 -08:00
Alexander Markov 430554158e [vm] Support implicit dynamic calls
According to the spec, a call in the form

  e(a0,...,aN)

where static type of 'e' is 'dynamic' should succeed only if
(1) 'e' evaluates to a function, or
(2) runtime type of 'e' has a 'call' *method*.

If runtime type of 'e' has a 'call' getter this invocation should
fail with NSM.

This behavior is different from 'e.call(a0,...,aN)' which accepts
'call' getters.

---

In order to implement this behavior in the VM, a special
'dyn:implicit:call' selector is added. It behaves similarly to
'dyn:call' except when looking for a getter target.

This selector is used when CFE sets FlagImplicitCall on a
DynamicInvocation node.


TEST=co19/Language/Expressions/Function_Invocation/Function_Expression_Invocation/call_A04_t01
TEST=co19/Language/Expressions/Function_Invocation/Function_Expression_Invocation/call_A04_t02

Fixes https://github.com/dart-lang/sdk/issues/59965
Issue https://github.com/dart-lang/sdk/issues/59952
Issue https://github.com/dart-lang/sdk/issues/51517
Issue https://github.com/dart-lang/language/issues/3482

Change-Id: Ic45f7743ad75571476642dcec9c91e6a77e8e321
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/407161
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-02-04 08:13:29 -08:00
Ryan Macnak 82f8a10cdb [vm] Take only a read lock during Field::SetStaticValue.
It is safe for multiple isolates to set their values concurrently. Only growth of the field tables needs to be excluded by the write lock.

A storm of such setters are invoked as part of core library initialization during isolate spawning.

TEST=ci, tsan
Change-Id: I4677e33ee80bb06d261ada2ae9d6b71c94fde611
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/405400
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-01-27 10:41:28 -08:00
Tess Strickland 1ac77f57dd [vm] Align entry point verification and the precompiler.
For entry-point pragma annotations, most of the time they are
used with either no argument or with an argument that evaluates
to either

* false to denote the annotation should not take effect, or
* null or true to denote the annotation should take effect.

However, the user can also specify that only part of the operations
on a member should be accessed from native code by using a string
argument that is either 'call', 'set', or 'get'.

The entry point verification in Invoke/InvokeGetter/InvokeSetter
assumes that for getters and setters, the only valid string argument
is 'get' or 'set', respectively. This is because those methods are
called via `Dart_GetField`[0] and `Dart_SetField`, respectively, as if
they were the getter or setter of a defined field.

However, the precompiler previously assumed that the string
argument 'call' was the only string argument that meant the link
to a function's code object should be saved. Similarly, it assumed the
string argument 'get' for functions meant that their implicit closure
function should be saved, which ends up including getters. Furthermore,
it did not do anything with setters annotated with the string argument
'set'. This means that the code link would not be saved for getters or
setters that were annotated with the string argument expected by the
entry point verifier.

This CL aligns the precompiler to match the expectations of other
parts of the codebase. It also changes TFA to report an error
if a getter or setter is marked with the string argument 'call'.

[0] `Dart_Invoke` can be called with the name of a getter that
returns a closure, but doing so is semantically equivalent to
calling `Dart_GetField` followed by `Dart_InvokeClosure`.

TEST=vm/dart/entrypoint_verification_test

Fixes: https://github.com/dart-lang/sdk/issues/59920
Change-Id: Ia2768bbaf9058bb14a1cdfb331eb85fa082a0e90
Cq-Include-Trybots: luci.dart.try:vm-aot-dwarf-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-product-x64-try,vm-aot-mac-product-arm64-try,vm-aot-obfuscate-linux-release-x64-try,vm-linux-debug-x64-try,vm-linux-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/404823
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-01-24 03:21:22 -08:00
Alexander Markov 9e8e8e5fca [vm,dynamic_modules] Support members which are overridden implictly (transitively) by a dynamic module
Consider the following situation: member M1 is overridden by another
member M2; M2 is overridden in a dynamic module.

Members which can be overridden in a dynamic module (such as M2)
should be specified as 'can-be-overridden' in the dynamic interface.
Members which are overridden implicitly/transitively (such as M1)
are not required to be mentioned in the dynamic interface.
However, when determining possible targets for a call with
interface target M1, compiler should treat it as potentially
overridden in a dynamic module.

This change adds such handling to the VM/AOT. Dynamic interface
annotator now marks members such as M1 with
'dyn-module:can-be-overridden-implicitly' pragma, and
VM/AOT takes both can-be-overridden and can-be-overridden-implicitly
into account.

This change also simplifies handling of implicitly extenable classes
in the VM/AOT - now VM handles both extendable and implicitly-extendable
pragmas (from dynamic interface annotator) instead of recalculating
implicitly extendable classes on its own.

TEST=pkg/vm/test/transformations/dynamic_interface_annotator_test.dart
TEST=dynamic_modules_suite/implicitly_extendable

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

Change-Id: Id4570cc86303f8e45a061d696e9bca0d0b2b4b81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403951
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Nate Biggs <natebiggs@google.com>
2025-01-15 08:13:52 -08:00
Alexander Markov 048df9d706 [vm] Fix tree-shaking of mixin applications when mixin has a member with entry point pragma
Cloned static members of mixins are not used (dead code) and usually
tree shaken in AOT mode. However, if static member is annotated with
@pragma('vm:entry-point'), its clone in the mixin application is
also retained. If such mixin application is not used, tree shaker
drops its supertypes which removes the link from mixin application to
the original mixin. As a result, gen_snapshot crashes when trying
to access original mixin in order to print qualified name of the member.

The first part of the fix is to avoid cloning static members into
mixin applications, which would allow tree shaker to remove unused
mixin applications entirely. This change also reduces size of
the non-AOT kernel binaries.

However, instance members of mixins are cloned
and they could be annotated with entry point pragmas too.

The second part of the fix is to clear isEliminatedMixin flag
in tree shaker when dropping supertypes.

TEST=pkg/front_end/testcases/general/mixin_with_static_member.dart
TEST=pkg/vm/testcases/transformations/type_flow/transformer/regress_flutter160030.dart

Fixes https://github.com/flutter/flutter/issues/160030

Change-Id: I1b36c4a7f64a4530c8b4799ec785f1077ce65de6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403963
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-01-13 07:30:16 -08:00
Alexander Markov 5fd11d360d [vm] Cleanup legacy differences between 'is' and 'as' checks
With sound null safety both 'is' and 'as' type checks use subtyping
without any extra differences.

Replace Instance::IsAssignableTo with IsInstanceOf (which is now
the same as RuntimeTypeIsSubtypeOf).

Remove Instance::NullIsInstanceOf as it is no longer used.

Replace CompileType::IsAssignableTo and IsInstanceOf with IsSubtypeOf.

TEST=ci

Change-Id: I3a071d114c5f86d990255416b244961d506257a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401861
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2024-12-19 11:03:59 -08:00
Stephen Adams da70ebe741 Reapply "[vm, compiler] Treat _uninitializedData/Index as effectively const."
This reverts commit 1d797bd2e2.

TEST=ci
Change-Id: I43a87112cb44239330704e5715051b3988832631
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401141
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Stephen Adams <sra@google.com>
2024-12-18 14:04:01 -08:00
Ryan Macnak 1d797bd2e2 Revert "[vm, compiler] Treat _uninitializedData/Index as effectively const."
This reverts commit 562af5de35.

Reason for revert: regression, loses exact type for initial value?

Original change's description:
> [vm, compiler] Treat _uninitializedData/Index as effectively const.
>
> This avoids static field initialization checks in the default map and set constructors, which in turn avoids write barriers and the frame build.
>
> TEST=ci
> Change-Id: Ie12840ae1799cd97645b2132ad94ec6525126f74
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398760
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

Change-Id: I41af0247277f6456ba9c5dfcdb8da43cebc64cc0
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400222
Commit-Queue: Siva Annamalai <asiva@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Auto-Submit: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2024-12-11 17:00:27 -08:00
Ryan Macnak 562af5de35 [vm, compiler] Treat _uninitializedData/Index as effectively const.
This avoids static field initialization checks in the default map and set constructors, which in turn avoids write barriers and the frame build.

TEST=ci
Change-Id: Ie12840ae1799cd97645b2132ad94ec6525126f74
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/398760
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-12-11 14:46:58 -08:00
Ryan Macnak f5d61441ce [vm] Protect the library map with the program lock.
TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/59626
Change-Id: I5cd12be5a54a519494ce168eaf1c10a45af71930
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399626
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-12-09 23:28:28 +00:00
Alexander Markov 9f38338bab [vm] Cache LanguageError result of metadata evaluation
Copying of pragmas during hot reload (Library::CopyPragmas) relies on
pragma metadata being fully evaluated in the earlier stage of hot reload
(in Library::EvaluatePragmas()).

However, if evaluation of metadata has ended with LanguageError,
the result of evaluation was not cached and metadata remains in
the unevaluated state, which triggers assertion in Library::CopyPragmas.

This change adds caching of the metadata evaluation result if
it ends with LanguageError.

TEST=ffi/abi_specific_int_incomplete_jit_test
Fixes https://github.com/dart-lang/sdk/issues/59665

Change-Id: I25e7b8f298f96ff4665e75fbbcbdb6b146c08f61
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/399200
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
2024-12-09 19:19:35 +00: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
Tess Strickland 9b06e26620 Reland "[vm] Enforce that entry points must be annotated by default."
This is a reland of commit cb9ecbc363

This reland only turns on the entry point verification flag by
default in AOT mode. After Flutter tests that use native access
in JIT mode have been appropriately updated, a followup CL will
turn this flag on by default in JIT mode as well.

Original change's description:
> [vm] Enforce that entry points must be annotated by default.
>
> Changes the default value of the --verify-entry-points flag
> to true.
>
> Changes the default value for the check_is_entrypoint argument to
> to the Invoke/InvokeGetter/InvokeSetter flags to true. The mirrors
> library implementation and calls via vm-service explicitly pass
> false for this argument now.
>
> Add annotations as needed, such as annotating classes with
> annotated generative constructors. In some cases, the annotations
> were more general than needed (e.g., annotating with a no-argument
> entry point annotation when only the setter is needed), so make
> those annotations more specific.
>
> As this pattern is already common in downstream code, allow
> Dart_Invoke on fields as long as the field is annotated for getter
> access. (That is, calling Dart_Invoke for a field is equivalent to
> retrieving the closure value via Dart_GetField and then calling
> Dart_InvokeClosure.)
>
> TEST=vm/cc/DartAPI_MissingEntryPoints
>      vm/dart/entrypoints_verification_test
>
> Issue: https://github.com/dart-lang/sdk/issues/50649
> Issue: https://github.com/flutter/flutter/issues/118608
>
> Change-Id: Ibb3bf15632ab2958d8791b449af8651d47f871a5
> Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try,vm-aot-dwarf-linux-product-x64-try
> CoreLibraryReviewExempt: adding/editing vm-only pragma annotations
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363566
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Commit-Queue: Tess Strickland <sstrickl@google.com>

TEST=vm/cc/DartAPI_MissingEntryPoints
     vm/dart/entrypoints_verification_test

Change-Id: I24919c32ab4760c7c5435c378879791086256f02
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try,vm-aot-dwarf-linux-product-x64-try,flutter-linux-try,vm-linux-debug-x64-try,vm-linux-release-x64-try,vm-appjit-linux-product-x64-try
CoreLibraryReviewExempt: adding/editing vm-only pragma annotations
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391620
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-12-04 14:36:46 +00:00
Alexander Aprelev 59f290ea48 [vm] Clone forwarder function object with relaxed atomics.
TEST=ci
BUG=dartbug.com/59594

Change-Id: I8f6b7ee0bb477d1f05cc8baed2b03650888fba5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396569
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2024-11-25 18:15:16 +00:00
Alexander Aprelev eca32d78e4 [vm/try_catch] Use same catch_entry parameter mechanism in JIT as in AOT.
This simplifies VM, enables further try-catch refactoring.
TEST=ci

Change-Id: Iff80e154f457ac7397a3b73dcf2b32cda2a2af2c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/395344
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2024-11-15 16:46:03 +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 e65b892d12 [vm, compiler] Enable argument registers for RISC-V.
dart2js.aot.rv64gc  28061800 -> 27559904 (-1.8%)
dart2js.aot.rv64gcb 27996112 -> 27510728 (-1.7%)

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/54955
Change-Id: Ic18ab8c33f59c36561fa7e7aed4d06f4e8f8c9dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/357215
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-30 16:34:12 +00:00
Ryan Macnak 949eb447a4 [vm, gc] Add write-write fence after initializing object headers, or defer marking new-space objects in an active TLAB.
On architectures with a weak memory model, there is the possibility that the concurrent marker can see the publishing store of a new object before it sees the initializing store of that object's header. On an M1, the barrier to prevent reordering these stores is fairly cheap, so we emit this barrier on Mac/iOS ARM64. Otherwise, this barrier is very expensive (or at least expensive for some hardware within the ABI), so instead we avoid the race by deferring marking of objects inside an active TLAB.

Disable TSAN instrumentation on the marker setting the mark bit, as TSAN does not understand fences.

TEST=ooo arm64 machines
Bug: https://github.com/dart-lang/sdk/issues/56845
Change-Id: I0676661a7cf941fdc6b451e516d890c26826bb3b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/389265
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2024-10-28 22:41:39 +00:00
Alexander Markov 2b899adb4c Revert "[vm] Enforce that entry points must be annotated by default."
This reverts commit cb9ecbc363.

Reason for revert: causes failures during Dart->Flutter roll and on Flutter HHH bots (see comments on the original CL).

Original change's description:
> [vm] Enforce that entry points must be annotated by default.
>
> Changes the default value of the --verify-entry-points flag
> to true.
>
> Changes the default value for the check_is_entrypoint argument to
> to the Invoke/InvokeGetter/InvokeSetter flags to true. The mirrors
> library implementation and calls via vm-service explicitly pass
> false for this argument now.
>
> Add annotations as needed, such as annotating classes with
> annotated generative constructors. In some cases, the annotations
> were more general than needed (e.g., annotating with a no-argument
> entry point annotation when only the setter is needed), so make
> those annotations more specific.
>
> As this pattern is already common in downstream code, allow
> Dart_Invoke on fields as long as the field is annotated for getter
> access. (That is, calling Dart_Invoke for a field is equivalent to
> retrieving the closure value via Dart_GetField and then calling
> Dart_InvokeClosure.)
>
> TEST=vm/cc/DartAPI_MissingEntryPoints
>      vm/dart/entrypoints_verification_test
>
> Issue: https://github.com/dart-lang/sdk/issues/50649
> Issue: https://github.com/flutter/flutter/issues/118608
>
> Change-Id: Ibb3bf15632ab2958d8791b449af8651d47f871a5
> Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try,vm-aot-dwarf-linux-product-x64-try
> CoreLibraryReviewExempt: adding/editing vm-only pragma annotations
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363566
> Reviewed-by: Martin Kustermann <kustermann@google.com>
> Commit-Queue: Tess Strickland <sstrickl@google.com>

Issue: https://github.com/dart-lang/sdk/issues/50649
Issue: https://github.com/flutter/flutter/issues/118608
Change-Id: Idba168f77b0636a50ad93309e29dc9989cc1f388
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try,vm-aot-dwarf-linux-product-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391460
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2024-10-22 14:18:04 +00:00
Tess Strickland cb9ecbc363 [vm] Enforce that entry points must be annotated by default.
Changes the default value of the --verify-entry-points flag
to true.

Changes the default value for the check_is_entrypoint argument to
to the Invoke/InvokeGetter/InvokeSetter flags to true. The mirrors
library implementation and calls via vm-service explicitly pass
false for this argument now.

Add annotations as needed, such as annotating classes with
annotated generative constructors. In some cases, the annotations
were more general than needed (e.g., annotating with a no-argument
entry point annotation when only the setter is needed), so make
those annotations more specific.

As this pattern is already common in downstream code, allow
Dart_Invoke on fields as long as the field is annotated for getter
access. (That is, calling Dart_Invoke for a field is equivalent to
retrieving the closure value via Dart_GetField and then calling
Dart_InvokeClosure.)

TEST=vm/cc/DartAPI_MissingEntryPoints
     vm/dart/entrypoints_verification_test

Issue: https://github.com/dart-lang/sdk/issues/50649
Issue: https://github.com/flutter/flutter/issues/118608

Change-Id: Ibb3bf15632ab2958d8791b449af8651d47f871a5
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-product-x64-try,vm-aot-linux-debug-x64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-product-arm64-try,vm-aot-dwarf-linux-product-x64-try
CoreLibraryReviewExempt: adding/editing vm-only pragma annotations
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363566
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2024-10-22 09:34:22 +00:00
Ryan Macnak da8f17762c [vm, gc] Allocate card tables up front.
This avoids data races when multiple mutators compete to install the card table, and allows removing the initialization check from the write barrier.

TEST=ci, tsan
Bug: https://github.com/dart-lang/sdk/issues/56895
Change-Id: I30fe4687d3ca771f6c00dfa59e8dadec23d557a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390023
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-16 21:25:17 +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
Ryan Macnak c7f9914497 [vm, reload] Use a more stable hash code for implicit closure functions.
The old hash code used the absolute token position, which made the hash code of a closure change for any insertions or deletions above it in the same file.

TEST=vm/cc/IsolateReload_ClosureHashStablity
Bug: https://github.com/flutter/flutter/issues/153536
Change-Id: I75da3f0cdca1862637179467ec23cf20b9878d8d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/387602
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-10-01 19:35:51 +00:00
Alexander Markov c0e5b7e75d [vm] Correct typo in a comment
Follow-up to https://github.com/dart-lang/sdk/commit/ab19361e87a0248ade1e883f638542163f9100d1#r147196426

TEST=ci

Change-Id: Ic1c67737d5e69f063a4f62fa8c514c0b2d985e98
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386682
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-09-25 16:53:52 +00:00
Alexander Markov ab19361e87 [vm] Masquerade VM internal types more consistently
VM has been hiding certain internal implementation types by
converting them to user-visible types in Object.runtimeType.

However, types of record fields were not converted,
which caused inconsistent hashCode of record types.

This change fixes this bug by applying the same type conversion to
types of record fields.

TEST=tests/language/records/type_equality_and_hash_code_test.dart
Fixes https://github.com/dart-lang/sdk/issues/56771

Change-Id: Ie02e76368de0026620d6ab278f49c14e06fd6eda
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/386542
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2024-09-25 13:46:40 +00:00
Ryan Macnak 2a96956cd3 Roll Clang to 3928edecfbd116d56bbe7411365d50bb567380a1.
Re-run clang-format.

TEST=ci
Change-Id: If40a619e32a17ae95c5ee39e36ef0effd07e90b3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/385363
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-09-23 23:36:48 +00:00