Commit Graph

15954 Commits

Author SHA1 Message Date
Tess Strickland 38ea3a8f5e Revert "[vm, gen_snapshot] Add app-aot-macho-dylib option for AOT snapshots."
This reverts commit 38ef28a058.

Reason for revert: Breaks build on debug mode 32-bit arches,
                   release mode simarm_x64

Issue: https://github.com/dart-lang/sdk/issues/60307
Original change's description:
> [vm, gen_snapshot] Add app-aot-macho-dylib option for AOT snapshots.
>
> This is the initial framework for creating snapshots as Mach-O dynamic
> libraries. Note that this framework is not 100% feature complete
> compared to generating Mach-O snapshots via assembly. In particular,
> the directly-compiled Mach-O dylib does not yet contain compact
> unwinding information.
>
> Other changes:
>
> * Adds UuidCommand to the native_stack_traces package's Mach-O reader,
>   which now appropriately returns the UUID as the build ID for Mach-O
>   shared objects.
>
> * Adds Utils::Basename(path) for portably retrieving the basename
>   from a path. (Returns nullptr for all arguments where it is not
>   currently implemented on Fuchsia or Windows.)
>
> * Adjusts vm/timeline.h to avoid pulling in <mach_o/loader.h> on MacOS,
>   as that interferes with uses of the namespaced Mach-O definitions
>   in platform/mach_o.h.
>
> * Only attempt to dlopen() a snapshot if ELF is the native format
>   for the host platform or the snapshot is not an ELF shared object.
>   If dlopen() is used, report the error message if it fails rather
>   than attempting to manually load the snapshot as an ELF shared object.
>
> * Fix the magic number stored in DylibAppSnapshot for loaded non-ELF
>   dynamic libraries.
>
> * Remove the detection of reverse-endian Mach-O magic numbers in
>   DartUtils::SniffForMagicNumber(), since all our Mach-O related code
>   assumes host-endian Mach-O files and so there's no point other than
>   to give a slightly better error message when failing.
>
> TEST=vm/dart/exported_symbols_test
>      vm/dart/unobfuscated_static_symbols_test
>      vm/dart/use_dwarf_stack_traces_flag_test
>      vm/cc/CanDetectMachOFiles
>
> Issue: https://github.com/dart-lang/sdk/issues/60307
> Change-Id: Idf5b49d6c6d035ab033509613212b95520d65965
> Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64-try,vm-mac-release-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-debug-x64-try,vm-mac-debug-arm64-try,vm-fuchsia-release-x64-try,vm-fuchsia-release-arm64-try
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415020
> Reviewed-by: Slava Egorov <vegorov@google.com>
> Commit-Queue: Tess Strickland <sstrickl@google.com>

Issue: https://github.com/dart-lang/sdk/issues/60307
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64-try,vm-mac-release-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-debug-x64-try,vm-mac-debug-arm64-try,vm-fuchsia-release-x64-try,vm-fuchsia-release-arm64-try
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: Iff2ab4c84a513a184784129f456bd357ae8e3a67
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431220
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Auto-Submit: Tess Strickland <sstrickl@google.com>
2025-05-27 01:05:48 -07:00
Tess Strickland 38ef28a058 [vm, gen_snapshot] Add app-aot-macho-dylib option for AOT snapshots.
This is the initial framework for creating snapshots as Mach-O dynamic
libraries. Note that this framework is not 100% feature complete
compared to generating Mach-O snapshots via assembly. In particular,
the directly-compiled Mach-O dylib does not yet contain compact
unwinding information.

Other changes:

* Adds UuidCommand to the native_stack_traces package's Mach-O reader,
  which now appropriately returns the UUID as the build ID for Mach-O
  shared objects.

* Adds Utils::Basename(path) for portably retrieving the basename
  from a path. (Returns nullptr for all arguments where it is not
  currently implemented on Fuchsia or Windows.)

* Adjusts vm/timeline.h to avoid pulling in <mach_o/loader.h> on MacOS,
  as that interferes with uses of the namespaced Mach-O definitions
  in platform/mach_o.h.

* Only attempt to dlopen() a snapshot if ELF is the native format
  for the host platform or the snapshot is not an ELF shared object.
  If dlopen() is used, report the error message if it fails rather
  than attempting to manually load the snapshot as an ELF shared object.

* Fix the magic number stored in DylibAppSnapshot for loaded non-ELF
  dynamic libraries.

