The newly added --worker-thread-priority can be used by users as an
opt-in to set the thread priority / nice value.
It is the responsibility of the user to ensure that the process has the
right to change the priority to the given value. Failure to set the
priority will be fatal.
See b/154918152
Change-Id: I3b3791e88b6ddf4fa6e39e4587f7fe1ab4d2312f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/150560
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
ThreadLocalData::RunDestructors is called even if
ThreadLocalData::InitOnce has not been run, which would result in a null
pointer dereference of thread_locals_. Check for this case, then return
if thread_locals_ is NULL.
Change-Id: Ic0ab12bf643aa112c72d144662f2a32c3f0888c5
Reviewed-on: https://dart-review.googlesource.com/65171
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
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>
Code path Monitor::Wait that handles timeout contains a race between removing
waiter from the list and another thread signaling waiter's event:
T1: WaitForSingleObject(wait_data->event_, ...) returns with WAIT_TIMEOUT
T2: SetEvent(wait_data->event_)
T1: data_.RemoveWaiter(wait_data->event_)
This race leaves wait_data->event_ signaled, which breaks an important invariant
the method relies on: if WaitForSingleObject returns successfully (neither
timedout nor failed), that implies that wait_data was removed from the
waiters list by the method that signaled the event (SignalAndRemoveAllWaiters
or SignalAndRemoveFirstWaiter). However if wait_data->event_ is left signaled
the next invocation to WaitForSingleObject will return prior to any invocation
of SignalAndRemoveAllWaiters/SignalAndRemoveFirstWaiter, which means that
wait_data->event_ will be left in the list, which can lead to all sorts of
bugs, for example:
T1: // Assuming that wait_data WD1 for thread T1 is left with signaled event.
T1: ml.Wait() | waiters list: WD1
T1: | WaitForSingleObject(...) returns "spuriously" | waiters list: WD1
T1: // WD1 is still on the waiters list, even though |
T1 // it is not waiting anymore | waiters list: WD1
|
T2: ml.Wait() | waiters list: WD1 -> WD2
|
T1: // wait on the same monitor again |
T1: ml.Wait() | waiters list: WD1 -> WD2
T1: | GetMonitorWaitDataForThread() | waiters list: WD1 -> WD2
T1: | | wait_data->next_ = NULL | waiters list: WD1
T3: // Notify all waiters. Only T1 will wake up!
T3: ml.NotifyAll()
Notice how waiting on the same monitor caused us to corrupt the singled
linked list of waiters, because GetMonitorWaitDataForThread(...) does
wait_data->next_ = NULL - which means that if WD1 was accidentally left
in the list of waiters then all elements on that list after WD1 are lost.
This means that NotifyAll will not wake up all threads.
This was causing deadlocks in GC (#29261) by breaking ThreadBarrier logic.
Fixes https://github.com/dart-lang/sdk/issues/29261
Bug:
Change-Id: Ia61efa065bc7db8fe4bbf549032f35932356a0f4
Reviewed-on: https://dart-review.googlesource.com/20760
Reviewed-by: Zach Anderson <zra@google.com>
Commit-Queue: Vyacheslav Egorov <vegorov@google.com>
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>
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>
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 .
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 .
Also:
- Reaps exited threads in the thread pool before putting
a thread on the idle list so that a new arriving task
isn't blocked on a supposedly idle thread in the middle
of a join.
- Stops trying to join eventhandler threads on
Windows. Now that we're using the correct exit() call,
we probably don't have to worry about exit code pollution,
so joining the threads is unnecessary.
related #26400R=asiva@google.com, iposva@google.com
Review URL: https://codereview.chromium.org/1978153002 .
- [x] Refactor old OSThread interface for querying thread CPU time into OS::GetCurrentThreadCPUMicros.
- [x] Add data to TimelineEvent to track thread CPU time.
- [x] Include "tts" and "tdur" properties when converting the timeline to JSON
Fixes#26396
BUG=
R=rmacnak@google.com
Review URL: https://codereview.chromium.org/1960483002 .
in these blocks will not have a safepoint operation
- changed boxed_field_list_monitor_ to boxed_field_list_mutex_ as we only
need a mutex for guarding access to boxed_field_list_ as changed the
lock to use SafepointMutexLocker as the list addition code could potentially
allocate and result in GC (safepoint operation)
- Added a SafepointMonitorLocker as we have a function Isolate::VisitIsolates
which could potentially have safepoints in the enclosed block.
- Make the lock around MegamorphicCacheTable::Lookup a SafepointMutexLocker
as the look up code seems to be allocating memory while the lock is held.
- Changed the ThreadPool and MessageHandler code to account for the new
MonitorLocker usage standard
- Fixed PortMap::PrintPortsForMessageHandler to use SafepointMutexLocker as
the code it encloses calls into Dart
- Removed profiler_ field in class Profiler as it doesn't seem to be used.
R=johnmccutchan@google.com, srdjan@google.com
Review URL: https://codereview.chromium.org/1748953003 .
- Ensure that no new OSThreads are created once the VM is in shutdown mode
- Do not query thread_list_head_ without a lock (this leads to the race which causes two threads to delete the lock and TLS at the same time)
BUG=25236
R=zra@google.com
Review URL: https://codereview.chromium.org/1537543002 .
fields in a thread (i.e fields that are not Dart VM related)
- Split the Thread structure to be a pure Dart per thread structure and add
a pointer to os_thread which points to the OSThread structure
- Change Schedule/UnSchedule to set the Dart Thread structure as the TLS of
the thread when it is inside the Dart world and reset the TLS back to the
OSThread strcuture when is exits the Dart World.
- Moved the stack_base and few stack size related functions to OSThread from Isolate
R=johnmccutchan@google.com, zra@google.com
Review URL: https://codereview.chromium.org/1439483003 .
- When a process exits on Windows, Windows closes all handles
- Our mutexes use a handle to a semaphore for locking
- If our TLS destructors need to take a lock during thread exit (but after process has started to shutdown) we will deadlock waiting on a handle that's been closed.
This works around the problem by not running tls destructors when we are exiting the process.
R=zra@google.com
Review URL: https://codereview.chromium.org/1409723007 .
- When a process exits on Windows, Windows closes all handles
- Our mutexes use a handle to a semaphore for locking
- If our TLS destructors need to take a lock during thread exit (but after process has started to shutdown) we will deadlock waiting on a handle that's been closed.
This works around the problem by not running tls destructors when we are exiting the process.
R=zra@google.com
Review URL: https://codereview.chromium.org/1416063005 .