Skip to content

Commit d47c838

Browse files
mralephCommit Queue
authored andcommitted
[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>
1 parent 82e8485 commit d47c838

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

runtime/vm/lockers.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ class SafepointLocker : public ValueObject {
282282
typename M::WaitResult Wait(int64_t millis = Monitor::kNoTimeout);
283283

284284
void NotifyAll() { monitor_->NotifyAll(); }
285+
void Notify() { monitor_->Notify(); }
285286

286287
private:
287288
friend class SafepointMonitorUnlockScope;

runtime/vm/profiler.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,7 @@ void SampleBlockProcessor::Init() {
18961896
void SampleBlockProcessor::Startup() {
18971897
ASSERT(initialized_);
18981898
ASSERT(processor_thread_id_ == OSThread::kInvalidThreadJoinId);
1899-
MonitorLocker startup_ml(monitor_);
1899+
SafepointMonitorLocker startup_ml(monitor_);
19001900
OSThread::Start("Dart Profiler SampleBlockProcessor", ThreadMain, 0);
19011901
while (!thread_running_) {
19021902
startup_ml.Wait();
@@ -1906,7 +1906,7 @@ void SampleBlockProcessor::Startup() {
19061906

19071907
void SampleBlockProcessor::Cleanup(bool drain /* = false */) {
19081908
{
1909-
MonitorLocker shutdown_ml(monitor_);
1909+
SafepointMonitorLocker shutdown_ml(monitor_);
19101910
if (shutdown_) {
19111911
// Already shutdown.
19121912
return;

0 commit comments

Comments
 (0)