Commit Graph

341 Commits

Author SHA1 Message Date
Ryan Macnak 894a5fa7d5 [vm, mac] Disable TSAN during profiler sample collection.
The suspended thread might hold a TSAN-internal lock to a location that will be read by the sampling thread, which would cause a dead lock.

TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/62332
Change-Id: I0ac6a05c25067749b52ed83b14f80ab1850013a3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471321
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-01-07 12:47:21 -08:00
Slava Egorov d47c8388aa [vm] Avoid deadlocks in SampleBlockProcessor
Processor thread might end up entering a safepoint while holding the
processor's monitor which will make thread calling Cleanup deadlock
while trying to acquire the monitor.

Use SafepointMonitorLocker instead to avoid this. Startup is unlikely
to exhibit this situation but we change it as well for symmetry.

TEST=manually, as reliably hitting this is hard

Change-Id: Ifb88a0418be064450374503bfc485e576a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/467801
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-12-12 03:30:33 -08:00
Slava Egorov badeb15e5d [vm] Do not interrupt mutator when SampleBlock is complete
This code was added when samples streaming was implemented and should
not be necessary. Let background thread drain samples instead.

This significantly reduces the overhead of activating profiler when
using NativeRuntime.streamTimelineTo from 2-3x to ~10% in AOT mode
and around ~20-25% in JIT.

TEST=ci

Change-Id: I4c6026f832d6a952b24323632b4126df6a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464183
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-11-24 13:29:52 -08:00
Alexander Markov bfb0766bdf [vm] Fix msvc product build
Fixes the following build error:

```
libdart_vm_precompiler.profiler.obj : error LNK2019: unresolved external symbol "public: static class dart::Sample * __cdecl dart::SampleBlock::ReserveSampleAndLink(class dart::Sample *,class dart::Isolate *)" (?ReserveSampleAndLink@SampleBlock@dart@@SAPEAVSample@2@PEAV32@PEAVIsolate@2@@Z) referenced in function "public: bool __cdecl dart::ProfilerStackWalker::Append(unsigned __int64,unsigned __int64)" (?Append@ProfilerStackWalker@dart@@QEAA_N_K0@Z)
```

TEST=vm-msvc-win-x64-try, vm-msvc-win-arm64-try

Change-Id: I0819a15c6201deb7933ebe01690a80e8d083134d
Cq-Include-Trybots: luci.dart.try:vm-msvc-win-arm64-try,vm-msvc-win-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460140
Auto-Submit: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-11-06 12:49:19 -08:00
Slava Egorov 270bc0855a [vm] Exclude timeline from Flutter linux release engine
This undoes size regression introduced 
commit 489f63a3bd

This also exclude timeline from Dart binaries built
in PRODUCT mode - but not from PRODUCT AOT runtime
built as part of normal SDK.

This CL also fixes the build with DART_DISABLE_TIMELINE.

TEST=manually by building Linux engine

Change-Id: Ie43826ea4150aac6bdb686f37215ba0c6a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459600
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-11-05 01:08:20 -08:00
Ryan Macnak 7e28e7d504 [profiler] Don't read from a previous block when a sample overflows to the another block.
TEST=dartfuzz
Bug: https://github.com/dart-lang/sdk/issues/61904
Change-Id: I0fd5176502e0d11c5af35f5c27653db8cc294eff
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/459523
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-11-04 13:14:10 -08:00
Ryan Macnak 3a46c47601 [vm] Don't feed the simulator's registers into ProfilerNativeStackWalker.
Default the simulators to --no-profile-vm same as the non-simulators.

TEST=vm/dart/stream_timeline_to_test
Bug: https://github.com/dart-lang/sdk/issues/61811
Change-Id: I26cf956e240ffa542f3d52345e680404bc2d2021
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457840
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-27 14:34:39 -07:00
Vyacheslav Egorov 489f63a3bd [vm] Add NativeRuntime.streamTimelineTo
This API allows to programmatically generate timeline information 
including profiling samples if timeline format supports it.

