Commit Graph

32 Commits

Author SHA1 Message Date
Corey Tabaka db0fa84d59 [vm] Optimize get current thread id in Fuchsia.
OSThread::GetCurrentThreadId() is used in many places throughout
the vm, particularly in facilities that are used heavily, such as
SafepointRwLock. The high frequency of invocations means that the
runtime overhead of getting the current thread id has a significant
impact on the overall performance of the vm.

The current Fuchsia implemention of OSThread::GetCurrentThreadId()
makes a syscall to get the koid of the current thread's handle,
resulting in hundreds of nanoseconds of unnecessary overhead per
invocation.

This patch changes to using the thread's handle as the id, which is
guaranteed to be unique for the lifetime of the thread, unless it
is closed prematurely (nothing in the vm does this). This approach
is similar to what MUSL libc (the libc used by Fuchsia) does for
the same purpose and has significant mileage.

Bug: b/182183059
TEST=existing ci test suite; manually deployed into Fuchsia build.

Change-Id: I274a793a823a717c8dd206b396001c6acb897b9a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/193643
Reviewed-by: Chase Latta <chaselatta@google.com>
Commit-Queue: Chase Latta <chaselatta@google.com>
2021-03-31 20:51:32 +00:00
Ryan Macnak f0b2a46734 [vm, fuchsia, arm64] Restore the shadow call stack on exceptions.
Fuchsia is about to turn on ShadowCallStack for ARM64. Once this is enabled, we need to treat R18 like a preserved register. Generated Dart has not accessed this register because it is reserved on iOS, and in the absence of Dart exceptions this would be sufficient for us to be ShadowCallStack compatible. However, our exception handling mechanism jumps past all the C++ frames between the Dart exit frame and Exceptions::JumpToFrame, skipping code that would pop from R18.

Add save/restore of R18 in the invocation stubs, and restore of R18 in the jump stub. The latter prevents the ShadowCallStack from overflowing for code that has lots of exceptions without a native call.

Bug: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=37449
Change-Id: I2ce6e46624c8d72507e7afa7a44839b1f0def556
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/119481
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2019-10-02 05:33:29 +00:00
Adam Barth 8a3a9dc588 [fuchsia] Migrate to zx_clock_get_new
Change-Id: Ibf9210e3965e77ff56d244cfd67dbccfb1eef3f0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/102104
Auto-Submit: Adam Barth <abarth@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
2019-05-10 18:22:28 +00:00
Ryan Macnak 0f24b9e7ae [standalone] Name dart:io threads, take 2.
Mac's pthread_setname_np assumes the current thread.

Bug: US-588
Change-Id: Ibbddd1f7bffeab10fd470a6176f68b1c0440aa99
Reviewed-on: https://dart-review.googlesource.com/c/93120
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-02-13 20:29:46 +00:00
Ryan Macnak d566a674d0 Revert "[standalone] Name dart:io threads."
This reverts commit cc3218b771.

Reason for revert: Mac build

Original change's description:
> [standalone] Name dart:io threads.
> 
> Change-Id: I5f5248366b39afab96a8b70b4f107ec5134b84f4
> Reviewed-on: https://dart-review.googlesource.com/c/92960
> Reviewed-by: Zach Anderson <zra@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

TBR=rmacnak@google.com,zra@google.com,asiva@google.com

Change-Id: I9071c955d4710f8146a661d15fa980f237b6eb81
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/93064
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-02-13 18:04:49 +00:00
Ryan Macnak cc3218b771 [standalone] Name dart:io threads.
Change-Id: I5f5248366b39afab96a8b70b4f107ec5134b84f4
Reviewed-on: https://dart-review.googlesource.com/c/92960
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-02-13 17:23:56 +00:00
Ryan Macnak 06a1e6e9e3 [vm] Enable timeline on Fuchsia even in product mode.
On Fuchsia, the timeline is accessed without involving the service isolate or vm-service.

Change-Id: Ia0d4e1ca252604e8fcef466a31e3d2a8b0912251
Reviewed-on: https://dart-review.googlesource.com/c/90100
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-01-18 00:06:10 +00:00
Ryan Macnak 07f95e7761 Revert "[vm] Enable timeline on Fuchsia even in product mode."
This reverts commit 3f7b371f2c.

Reason for revert: Some modes failing to find new constant?

Original change's description:
> [vm] Enable timeline on Fuchsia even in product mode.
> 
> On Fuchsia, the timeline is accessed without involving the service isolate or vm-service.
> 
> Change-Id: I0d2351dcadcfc47835732235e1b8fafa8212f883
> Reviewed-on: https://dart-review.googlesource.com/c/89880
> Reviewed-by: Zach Anderson <zra@google.com>
> Commit-Queue: Ryan Macnak <rmacnak@google.com>

TBR=rmacnak@google.com,alexmarkov@google.com,zra@google.com,asiva@google.com

