Skip to content

Commit e4e8360

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm, isolates] Avoid three-way deadlock during isolate exit.
Running mutator holds safepoint operation scope starting old space GC waiting for old space tasks to reach 0 Concurrent marker holds old space tasks > 0 waiting for isolates_list_ lock to interrupt for finalization Exiting mutator holds isolates_list_ lock_ to unregister isolate waiting for safepoint to end TransitionVMToBlocked Reorder isolate [un]registeration to not need safepoint transition to acquire the isolates_list_ lock. TEST=ci Bug: #59574 Change-Id: Ia98fabd654c880b253893a0598d2e26ed77f52da Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397660 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 343ffd1 commit e4e8360

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

runtime/vm/isolate.cc

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,6 @@ bool IsolateGroup::ContainsOnlyOneIsolate() {
454454
return isolate_count_ == 0 || isolate_count_ == 1;
455455
}
456456

457-
void IsolateGroup::RunWithLockedGroup(std::function<void()> fun) {
458-
SafepointWriteRwLocker ml(Thread::Current(), isolates_lock_.get());
459-
fun();
460-
}
461-
462457
void IsolateGroup::UnregisterIsolate(Isolate* isolate) {
463458
SafepointWriteRwLocker ml(Thread::Current(), isolates_lock_.get());
464459
isolates_.Remove(isolate);
@@ -1850,14 +1845,6 @@ Isolate* Isolate::InitIsolate(const char* name_prefix,
18501845
#undef ISOLATE_METRIC_INIT
18511846
#endif // !defined(PRODUCT)
18521847

1853-
// First we ensure we enter the isolate. This will ensure we're participating
1854-
// in any safepointing requests from this point on. Other threads requesting a
1855-
// safepoint operation will therefore wait until we've stopped.
1856-
//
1857-
// Though the [result] isolate is still in a state where no memory has been
1858-
// allocated, which means it's safe to GC the isolate group until here.
1859-
Thread::EnterIsolate(result);
1860-
18611848
// Setup the isolate message handler.
18621849
result->message_handler_ = new IsolateMessageHandler(result);
18631850

@@ -1885,6 +1872,14 @@ Isolate* Isolate::InitIsolate(const char* name_prefix,
18851872
// to vm-isolate objects, e.g. null)
18861873
isolate_group->RegisterIsolate(result);
18871874

1875+
// Now we enter the isolate. This will ensure we're participating in any
1876+
// safepointing requests from this point on. Other threads requesting a
1877+
// safepoint operation will therefore wait until we've stopped.
1878+
//
1879+
// Though the [result] isolate is still in a state where no memory has been
1880+
// allocated, which means it's safe to GC the isolate group until here.
1881+
Thread::EnterIsolate(result);
1882+
18881883
if (api_flags.is_service_isolate) {
18891884
ASSERT(!ServiceIsolate::Exists());
18901885
ServiceIsolate::SetServiceIsolate(result);
@@ -2619,14 +2614,15 @@ void Isolate::LowLevelCleanup(Isolate* isolate) {
26192614
Dart_IsolateCleanupCallback cleanup = isolate->on_cleanup_callback();
26202615
auto callback_data = isolate->init_callback_data_;
26212616

2622-
// From this point on the isolate is no longer visited by GC (which is ok,
2623-
// since we're just going to delete it anyway).
2624-
isolate_group->UnregisterIsolate(isolate);
2625-
26262617
// From this point on the isolate doesn't participate in safepointing
26272618
// requests anymore.
26282619
ASSERT(!Thread::Current()->HasActiveState());
26292620
Thread::ExitIsolate(/*isolate_shutdown=*/true);
2621+
ASSERT(Thread::Current() == nullptr);
2622+
2623+
// From this point on the isolate is no longer visited by GC (which is ok,
2624+
// since we're just going to delete it anyway).
2625+
isolate_group->UnregisterIsolate(isolate);
26302626

26312627
// Now it's safe to delete the isolate.
26322628
delete isolate;

runtime/vm/isolate.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,8 +327,6 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
327327

328328
bool ContainsOnlyOneIsolate();
329329

330-
void RunWithLockedGroup(std::function<void()> fun);
331-
332330
void ScheduleInterrupts(uword interrupt_bits);
333331

334332
ThreadRegistry* thread_registry() const { return thread_registry_.get(); }

runtime/vm/port.cc

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,6 @@ Dart_Port PortMap::CreatePort(PortHandler* handler) {
5959
return ILLEGAL_PORT;
6060
}
6161

62-
#if defined(DEBUG)
63-
handler->CheckAccess();
64-
#endif
65-
6662
const Dart_Port port = AllocatePort();
6763
if (auto ports = handler->ports(ml)) {
6864
ports->Insert(PortHandler::PortSetEntry{port});

0 commit comments

Comments
 (0)