This change also includes Perfetto timeline writer and profiler 
into non-mobile PRODUCT builds. The size of Mac OS X dartaotruntime
has increased by 34352 bytes (0.7%).

This relands commit 553887bc56 with fixes
for Android builds.

TEST=vm/dart/stream_timeline_to_test

CoreLibraryReviewExempt: VM specific dart:developer API.
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-product-arm-try,vm-ffi-android-release-arm-try,vm-aot-android-release-arm64c-try
Change-Id: Ifb7c66982fe9d17d2f5c9acb163a94c56a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457301
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2025-10-24 04:34:01 -07:00
Slava Egorov b24698b9b5 Revert "[vm] Add NativeRuntime.streamTimelineTo"
This reverts commit 553887bc56.

Reason for revert: Broken android builds

Original change's description:
> [vm] Add NativeRuntime.streamTimelineTo
>
> This API allows to programmatically generate timeline information 
> including profiling samples if timeline format supports it.
>
> This change also includes Perfetto timeline writer and profiler 
> into non-mobile PRODUCT builds. The size of Mac OS X dartaotruntime
> has increased by 34352 bytes (0.7%).
>
> TEST=vm/dart/stream_timeline_to_test
>
> CoreLibraryReviewExempt: VM specific dart:developer API.
> Change-Id: I326f5fd29ee82a503160f5f5a2a857a7c55330ec
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426220
> Reviewed-by: Ryan Macnak <rmacnak@google.com>
> Commit-Queue: Slava Egorov <vegorov@google.com>

No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Change-Id: I583ad74b850514fb47054149da464a07874fc2f6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457000
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
2025-10-23 04:58:29 -07:00
Vyacheslav Egorov 553887bc56 [vm] Add NativeRuntime.streamTimelineTo
This API allows to programmatically generate timeline information 
including profiling samples if timeline format supports it.

This change also includes Perfetto timeline writer and profiler 
into non-mobile PRODUCT builds. The size of Mac OS X dartaotruntime
has increased by 34352 bytes (0.7%).

TEST=vm/dart/stream_timeline_to_test

CoreLibraryReviewExempt: VM specific dart:developer API.
Change-Id: I326f5fd29ee82a503160f5f5a2a857a7c55330ec
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/426220
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-10-23 04:47:13 -07:00
Ryan Macnak d61d6adaf6 [vm] More TSAN profiler issues.
TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/61594
Change-Id: I82598218a98b764d66deb671f8ec841c8e1c3cab
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452280
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-09-29 21:54:41 -07:00
Ryan Macnak 7271e104a2 [vm] More profiler false-positives under Mac TSAN.
TEST=tsan
Cq-Include-Trybots: luci.dart.try:vm-tsan-mac-release-arm64-try
Change-Id: Ic7c2e1bfbe996d61efa48501ad0fd9f1c11149da
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451123
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-09-24 09:25:41 -07:00
Ryan Macnak 73c29770fa [vm] More workarounds for false-positives in the profiler due to TSAN not understanding thread_suspend.
TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/61509
Change-Id: I4e8e2d949f4df88bb401dbe5997b59491988c05a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450102
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-09-17 11:03:00 -07:00
Ryan Macnak 6f4a9bd481 [vm] Work around missing TSAN support for thread_suspend.
TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/61478
Change-Id: I700f36eb07c998993682f046d82bbc9d04847f9c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449074
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-09-15 10:00:44 -07:00
Alexander Aprelev 2d7c7b039c [vm/usertag] Move usertags from Isolate to Thread.
This allows use of usertag api in isolategroup-bound context.

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

Change-Id: I73d5631ba6eddcc06965b982bc199221ac021cd5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445967
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-08-25 14:43:41 -07:00
Derek Xu ad27629118 [VM] Delete streamable_ field from UntaggedUserTag
TEST=CI

Issue: https://github.com/dart-lang/sdk/issues/61267
Change-Id: I5ae405b2edbe478b6a14aa2416e8e4ee590349cf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445520
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2025-08-20 08:13:47 -07:00
Derek Xu 9b89266f43 [VM] Introduce --profile-startup CLI flag
TEST=pkg/vm_service/test/profile_startup_cli_flag_test