Change-Id: Ic03a78d14821e0361d54587f1f7510bc9ebfef1c
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/c/89942
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-01-17 00:39:39 +00:00
Ryan Macnak 3f7b371f2c [vm] Enable timeline on Fuchsia even in product mode.
On Fuchsia, the timeline is accessed without involving the service isolate or vm-service.

Change-Id: I0d2351dcadcfc47835732235e1b8fafa8212f883
Reviewed-on: https://dart-review.googlesource.com/c/89880
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2019-01-16 22:55:51 +00:00
Adam Barth 85b73ddd40 [fuchsia] Migrate from zx_time_get to zx_clock_get
Change-Id: I498d751037ae240cb639d30adc125e0b14d756ef
Reviewed-on: https://dart-review.googlesource.com/36321
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Zach Anderson <zra@google.com>
2018-01-22 22:46:35 +00:00
Zachary Anderson f97e11f624 [Fuchsia] Safestack fix for exceptions
The safestack stack pointer is cached when invoking Dart code, and
manually restored when jumping over C++ frames for Dart exceptions
in Exceptions::JumpToFrame().

fixes #31356

Change-Id: I71c2e86d1d4f24571dd618a5db06fd1277339ebc
Reviewed-on: https://dart-review.googlesource.com/23141
Commit-Queue: Zach Anderson <zra@google.com>
Reviewed-by: Vyacheslav Egorov <vegorov@google.com>
2017-11-22 19:27:54 +00:00
Ryan Macnak b85a7fecd0 Reapply "[vm] Prefer stack bounds from the system thread library for overflow checks."
Mark some profiler tests on Windows as failing.

Bug: https://github.com/dart-lang/sdk/issues/31137
Change-Id: I46a5d4838443e5cfdac6043ea8dcfeb3d05d4823
Reviewed-on: https://dart-review.googlesource.com/14920
Reviewed-by: Zach Anderson <zra@google.com>
2017-10-18 21:15:49 +00:00
Dmitry Stefantsov a227b168da Revert "Reapply "[vm] Prefer stack bounds from the system thread library for overflow checks.""
This reverts commit 5a022b9db6.

The reverted CL caused some redness on some vm and vm-precomp bots.

TBR=rmacnak@google.com
Change-Id: I9be670f3c3e341ec6d95082f288bc569834e38c7
Reviewed-on: https://dart-review.googlesource.com/13460
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Karl Klose <karlklose@google.com>
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
2017-10-12 07:32:30 +00:00
Ryan Macnak 5a022b9db6 Reapply "[vm] Prefer stack bounds from the system thread library for overflow checks."
Fix accounting of guard pages to move the stack limit up instead of down.

Change-Id: I2f6577a12cf95707c186884f0bd3def03eac12ed
Reviewed-on: https://dart-review.googlesource.com/13381
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2017-10-12 02:17:11 +00:00
Ryan Macnak 6ecf6dd0a3 Revert "[vm] Prefer stack bounds from the system thread library for overflow checks."
This reverts commit af251ddfec.

Reason for revert: Crashes on Windows.

Original change's description:
> [vm] Prefer stack bounds from the system thread library for overflow checks.
> 
> Before this change, we would assume all stacks have the size the VM specifies for threads it creates, but this won't be accurate for the initial thread or threads created by the embedder.
> 
> Change-Id: I6605a88d6666a6f9d47fbe047d3fdd02aa22c80a
> Reviewed-on: https://dart-review.googlesource.com/10209
> Reviewed-by: Zach Anderson <zra@google.com>

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

Change-Id: I96eaccdc8edf6e3d319827a63d168534bad0518e
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Reviewed-on: https://dart-review.googlesource.com/13106
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2017-10-11 21:17:28 +00:00
Ryan Macnak af251ddfec [vm] Prefer stack bounds from the system thread library for overflow checks.
Before this change, we would assume all stacks have the size the VM specifies for threads it creates, but this won't be accurate for the initial thread or threads created by the embedder.

Change-Id: I6605a88d6666a6f9d47fbe047d3fdd02aa22c80a
Reviewed-on: https://dart-review.googlesource.com/10209
Reviewed-by: Zach Anderson <zra@google.com>
2017-10-11 19:35:44 +00:00
Zachary Anderson 485b737fc5 [Fuchsia] Set VM thread names
For example, this will cause thread pool threads to be named
"Dart ThreadPool Worker" in the system trace.

FL-25

Change-Id: I929ca51daef58217042a2f64491fee6fe8112ad5
Reviewed-on: https://dart-review.googlesource.com/9002
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2017-09-28 15:09:24 +00:00
George Kulakowski 7800d2a995 Rename Magenta to Zircon, along with related abbreviations
Change-Id: Ic4215ceb00f5a60d21ec1398fd398a9f78a9eb94
Reviewed-on: https://dart-review.googlesource.com/6100
Reviewed-by: Zach Anderson <zra@google.com>
2017-09-15 14:54:18 +00:00
Vyacheslav Egorov c25ebfff96 [VM, Platform] Allow assigning names to mutexes.
Use this name when reporting errors.

