Skip to content

Commit

Permalink
[vm/concurrency/debugger] Fix lock acquisition to avoid deadlocks.
Browse files Browse the repository at this point in the history
TEST=break_on_function_many_child_isolates_test flaky failures on debug build

Fixes #45391

Issue #36097

Change-Id: I075318878f1e4b0f3f921377b0281b785274621e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/192060
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
  • Loading branch information
aam authored and commit-bot@chromium.org committed Mar 19, 2021
1 parent 2c5b320 commit dd9b00f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
8 changes: 5 additions & 3 deletions runtime/vm/compiler/jit/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -612,9 +612,11 @@ CodePtr CompileParsedFunctionHelper::Compile(CompilationPipeline* pipeline) {
// breakpoint.
if (!result->IsNull()) {
if (!function.HasOptimizedCode()) {
thread()->isolate_group()->ForEachIsolate([&](Isolate* isolate) {
isolate->debugger()->NotifyCompilation(function);
});
thread()->isolate_group()->ForEachIsolate(
[&](Isolate* isolate) {
isolate->debugger()->NotifyCompilation(function);
},
/*at_safepoint=*/true);
}
}
#endif
Expand Down
41 changes: 22 additions & 19 deletions runtime/vm/runtime_entry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3011,10 +3011,7 @@ void DeoptimizeAt(Thread* mutator_thread,
ASSERT(!unoptimized_code.IsNull());
// The switch to unoptimized code may have already occurred.
if (function.HasOptimizedCode()) {
SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
if (function.HasOptimizedCode()) {
function.SwitchToUnoptimizedCode();
}
function.SwitchToUnoptimizedCode();
}

if (frame->IsMarkedForLazyDeopt()) {
Expand Down Expand Up @@ -3048,23 +3045,29 @@ void DeoptimizeAt(Thread* mutator_thread,
// Currently checks only that all optimized frames have kDeoptIndex
// and unoptimized code has the kDeoptAfter.
void DeoptimizeFunctionsOnStack() {
auto isolate_group = IsolateGroup::Current();
auto thread = Thread::Current();
// Have to grab program_lock before stopping everybody else.
SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());

auto isolate_group = thread->isolate_group();
isolate_group->RunWithStoppedMutators([&]() {
Code& optimized_code = Code::Handle();
isolate_group->ForEachIsolate([&](Isolate* isolate) {
auto mutator_thread = isolate->mutator_thread();
DartFrameIterator iterator(
mutator_thread, StackFrameIterator::kAllowCrossThreadIteration);
StackFrame* frame = iterator.NextFrame();
while (frame != nullptr) {
optimized_code = frame->LookupDartCode();
if (optimized_code.is_optimized() &&
!optimized_code.is_force_optimized()) {
DeoptimizeAt(mutator_thread, optimized_code, frame);
}
frame = iterator.NextFrame();
}
});
isolate_group->ForEachIsolate(
[&](Isolate* isolate) {
auto mutator_thread = isolate->mutator_thread();
DartFrameIterator iterator(
mutator_thread, StackFrameIterator::kAllowCrossThreadIteration);
StackFrame* frame = iterator.NextFrame();
while (frame != nullptr) {
optimized_code = frame->LookupDartCode();
if (optimized_code.is_optimized() &&
!optimized_code.is_force_optimized()) {
DeoptimizeAt(mutator_thread, optimized_code, frame);
}
frame = iterator.NextFrame();
}
},
/*at_safepoint=*/true);
});
}

Expand Down

0 comments on commit dd9b00f

Please sign in to comment.