Change-Id: I39bf67bf3157fe5700f1a62822f1dc3159c9bc96
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438980
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2025-07-24 12:04:17 -07:00
Alexander Markov 58c09c24ed [vm,dyn_modules] Fix Dart stack dump for crashes in the interpreter
When crash happens in the interpreter while running Dart code,
Dart stack dump should start with the interpreter frame instead of
using crash sp/fp/pc. (Native stack dump still uses crash sp/fp/pc.)

TEST=manual

Change-Id: I8748d3f9c683fcc0cbda949ff7619981c9f3f134
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/+/441821
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-07-22 11:35:51 -07:00
Derek Xu 4a73fed7c5 [VM/Profiler] Fix Profiler::CalculateSampleBufferCapacity
This CL corrects a calculation in
`Profiler::CalculateSampleBufferCapacity` by semantically changing it
from `floor(FLAG_max_profile_depth / kMaxSamplesPerTick)` to
`ceil(FLAG_max_profile_depth / Sample::kPCArraySizeInWords)`.

This CL also makes the help message for `--max_profile_depth` consistent
with the logic in `Profiler::SetSampleDepth`.

TEST=CI, pkg/vm_service/test/profile_startup_cli_flag_test which will be
added in https://dart-review.googlesource.com/c/sdk/+/438980

Change-Id: Iae440cec74f8b84c927eca085a66d962b6745a7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/439360
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2025-07-21 11:05:41 -07:00
Ryan Macnak fc345a7ead [vm] Also attempt a stack walk for crashes in the generated safepoint state.
TEST=ci
Change-Id: I87e8ca974b915d25b8a3e84c331af9e6345f0e5a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/440320
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-07-15 09:31:25 -07:00
Ryan Macnak a3bb94210c [vm] Fix stack traces from ASSERT/FATAL.
TEST=vm/dart/symbolized_crash_test
Bug: https://github.com/dart-lang/sdk/issues/60987
Cq-Include-Trybots: luci.dart.try:vm-linux-release-arm64-try,vm-aot-linux-release-arm64-try
Change-Id: I6e1859a99079087161d5af8a10d1728277740218
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/436760
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-06-25 09:44:11 -07:00
Alexander Markov e0c561cf13 [dyn_modules] Support interpreted frames in the profiler
TEST=pkg/vm_service/test

Change-Id: Iba7b8e78feeff888eb0657a6e3790602a8b3d7ca
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/+/435240
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-06-23 06:45:22 -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
Ryan Macnak f5eaefd5b6 [vm] Runtime option to not use the simulator for simarm64_arm64.
TEST=ci
Cq-Include-Trybots: luci.dart.try:vm-ffi-mac-debug-simarm64_arm64-try,vm-ffi-mac-release-simarm64_arm64-try
Change-Id: Id98d337ce16ba4b434b5c69016f01eec9b85f9d2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/434982
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-06-18 10:45:05 -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
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
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
Derek Xu 0a7aae2648 [VM/Profiler] Correctly apply the value of --profile-period specified on the CLI
TEST=Verified that pkg/vm_service/test/profile_period_cli_option_test
passes with the changes in this CL and fails without them.

Change-Id: Ic36014abe682f9b4c829317b59bb664683e12d7e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/412781
Commit-Queue: Derek Xu <derekx@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2025-02-28 10:26:02 -08:00
Alexander Markov f37db8487f [vm] Double check if thread interrupts are enabled after thread is interrupted
Thread interrupts can be disabled after thread interrupter decided to
interrupt a thread but before thread actually receives and handles
a signal.

This may cause a data race accessing a Sample between profiler which
initializes and adds a Sample and the main thread using
Profiler::sample_block_buffer() in the profiler unit tests.

This is a possible fix for the following benign TSAN error:

WARNING: ThreadSanitizer: data race (pid=5824)
  Write of size 4 at 0x7f53e8e53a98 by thread T6:
    #0 dart::Sample::set_thread_task(dart::Thread::TaskKind) out/ReleaseTSANX64/../../runtime/vm/profiler.h:325:12 (run_vm_tests+0x292cab2)
    #1 dart::SetupSample(dart::Thread*, bool, unsigned long) out/ReleaseTSANX64/../../runtime/vm/profiler.cc:1226:11 (run_vm_tests+0x292cab2)
    #2 dart::Profiler::SampleThread(dart::Thread*, dart::InterruptedThreadState const&) out/ReleaseTSANX64/../../runtime/vm/profiler.cc:1381:7 (run_vm_tests+0x292cab2)
    #3 dart::ThreadInterrupterLinux::ThreadInterruptSignalHandler(int, siginfo_t*, void*) out/ReleaseTSANX64/../../runtime/vm/thread_interrupter_linux.cc:44:5 (run_vm_tests+0x2a064b0)
    #4 __tsan::CallUserSignalHandler(__tsan::ThreadState*, bool, bool, int, __sanitizer::__sanitizer_siginfo*, void*) ../staging/llvm_build/tools/clang/stage2-bins/runtimes/runtimes-x86_64-unknown-linux-gnu-bins/compiler-rt/lib/tsan/rtl/tsan_interceptors_posix.cpp:2122:5 (run_vm_tests+0x1fc057f)
    #5 dart::Mutex::Unlock() out/ReleaseTSANX64/../../runtime/vm/os_thread_linux.cc:367:16 (run_vm_tests+0x2924b89)

  Previous read of size 4 at 0x7f53e8e53a98 by main thread:
    #0 dart::Sample::head_sample() const out/ReleaseTSANX64/../../runtime/vm/profiler.h:350:59 (run_vm_tests+0x22c70e7)
    #1 dart::SampleBuffer::VisitSamples(dart::SampleVisitor*) out/ReleaseTSANX64/../../runtime/vm/profiler.h:589:20 (run_vm_tests+0x22c70e7)
    #2 dart::SampleBlockBuffer::VisitSamples(dart::SampleVisitor*) out/ReleaseTSANX64/../../runtime/vm/profiler.h:752:18 (run_vm_tests+0x22c70e7)
    #3 dart::Dart_TestHelperProfiler_GetSourceReport(dart::Thread*) out/ReleaseTSANX64/../../runtime/vm/profiler_test.cc:2241:26 (run_vm_tests+0x22c70e7)
    #4 dart::Dart_TestProfiler_GetSourceReport() out/ReleaseTSANX64/../../runtime/vm/profiler_test.cc:2206:1 (run_vm_tests+0x22c70e7)
    #5 dart::TestCase::Run() out/ReleaseTSANX64/../../runtime/bin/run_vm_tests.cc:53:3 (run_vm_tests+0x203fe6c)

--- Re-run this test:
python3 tools/test.py -n vm-tsan-linux-release-x64 vm/cc/Profiler_GetSourceReport

Also, this change is a possible fix for https://github.com/dart-lang/sdk/issues/44089.

TEST=ci

Change-Id: I8ad87c340580325cbd6e22b5f068e1e33b0a7d46
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409460
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-02-12 14:48:28 -08:00
Ryan Macnak b2eec8b759 [vm, profiler] Also use alignment to detect invalid frame pointers.
TEST=ubsan
Change-Id: Ie4742c82c2ca5de5e4283914dd5098bf4c325e5b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/375063
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-07-10 16:31:19 +00:00
Ryan Macnak f5fe3dddcc [vm] Avoid strdup during the segfault handler.
malloc is not signal-safe.

TEST=tsan
Change-Id: I8bd6cae743b7ae2d64525f4e88fb412373d4e3df
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/365187
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-05-02 16:36:20 +00:00
Ryan Macnak dfe009cace [vm] Make Dart_DumpNativeStackTrace work if called before VM startup.
TEST=add crash to VM
Change-Id: I6188cee39cdea4075eedee9f1ad176ea1008f21b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363643
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
2024-05-01 20:13:07 +00:00
Ryan Macnak 5187dbfffe [vm] Update gdb helpers.
- Take raw addresses instead of ObjectPtr. gdb seems to sometimes not understand how to do the cast.
 - Use newer "retain" attribute to disable linker GC instead of exporting a dynamic symbol.
 - Add helper to get the current thread. Directly accessing dart::OSThread::current_vm_thread_ doesn't work.
 - Add helper to find the function or stub for a PC and disassemble.