We need this sort of debug information to better understand Isolate shutdown races like one in https://github.com/dart-lang/sdk/issues/28549

Bug: https://github.com/dart-lang/sdk/issues/28549
Change-Id: I24f27b4eef4faf4b2f80f82b269d88a6e5c3880b
Reviewed-on: https://dart-review.googlesource.com/4721
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
Reviewed-by: Zach Anderson <zra@google.com>
2017-09-11 19:17:46 +00:00
Zachary Anderson 6cd8a79078 VM: Re-format to use at most one newline between functions
R=asiva@google.com

Review-Url: https://codereview.chromium.org/2974233002 .
2017-07-13 08:08:37 -07:00
Zachary Anderson a834e6dcf3 Update Fuchsia-specific code to use the new MX_ error names
R=zra@google.com

Review-Url: https://codereview.chromium.org/2935483002 .
2017-06-09 13:19:54 -07:00
Zachary Anderson 5e8799ce81 [Fuchsia] Enable CPU profiling for the standalone VM
R=asiva@google.com

Review-Url: https://codereview.chromium.org/2916313003 .
2017-06-05 14:45:41 -07:00
Zachary Anderson 904aefe6e3 [Fuchsia] Implements the thread interrupter for CPU profiling.
R=asiva@google.com

Review-Url: https://codereview.chromium.org/2796143002 .
2017-05-23 10:22:07 -07:00
Ryan Macnak 877284947b Rename TARGET_OS_* to HOST_OS_*.
Like HOST_ARCH_*, HOST_OS_* describes the OS the VM is running on, which may be different from the OS the VM is generating code for during AOT compilation.

Currently we conflate the two when emitting AOT as assembly, and we get away with it because Flutter only uses assembly for targeting iOS and one can only target iOS from a Mac, but we expect to use assembly for Android as well so native tools can unwind Dart frames.

R=zra@google.com

Review-Url: https://codereview.chromium.org/2750843003 .
2017-03-15 13:11:05 -07:00
Vyacheslav Egorov 5ef40e6091 VM: Teach GetAndValidateIsolateStackBounds(...) to fallback to OS thread stack bounds.
Currently it relies on OSThread::stack_base_ which is explicitly set.

However if we encounter a crash or assertion failure early we don't have stack_base_ set yet.

This CL allows us to get correct stack dump even if OSThread::stack_base_ is not set yet by falling back to low-level APIs:

* On Linux and Android we fallback to pthread_attr_getstack
* On Mac OS X we use pthread_get_stackaddr_np/pthread_get_stacksize_np.
* On Windows we read limits from TIB.

This code is mostly a port of the battle tested thread limits code from Oilpan GC inside Blink. The only differences is that we don't fallback to __libc_stack_end for the main thread.

We also cleanup GetAndValidateIsolateStackBounds a bit to avoid duplication there.

(This change is motivated by https://github.com/dart-lang/sdk/issues/28692 where crash in bootstrapping does not produce any useful stack trace)

BUG=
R=johnmccutchan@google.com

Review-Url: https://codereview.chromium.org/2680123004 .
2017-02-09 19:46:06 +01:00
Zachary Anderson 076ff10c3c Fuchsia: fix Debug build
R=rmacnak@google.com

Review URL: https://codereview.chromium.org/2488813002 .
2016-11-08 14:35:00 -08:00
Zachary Anderson a1bcf051d8 clang-format runtime/vm
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2481873005 .
2016-11-08 13:54:47 -08:00
Adam Barth 823bb1a0a2 Remove use of the deprecated mx_current_time Fuchsia syscall
BUG=
R=abarth@google.com, zra@google.com

Review URL: https://codereview.chromium.org/2466003002 .
2016-11-01 14:01:04 -07:00
Zachary Anderson 74bbc7f55f Fuchsia: Make some more VM tests pass
R=asiva@google.com

Review URL: https://codereview.chromium.org/2189973003 .
2016-07-29 08:07:25 -07:00
Zachary Anderson cf5eca5416 Fuchsia: Fixes for Debug build
R=johnmccutchan@google.com

Review URL: https://codereview.chromium.org/2154713004 .
2016-07-15 13:14:32 -07:00
Zachary Anderson 8ccb85e38e [fuchsia] Update to new spelling of magenta syscalls
These now have an mx_ prefix instead of a _magenta prefix as of
https://fuchsia.googlesource.com/magenta/+/937bde71d2

R=zra@google.com

Review URL: https://codereview.chromium.org/2154443002 .
2016-07-14 14:31:07 -07:00
Zachary Anderson a503570e3a Fuchsia: Initial check-in.
Instructions to build and run are in README.fuchsia.

R=asiva@google.com

Review URL: https://codereview.chromium.org/2117593002 .
2016-07-01 12:42:05 -07:00