* Remove the detection of reverse-endian Mach-O magic numbers in
  DartUtils::SniffForMagicNumber(), since all our Mach-O related code
  assumes host-endian Mach-O files and so there's no point other than
  to give a slightly better error message when failing.

TEST=vm/dart/exported_symbols_test
     vm/dart/unobfuscated_static_symbols_test
     vm/dart/use_dwarf_stack_traces_flag_test
     vm/cc/CanDetectMachOFiles

Issue: https://github.com/dart-lang/sdk/issues/60307
Change-Id: Idf5b49d6c6d035ab033509613212b95520d65965
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64-try,vm-mac-release-arm64-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-dwarf-linux-product-x64-try,vm-linux-debug-x64-try,vm-mac-debug-arm64-try,vm-fuchsia-release-x64-try,vm-fuchsia-release-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415020
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-05-26 08:52:26 -07:00
Chloe Stefantsova 6fa858cfe8 Enable 'getter-setter-error' flag in 3.9
TEST=existing

Change-Id: Ic4a5735adda7cf8ef1565b9356ca277d9b62b064
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430720
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Michael Thomsen <mit@google.com>
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Chloe Stefantsova <cstefantsova@google.com>
2025-05-26 08:08:31 -07:00
Roy c9ba43db45 [vm] Adding static_field_offset to Field objects.
This adds the offset of static fields within their field table.

TEST=vm/dart/analyze_snapshot_binary_test

Change-Id: I90b13760fa3203ca2e3c5611e3fd890a74c97728
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429880
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-05-23 12:45:41 -07:00
Alexander Aprelev 6497b412e2 [vm/shared] Ensure dart mutator thread stack is walked during gc.
Fix asynchronous aspect of the test.

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

Change-Id: Ife311d5663665e7fa6e8dd3977fc31f5ed22cc17
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430580
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2025-05-23 07:23:22 -07:00
Tess Strickland 9a2234461a [vm] Use a non-native definition of the runtime function structure.
Attempting to use the native definition when available causes problems
when cross-compiling, and the original attempts to avoid this broke in
subtle ways. Instead, just make a non-native definition that mimics
the native definition and use that with reinterpret_casts when sending
uses of the non-native definition to Windows API calls that expect
a value of the native definition.

TEST=windows ci

Fixes: https://github.com/dart-lang/sdk/issues/60771
Change-Id: I347fcaf8cccd809a3d8e6f041cc7e360b0b8226e
Cq-Include-Trybots: luci.dart.try:vm-aot-win-release-arm64-try,vm-aot-win-release-x64-try,vm-win-release-arm64-try,vm-win-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64-try,pkg-win-release-try,pkg-win-release-arm64-try,dart-sdk-win-try,dart-sdk-win-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430400
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-05-23 06:19:16 -07:00
Alexander Aprelev 3718baa446 [ffi/isolate_group_shared] Keep isolate alive for isolate group shared callback.
To fix encountered tsan race(patchset 3)  split Metadata into MetadataEntry as discussed on https://github.com/dart-lang/sdk/issues/60728#event-17760701621

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

Change-Id: I9308d6fb6a9b819221f7fe4668aefb3a578fe8a8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430122
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-22 09:02:01 -07:00
Alexander Aprelev 56819231be [vm/shared] Fix LoadStaticField calls initializer behavior.
With b32e5e5a91 under --experimental_shared_data flag, `LoadStaticField` calls initializer stub to confirm presence of isolate when accessing non-shared static fields. This breaks the role that `calls_initializer` attribute/parameter used to play where it was specifically describing neccessity to call initializer, which is important in how `LoadStaticField` instruction is used in static field setters - it should not attempt to call initialzer.

This CL fixes the problem by renaming current `calls_initializer` `LoadStaticFieldInstr` attribute to `does_slow_checks`, and "adding" separate `calls_initializer` parameter to the instruction to signify specifically whether initializer has to be called.

TEST=ci

Change-Id: Ib81424864c98d889fb6dbb9dd15dac9a39c530f8
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429062
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-05-22 09:02:01 -07:00
Alexander Markov f7790bb65b [gardening] Fix gcc and msvc builds
Fix the following compile-time errors:

C:\b\s\w\ir\cache\builder\sdk\runtime\vm\elf.cc(601) : error C2220: the following warning is treated as an error
C:\b\s\w\ir\cache\builder\sdk\runtime\vm\elf.cc(601) : warning C4715: 'dart::ElfSymbolTable::ElfSymbolType': not all control paths return a value

../../runtime/vm/elf.cc: In static member function ‘static intptr_t dart::ElfSymbolTable::ElfSymbolType(dart::SharedObjectWriter::SymbolData::Type)’:
../../runtime/vm/elf.cc:601:3: error: control reaches end of non-void function [-Werror=return-type]
  601 |   }
      |   ^

TEST=ci

Change-Id: Ib06339405b406ea4a6f6d395a04a16573d92c704
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/430321
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-22 07:50:49 -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
Vyacheslav Egorov 9ff77fd414 [vm] Mark _FutureListener.handleValue invisible
Instead of hiding it by skipping it in AsyncAwareStackUnwinder.

Skipping it manually meant that we don't expand and see
functions which are inlined into handleValue in the
stacktrace which might be undesirable and makes
stacktraces unnecessarily sensitive to inlining.

Filtering based on visibility happens after inlined
frame expansion which makes stack trace more stable.

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

TEST=vm/dart/awaiter_stacks/*

CoreLibraryReviewExempt: pragma only change
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-release-x64-try,vm-aot-linux-product-x64-try
Change-Id: Ie6e0ad65285dd1d6f77e27e7488e8d46d30c176c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429660
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-05-20 11:12:02 -07:00
Ryan Macnak 0a6fa7ac03 [vm] Fix --gc_at_throw, etc for isolate group callbacks.
TEST=ffi/isolate_group_shared_callback_test
Change-Id: Ib4c241d59a36544495c264c51848753a0bc22bf4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/429460
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-05-19 14:07:50 -07:00
Ryan Macnak 3d32a60b55 [vm] Fix race between VM shutdown and in-flight API call.
TEST=vm/cc/DartAPI_TimelineEvents_Loop
Change-Id: I4175fb50991f8bf842437507cc4bf18fc926889d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428622
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-05-19 10:44:33 -07:00
Alexander Aprelev e6784e0580 [gardening] Fix temp variable intptr_t type to match offset uint32_t.
Follow-up to 52dc7979c6
Fixes failed build https://ci.chromium.org/ui/p/dart/builders/ci.sandbox/vm-aot-linux-debug-simarm_x64/4968/overview

TEST=ci

Change-Id: Ifea13d795638e2ba7b6a1e6d50f3e91f012945cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428841
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2025-05-15 09:47:40 -07:00
Ryan Macnak 52dc7979c6 [vm] Fix truncation of slot offsets during heap snapshots.
Truncation caused sorting to place the field at offset 2^16 before the field at offset 8, etc.

TEST=iso-stress
Bug: https://github.com/dart-lang/sdk/issues/60717
Change-Id: Ie75c9fa74b830bc08b386533b16e8b01127b0f26
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428565
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-05-15 09:02:20 -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
Alexander Markov e0673fec9c [vm,dyn_modules] Fix printing of interpreter entry and exit frames
TEST=ci

Change-Id: I49139dd3f03df74e3a6a94f7a4366b9d4dfdc0fb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428580
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-05-15 06:46:16 -07:00
Alexander Markov 081211fd4d [vm,dyn_modules] Fix parameter names for closures declared in bytecode
TEST=existing (e.g. language/vm/regress_32502_test)

Change-Id: I2ea118aa34046a52c7c0d648e60f0d928c7702f5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428620
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-05-15 06:46:11 -07:00
Derek Xu 3dc9d8dcf9 [VM/Service] Add getQueuedMicrotasks RPC
TEST=pkg/vm_service/test/get_queued_microtasks_rpc_test

CoreLibraryReviewExempt: This CL does not include any core library API
changes, only VM Service implementation changes within
sdk/lib/vmservice/.
Change-Id: Ie5488f498e4d0f3d201e3f31423fd5029b74a726
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425160
Commit-Queue: Derek Xu <derekx@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-05-13 14:29:37 -07:00
Derek Xu 0ead16d05b [VM] Make it so that --profile-microtasks is processed by the code in both runtime/bin/main_options.h and runtime/vm/flags.h
TEST=pkg/vm_service/test/timeline_events_for_completed_microtasks_test

Change-Id: Ia544cabc7bfe6e322955d16d3078cab461b803ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425100
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-05-13 14:29:37 -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
Ryan Macnak c0e2f38f02 [dart:io] Fix some code to be safe in the face of reflective invocation.
Reflection can invoke public members of dart:* private types when values of the private types can be returned from public members.

TEST=lib/mirrors/invocation_fuzz_test
CoreLibraryReviewExempt: does not change public API
Bug: https://github.com/dart-lang/sdk/issues/31838
Bug: https://github.com/dart-lang/sdk/issues/46435
Bug: https://github.com/dart-lang/sdk/issues/51213
Change-Id: I969cd935d60455bd9cf4775b8df19838f9e6107c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428065
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-05-13 10:39:23 -07:00
Ryan Macnak 21dd5d02d9 [vm] Fix assert in heap snapshot writer.
TEST=iso-stress
Bug: https://github.com/dart-lang/sdk/issues/60701
Change-Id: I0e66fc1e9ce38eb566f68eddb63ebbe5e2200275
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428081
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-05-12 13:15:33 -07:00
Ryan Macnak 564444d92b [vm] Fix race in thread pool test.
TEST=vm/cc/ThreadPool_RunOne
Bug: https://github.com/dart-lang/sdk/issues/60698
Change-Id: I97dedcea70d389c5f3b9c94ebd99b617cbd70bc9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/428082
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-05-12 12:32:19 -07:00
Ryan Macnak eb563faf6d [vm, gc] Report RSS as timeline counter events, sampled before and after GC.
Catapult will display a nice graph for this.

TEST=view timeline
Change-Id: I6b6fdede463b37dbb10841cfa7c1e08c95e7cb62
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427060
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-05-12 10:46:39 -07:00
Alexander Aprelev e252d458e5 [vm/shared] Fix check for presence of dart mutator stack.
For GC purposes dart mutator thread could be identified by task kind, or if gc task is occupying the thread, by presence of scheduled isolate or (in case of isolategroup-shared thread) by presence of top_exit_frame.

Fixes dartbug.com/60705
TEST=ci

Change-Id: I09d212caf06e92a36efe1e5d397e5bb89846ced2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427981
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-12 07:49:30 -07:00
Paul Berry a757d2af41 Enable sound-flow-analysis for Dart 3.9.
Bug: https://github.com/dart-lang/sdk/issues/60438
Change-Id: I908d4e4a9143142281d8198870f40eba6cf6f67f
Tested: trybots
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427500
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
Reviewed-by: Morgan :) <davidmorgan@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Samuel Rawlins <srawlins@google.com>
2025-05-09 14:50:26 -07:00
Alexander Aprelev 893e37a517 [vm/shared] Add timeout to ConditionVariable.wait.
Update isolate_group_shared_callback_test to use that and also use flag to print exceptions.

TEST=ci
CoreLibraryReviewExempt: only internal library is affected
Change-Id: Ia53ca7a6dc847b551229ccf00bbbfe302a260fcb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427680
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-09 11:29:30 -07:00
Ryan Macnak b7e0e10f68 [vm] Fix hang in mutator slot stealing when no waiters have a timeout.
TEST=vm/dart/isolates/many_isolates_blocked_at_process_run_sync_test
Change-Id: I9d5f300c91ecfeb798f467d5624ada3baa3fb453
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427306
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-05-07 19:47:01 -07:00
Ryan Macnak 57ee563bc9 Roll Clang from 0454dd8c48cd to 8c7a2ce01a77
TEST=ci
Cq-Include-Trybots: luci.dart.try:dart-sdk-linux-try;luci.dart.try:dart-sdk-mac-try;luci.dart.try:dart-sdk-mac-arm64-try;luci.dart.try:dart-sdk-win-try
Change-Id: I9d4e7abe9541f74a67e469c4ba4ba3cecfaec431
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427280
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-05-07 09:22:20 -07:00
Vyacheslav Egorov 3e65c9d2a7 [vm] Buffer writes in TimelineEventFileRecorderBase
Previous implementation allocated individual events and then
executed writes directly - both of these add unnecessary overhead.

Instead allocate and process events in blocks just like other
recorders and buffer writes in a temporary buffer before passing
data to Dart::file_write_callback().

Currently if you write something like this:

    int fib(int n) {
      return Timeline.timeSync('fib', () {
        // typical recursive fib implementation here.
      });
    }

    for (var i = 0; i < 1000; i++) {
      fib(10);
    }

and then run it with perfettofile recorder you end up waiting several
seconds before recorder is drained with program spending most time
doing small writes via File::WriteFully.

This is no longer the case after this change.

TEST=ci

Change-Id: I6a33ccdb1f293a94669ad0dd7d883837b86c8b6f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426861
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-05-07 08:13:17 -07:00
Alexander Aprelev 66a57a8c53 [gardening] Fix trampoline near jump to far jump.
Fuchsia has slightly more code in FfiCallbackTrampoline, so near jump don't work, has to be far jump.

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

Change-Id: Iaabdcfe59c821eeed00fff7faf1dbd661145922b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426905
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-05-07 07:47:59 -07:00
Vyacheslav Egorov a72f25effd [vm] Fix Profiler::UpdateRunningState
It was calling Profiler::Cleanup() to shut the profiler down but
Cleanup did nothing if FLAG_profiler is false. So we need to
adjust condition at the start of Cleanup().

TEST=pkg/dds/test/profiler_can_be_stopped_test.dart

Change-Id: I9921334d264c5cae879e37148d0d784494cb2d63
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426464
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-05-07 07:23:14 -07:00
Vyacheslav Egorov a6a99dc45f [vm] Fix issues in SampleBlockProcessor
This is follow up to commit cb0c2bf5ed.

SampleBlockProcessor only enters isolate group and not a specific
isolate so the code must not rely on thread->isolate(). This fixes two
places where this was not the case:

* ProfileBuilder::IsPCInDartHeap
* UserTags::TagName

pkg/dds/test/get_cached_cpu_samples_test was supposed to cover this but
it has two problems:

First I observed that SampleBlockProcessor never gets a chance to
process a block if mutator thread always gets to it first (via a
scheduled interrupt), so this code is not well exercised. I started by
adding a variant of the test where interrupts are inhibited via a
vm:unsafe:no-interrupts pragma - which revealed the crashes in the
SampleBlockProcessor code.

This revealed the second problem: get_cached_cpu_samples_test does not
actually fail if testee crashes during the test, it just silently
completes with success. This seems to happen because disposal of
VmService connection is not forwarded into the future on which the test
is awaiting - and the whole process just exits once VmService connection
to the testee disappears (because all ports are closed, no pending
activity is possible after that one). I have fixed this by adding a
helper function which checks that connection to VmService only goes away
when we dispose it.

Note: there is another obvious issue here, which I am leaving unfixed
for now. SampleBlockProcessor calls UserTags::TagName in a way that can
race with isolate itself modifying the table. I think this race is
extremely unlikely but it can cause crashes on ARMs with its weak memory
model (e.g. we might end up reading garbage due to the reordering of
stores).

TEST=pkg/dds/test/get_cached_cpu_samples_test

Change-Id: Iee15ec2b019928b798c312e63edc76696abf5527
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426300
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-05-07 07:18:41 -07:00
Alexander Aprelev 73971941f5 [gardening] Clean up fuchsia build for IsolateGroup shared callbacks.
Follow-up to 50e0e0d99d

TEST=ci

Change-Id: I48114f5677a010561638fedf37390479885c8eef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/427041
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-05-06 15:39:57 -07:00
Alexander Aprelev 50e0e0d99d [vm/shared] Introduce NativeCallable.isolateGroupShared
This method allows for synchronous execution of dart callbacks from native code. The execution happens on dart mutator thread, from which dart code can only access isolate-group variables - those which are tagged with .

Bug: https://github.com/dart-lang/sdk/issues/54530
Bug: https://github.com/dart-lang/sdk/issues/56841
Change-Id: Ia1a6b01327be493f003f1eea82e558bb6b147dd3
CoreLibraryReviewExempt: only internal library change
TEST=isolate_group_shared_callback_test
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422920
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-05-06 13:28:44 -07:00
Alexander Aprelev b32e5e5a91 [vm/shared] Throw AccessError when isolategroup mutator accesses static fields.
Sample snapshot size comparison before/after:

===
dart2js_aot.dart.snapshot before: 19946368
                          after:  19998800  (with flag turned on)
                          delta:     52432 0.26%
===

Bug: https://github.com/dart-lang/sdk/issues/54530
Bug: https://github.com/dart-lang/sdk/issues/56841
CoreLibraryReviewExempt: internal library change only
Change-Id: I34b1945c040bbad22cb3ec6fdb6e6776df31a82f
TEST=run_isolate_group_run_test.dart
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/422360
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-05-06 10:42:44 -07:00
Alexander Markov 4221de4e0a [vm] Fix memory leak in Scavenger::Scavenge
```
Direct leak of 8 byte(s) in 1 object(s) allocated from:
    #0 0x6281a99eb78d in operator new[](unsigned long) ../../../../../../llvm-llvm-project/compiler-rt/lib/asan/asan_new_delete.cpp:89:3
    #1 0x6281a9e5ba7d in dart::Scavenger::Scavenge(dart::Thread*, dart::GCType, dart::GCReason) out/ReleaseASANX64/../../runtime/vm/heap/scavenger.cc:1890:33
    #2 0x6281a9e29cfd in dart::Heap::CollectNewSpaceGarbage(dart::Thread*, dart::GCType, dart::GCReason) out/ReleaseASANX64/../../runtime/vm/heap/heap.cc:490:18
    #3 0x6281a9e2680f in dart::Heap::CollectGarbage(dart::Thread*, dart::GCType, dart::GCReason) out/ReleaseASANX64/../../runtime/vm/heap/heap.cc:564:7
    #4 0x6281a9e2680f in dart::Heap::AllocateNew(dart::Thread*, long) out/ReleaseASANX64/../../runtime/vm/heap/heap.cc:105:7
    #5 0x6281a9bfe991 in dart::Heap::Allocate(dart::Thread*, long, dart::Heap::Space) out/ReleaseASANX64/../../runtime/vm/heap/heap.h:73:16
```

Caused by https://dart-review.googlesource.com/c/sdk/+/426582.

TEST=tools/build.py --sanitizer=asan -ax64 -mrelease runtime

Change-Id: I8f863d53359fad07bcf9b30c8dd860c93b24c50f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426900
Reviewed-by: Ivan Inozemtsev <iinozemtsev@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Auto-Submit: Alexander Markov <alexmarkov@google.com>
2025-05-06 07:16:20 -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 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
Ivan Inozemtsev 29e33b00d0 Reland "watchOS target os"
This is a reland of commit 7ae1d75869

TEST=manual, no watchOS SDK on bots yet.

Original change's description:
> watchOS target os
>
> - add support for --os=watchos | --os=watchos_simulator
> - do not depend on perfetto if dart_support_perfetto is false
> - change the default value for dart_support_perfetto to !is_watchos
>
> To minimize changes and to avoid modifying third-party zlib BUILD file, is_watchos implies is_ios for now.
>
> TEST=manual, no watchOS SDK on bots yet.
>
> Cq-Include-Trybots: luci.dart.try:vm-mac-debug-arm64-try,vm-mac-release-arm64-try
> Change-Id: If2130068ef546162a07a9ba53f94b11ff25fb565
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415021
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>

Cq-Include-Trybots: luci.dart.try:vm-mac-debug-arm64-try,vm-mac-release-arm64-try
Change-Id: I2b50f7eb4da173627aeb4833b88a08712b278d9f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425523
Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-05-05 06:40:30 -07:00
Martin Kustermann 1504dc6362 [vm] Extend analyze_snapshot tool to emit more detailed information
In release builds most `Field` objects are tree shaken,
but if an instance field is e.g. a `late final` field then the `Field`
object is retained in the snapshot for the `LateInitializationError`
slow path. Though `Field` will not appear in `Class.fields()`, it
will only be referenced in the `ObjectPool`.

=> Instead of dumping `Class.fields()` we collect all `Field`s with
   the same owner and dump those (a superset of `Class.fields()`)

We dump more information for a `Field`: Whether it's a reference field
or unboxed field (in which case we dump what unboxed type it is). We
also dump field flags (e.g. `late`, `final`, `static`).

We also dump now a `instance_slots` property on the class which
describes every slot in the instance. If a slot in an instance
  * has a corresponding `Field` we emit `instance_field` type and
    the id of the `Field` object.
  * has no corresponding `Field` we emit a `unknown_slot` type
  * we emit whether the slot is a reference field

This brings the information the `analyze_snapshot` tool dumps closer to
what Blutter uses, but some differences remain, e.g.:

  * Blutter seems to scan constant instances of classes (if there's any)
    and tries to determine based on those constants what unboxed slots
    could mean.
    It may look at 8 bytes and "guess" whether it's more likely to be an
    integer or a double. (Side note: It doesn't consider
    `Float32x4`/`Float64x2`)
    => The guess can be incorrect, so we do not do that.

  * Blutter seems to scan constant instances of classes (if there's any)
    and tries to guess the type of a reference field based on what that
    constant's field points to.
    => The guess can be incorrect, so we do not do that.

go/dart-ama

TEST=vm/dart/analyze_snapshot_binary_test

Change-Id: I116560ba5e5f89d4349f2227362b8494e3af7a1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425261
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-05-05 01:04:25 -07:00
Alexander Markov 16909d8ccb [vm] Simplify evaluation of asserts
Since Dart 2, assert statements only accept bool conditions,
so evaluation of the assert condition can be simplified in the VM.

TEST=existing

Change-Id: I0f54ad66b9d9aef707fef4eac192128a3994e7c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425920
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-05-01 13:13:19 -07:00
Ryan Macnak fa35265af2 [vm, gc] Fix race between BlockForSafepoint and TryStealActiveMutator.
This race can result in the stolen bit becoming cleared and the same thread stolen from multiple tests.

TEST=vm/dart/isolates/many_isolates_blocked_at_process_run_sync_test
Change-Id: I737458ff48e9d01ddfe4e5a016ef57e4cbdbf292
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425740
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-04-30 16:02:59 -07:00
Alexander Aprelev 9fa0f081cd [vm] Remove redundant VerifyOriginId.
It was made redundant by 69485e9b28, which started using isolate group id as origin id. It is populated by different random generator than the one used for isolate id.

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

Change-Id: I42545f8a491dbaa7e8b7f636df929522b4499990
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425700
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-04-30 14:00:50 -07:00
Alexander Markov 77e6cdc259 [dyn_modules] Handle interpreter frames during deoptimization
TEST=tools/test.py -n vm-dyn-linux-debug-x64 corelib/bigint_test
Fixes b/406924438

Change-Id: I621c31af7754c629e577e39b2ee4102533fa1363
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425341
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-04-30 06:42:56 -07:00
Ryan Macnak 077d7c9e89 [vm] Don't acquire safepoint locks while participating in reload safepoints.
Also disable lint intended to guard against use of std::thread::detach as it has too many false positives against dart::FinalizerEntry::detach.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/60638
Change-Id: I19a0fde743fc5c5658a8dd96cecb5b074481a035
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425324
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-04-29 16:23:20 -07:00
Ivan Inozemtsev 10c579c7e8 Revert "watchOS target os"
This reverts commit 7ae1d75869.

Reason for revert: breaks flutter build

Original change's description:
> watchOS target os
>
> - add support for --os=watchos | --os=watchos_simulator
> - do not depend on perfetto if dart_support_perfetto is false
> - change the default value for dart_support_perfetto to !is_watchos
>
> To minimize changes and to avoid modifying third-party zlib BUILD file, is_watchos implies is_ios for now.
>
> TEST=manual, no watchOS SDK on bots yet.
>
> Cq-Include-Trybots: luci.dart.try:vm-mac-debug-arm64-try,vm-mac-release-arm64-try
> Change-Id: If2130068ef546162a07a9ba53f94b11ff25fb565
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415021
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>

Cq-Include-Trybots: luci.dart.try:vm-mac-debug-arm64-try,vm-mac-release-arm64-try
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I4bede9ede04ac3c533b8ff7ae2f1adbd84eb2397
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425262
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Commit-Queue: Alexander Thomas <athom@google.com>
Auto-Submit: Ivan Inozemtsev <iinozemtsev@google.com>
2025-04-29 03:21:37 -07:00
Ivan Inozemtsev 7ae1d75869 watchOS target os
- add support for --os=watchos | --os=watchos_simulator
- do not depend on perfetto if dart_support_perfetto is false
- change the default value for dart_support_perfetto to !is_watchos

To minimize changes and to avoid modifying third-party zlib BUILD file, is_watchos implies is_ios for now.

TEST=manual, no watchOS SDK on bots yet.

Cq-Include-Trybots: luci.dart.try:vm-mac-debug-arm64-try,vm-mac-release-arm64-try
Change-Id: If2130068ef546162a07a9ba53f94b11ff25fb565
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/415021
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ivan Inozemtsev <iinozemtsev@google.com>
2025-04-29 02:28:52 -07:00