TEST=gdb
Change-Id: I3825a820194673a9a9d5153cd0e0cf175acab5f4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/363403
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2024-04-18 16:35:58 +00:00
Ryan Macnak 9c0b1e06db [vm, profiler] Remove race between sample processor and stub code initialization.
TEST=tsan
Bug: https://github.com/dart-lang/sdk/issues/54226
Change-Id: I54ce983acae28474c4a31200922b902dd19cf95d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339643
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-12-05 17:29:05 +00:00
Ryan Macnak f59650497a [vm] Don't hold a group's isolates_lock_ while attempting to enter the group as a helper thread.
Avoids a three-way deadlock:
  existing isolate waiting for new isolate to reach reload safepoint
  new isolate waiting for sample processor to release isolates_lock_
  sample processor waiting for existing isolate to finish safepoint

TEST=reload bots
Bug: https://github.com/dart-lang/sdk/issues/54104
Change-Id: If4343293b94103d940d6a2f91904a14c6cb375b4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/337401
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-11-28 22:02:31 +00:00
Ryan Macnak 1569e88983 [vm] Attempt to symbolize JIT frames during a crash with no exit frame.
TEST=broke some stub code
Bug: https://github.com/dart-lang/sdk/issues/53952
Change-Id: I9fcd4315857805bd19228d5c8ce23c6b132270af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335951
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-11-15 18:48:27 +00:00
Ryan Macnak f36c109471 [vm, profiler] Don't assume the isolate has a mutator during a profile sample.
A sample can be taken when Thread::Current() and Thread::Current()->isolate() are non-NULL. When a thread is entering or exiting an isolate, the is a brief window between the TLS being set/cleared and Isolate::mutator_thread_ being set/cleared.

TEST=vm/cc/Profiler_EnterExitIsolate
Bug: https://github.com/flutter/flutter/issues/134548
Change-Id: I7a6b25dabf930e8480d1a85d7f24c4765fc36b15
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/328380
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2023-10-02 17:57:33 +00:00
Ryan Macnak b8ee3a9996 [build] Don't export all symbols to the dynamic table.
We were exporting all symbols to the dynamic table so that they could be looked up using `dladdr` for the profiler and backtracer. The symbols include our statically-linked libcxx, which can create trouble when another DSO has a different version of libcxx. Now we export only the VM embedding API functions (`Dart_*`) and use a specially produced table to do the symbolization.

TEST=runtime/tests/vm/dart/exported_symbols_test.dart
TEST=runtime/tests/vm/dart/symbolized_crash_test.dart
Bug: https://github.com/dart-lang/sdk/issues/53267
Change-Id: I2ee494fba86f67127ba0f6f402622f01a4662207
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/323702
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-09-05 21:47:59 +00:00
Derek Xu cb0c2bf5ed [VM/Profiler] Remove invalid calls to Thread::Current()::isolate()
Thread::EnterIsolateAsHelper was removed in
https://dart-review.googlesource.com/c/sdk/+/295940, so we now need to
pass isolate pointers through more function calls.

TEST=Ran pkg/dds/test/get_cached_cpu_samples_test in debug mode, in
release mode with TSAN, and in release mode with ASAN.

Fixes: https://github.com/dart-lang/sdk/issues/52796
Change-Id: Ib0187fb8551628c7b7606a3a5fa9385d26e097d6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/321500
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Derek Xu <derekx@google.com>
2023-08-17 18:51:19 +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 779e51efc1 [vm] Remove Thread::{Enter,Exit}IsolateAsHelper
For every isolate there should be only one mutator with
a unique [Thread] object.

We change existing tests that use this functionality to instead use
`Thread::{Enter,Exit}IsolateGroupAsHelper`. It also results in a net
removal of code.

TEST=ci

Change-Id: Ic326e868a98ddedbab5b8c429252d38ea71bbf04
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/295940
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2023-04-19 09:36:41 +00:00
Ryan Macnak 2bfecc160b [vm] Update to constexpr in runtime/vm.
TEST=build
Change-Id: I2dd8ae69764af27f480a19995b491e98f52476ae
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293902
Reviewed-by: Liam Appelbe <liama@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-04-12 22:18:54 +00:00
Ryan Macnak 96fd0b2208 [vm, gc] Avoid duplicate pointer visiting functions when compressed pointers are disabled.
This reduces code size ~10k, but more importantly it is easier to read profiling results without duplicate entries.

TEST=ci
Change-Id: I14c4a0d78d856242c5493df6de629ce048753c38
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/294440
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2023-04-11 17:36:33 +00:00
Ryan Macnak 1eae028526 [vm] Fix zero-as-null-pointer-constant warnings in the VM.
Unfortunately we cannot enable -Wzero-as-null-pointer-constant because of zlib and icu headers we include.

TEST=build
Change-Id: I9ffd7d7e26f2b3dd616ce54d164b92e60a2366dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/293882
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2023-04-10 21:38:57 +00:00
Ryan Macnak f9a6a5bdd2 [vm] Update NULL to nullptr in runtime/vm.
TEST=build
Change-Id: I2834ef7cf7cb7c8770f8167a2438cbedcee5c623
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/292063
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2023-04-10 18:15:12 +00:00
Ryan Macnak 90ff190627 [vm] Remove malloc profiler.
Splitting c67fac9cb4.

TEST=ci
Change-Id: Ib42d861e458648ce810be44cea0734c244703c1c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/287000
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-03-06 21:00:30 +00:00
Daco Harkes b1e59721d4 Revert "[vm] Remove tcmalloc and malloc profiler."
This reverts commit c67fac9cb4.

Reason for revert: Regresses `dart:io` performance and causes
failures.
https://github.com/dart-lang/sdk/issues/51639

Original change's description:
> [vm] Remove tcmalloc and malloc profiler.
>
> The standalone VM originally began statically linking tcmalloc to work around bugs in the system malloc for Fiber. Later it used tcmalloc's hooks to implement a profiler, but this is rarely used since it is only available in debug mode, misses early allocations, and often misses late allocations from an exhausted sample buffer. Removing it altogether avoids build complexity around which combinations of compiler/architecture/sysroot support tcmalloc, and reduces binary size.
>
> TEST=ci
> Change-Id: I4b259e18b82b2d12a2a60962aabf83bd8d997d19
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286120
> Reviewed-by: Ben Konyi <bkonyi@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

Change-Id: I4395edd6f5bd7e26b4e38f4d931ad2ea67afba18
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286925
Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2023-03-06 10:28:33 +00:00
Ryan Macnak c67fac9cb4 [vm] Remove tcmalloc and malloc profiler.
The standalone VM originally began statically linking tcmalloc to work around bugs in the system malloc for Fiber. Later it used tcmalloc's hooks to implement a profiler, but this is rarely used since it is only available in debug mode, misses early allocations, and often misses late allocations from an exhausted sample buffer. Removing it altogether avoids build complexity around which combinations of compiler/architecture/sysroot support tcmalloc, and reduces binary size.

TEST=ci
Change-Id: I4b259e18b82b2d12a2a60962aabf83bd8d997d19
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/286120
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-03-03 23:32:12 +00:00
Ryan Macnak 8949974caf [vm] Remove unnecessary check for compaction from the profiler.
The PC marker slots are transiently invalid during a compaction, but the profiler's stack walker no longer uses them, as they are completely absent in bare instructions mode.

TEST=ci
Change-Id: I3dba373ccccaba48e6dcc2b01d48e5e75620a4db
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284744
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-02-24 03:39:05 +00:00
Ryan Macnak 789a5061ac [vm] Remove redundant register check.
This was once necessary because we did not reliably discover the stack bounds.

TEST=ci
Change-Id: I56e81b5854f6b7313384363647a94340d7f904fc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/284743
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2023-02-24 00:02:26 +00:00