Skip to content

Commit 0a29936

Browse files
mkustermanncommit-bot@chromium.org
authored andcommitted
[vm/concurrency] Make all isolates within an isolate group coordinate on GCs
This CL moves the thread registry and the safepoint handler to the [IsolateGroup]. This will cause all threads belonging to the isolate group to safepoint together. => We will therefore start to get an idea of the impact this will have on pause times. So far it was only possible to enter a particular isolate (e.g. as mutator thread or auxiliary thread). This CL adds support for entering an isolate group (instead of a particular isolate) as an auxiliarly thread. The current isolate group is available via `IsolateGroup::Current()`. => This is a preparation step to let GC threads enter the isolate group as auxiliary threads, not associated with a particular isolate but to an isolate group as a whole. Issue #36097 Change-Id: I7069d07130938d370869f02060570143bfeb1b48 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/108801 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Martin Kustermann <[email protected]>
1 parent 9ec6a48 commit 0a29936

10 files changed

+331
-175
lines changed

runtime/vm/heap/safepoint.cc

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ SafepointOperationScope::SafepointOperationScope(Thread* T)
1717
Isolate* I = T->isolate();
1818
ASSERT(I != NULL);
1919

20-
SafepointHandler* handler = I->safepoint_handler();
20+
SafepointHandler* handler = I->group()->safepoint_handler();
2121
ASSERT(handler != NULL);
2222

2323
// Signal all threads to get to a safepoint and wait for them to
@@ -37,8 +37,8 @@ SafepointOperationScope::~SafepointOperationScope() {
3737
handler->ResumeThreads(T);
3838
}
3939

40-
SafepointHandler::SafepointHandler(Isolate* isolate)
41-
: isolate_(isolate),
40+
SafepointHandler::SafepointHandler(IsolateGroup* isolate_group)
41+
: isolate_group_(isolate_group),
4242
safepoint_lock_(),
4343
number_threads_not_at_safepoint_(0),
4444
safepoint_operation_count_(0),
@@ -47,7 +47,7 @@ SafepointHandler::SafepointHandler(Isolate* isolate)
4747
SafepointHandler::~SafepointHandler() {
4848
ASSERT(owner_ == NULL);
4949
ASSERT(safepoint_operation_count_ == 0);
50-
isolate_ = NULL;
50+
isolate_group_ = NULL;
5151
}
5252

5353
void SafepointHandler::SafepointThreads(Thread* T) {
@@ -79,7 +79,7 @@ void SafepointHandler::SafepointThreads(Thread* T) {
7979

8080
// Go over the active thread list and ensure that all threads active
8181
// in the isolate reach a safepoint.
82-
Thread* current = isolate()->thread_registry()->active_list();
82+
Thread* current = isolate_group()->thread_registry()->active_list();
8383
while (current != NULL) {
8484
MonitorLocker tl(current->thread_lock());
8585
if (!current->BypassSafepoints()) {
@@ -113,7 +113,8 @@ void SafepointHandler::SafepointThreads(Thread* T) {
113113
if (FLAG_trace_safepoint && num_attempts > 10) {
114114
// We have been waiting too long, start logging this as we might
115115
// have an issue where a thread is not checking in for a safepoint.
116-
for (Thread* current = isolate()->thread_registry()->active_list();
116+
for (Thread* current =
117+
isolate_group()->thread_registry()->active_list();
117118
current != NULL; current = current->next()) {
118119
if (!current->IsAtSafepoint()) {
119120
OS::PrintErr("Attempt:%" Pd
@@ -139,7 +140,7 @@ void SafepointHandler::ResumeThreads(Thread* T) {
139140
decrement_safepoint_operation_count();
140141
return;
141142
}
142-
Thread* current = isolate()->thread_registry()->active_list();
143+
Thread* current = isolate_group()->thread_registry()->active_list();
143144
while (current != NULL) {
144145
MonitorLocker tl(current->thread_lock());
145146
if (!current->BypassSafepoints()) {

runtime/vm/heap/safepoint.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ class SafepointOperationScope : public ThreadStackResource {
2424
DISALLOW_COPY_AND_ASSIGN(SafepointOperationScope);
2525
};
2626

27-
// Implements handling of safepoint operations for all threads in an Isolate.
27+
// Implements handling of safepoint operations for all threads in an
28+
// IsolateGroup.
2829
class SafepointHandler {
2930
public:
30-
explicit SafepointHandler(Isolate* I);
31+
explicit SafepointHandler(IsolateGroup* I);
3132
~SafepointHandler();
3233

3334
void EnterSafepointUsingLock(Thread* T);
@@ -39,8 +40,8 @@ class SafepointHandler {
3940
void SafepointThreads(Thread* T);
4041
void ResumeThreads(Thread* T);
4142

42-
Isolate* isolate() const { return isolate_; }
43-
Monitor* threads_lock() const { return isolate_->threads_lock(); }
43+
IsolateGroup* isolate_group() const { return isolate_group_; }
44+
Monitor* threads_lock() const { return isolate_group_->threads_lock(); }
4445
bool SafepointInProgress() const {
4546
ASSERT(threads_lock()->IsOwnedByCurrentThread());
4647
return ((safepoint_operation_count_ > 0) && (owner_ != NULL));
@@ -74,7 +75,7 @@ class SafepointHandler {
7475
safepoint_operation_count_ -= 1;
7576
}
7677

77-
Isolate* isolate_;
78+
IsolateGroup* isolate_group_;
7879

7980
// Monitor used by thread initiating a safepoint operation to track threads
8081
// not at a safepoint and wait for these threads to reach a safepoint.
@@ -91,6 +92,7 @@ class SafepointHandler {
9192
Thread* owner_;
9293

9394
friend class Isolate;
95+
friend class IsolateGroup;
9496
friend class SafepointOperationScope;
9597
friend class HeapIterationScope;
9698
};

runtime/vm/heap/scavenger.cc

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -909,8 +909,14 @@ void Scavenger::MakeNewSpaceIterable() const {
909909
MonitorLocker ml(isolate->threads_lock(), false);
910910
Thread* current = heap_->isolate()->thread_registry()->active_list();
911911
while (current != NULL) {
912-
if (current->HasActiveTLAB()) {
913-
heap_->MakeTLABIterable(current);
912+
// NOTE: During the transition period all isolates within an isolate group
913+
// share the thread registry, but have their own heap.
914+
// So we explicitly filter those threads which belong to the isolate of
915+
// interest (once we have a shared heap this needs to change).
916+
if (current->isolate() == isolate) {
917+
if (current->HasActiveTLAB()) {
918+
heap_->MakeTLABIterable(current);
919+
}
914920
}
915921
current = current->next();
916922
}
@@ -925,7 +931,13 @@ void Scavenger::AbandonTLABs(Isolate* isolate) {
925931
MonitorLocker ml(isolate->threads_lock(), false);
926932
Thread* current = isolate->thread_registry()->active_list();
927933
while (current != NULL) {
928-
heap_->AbandonRemainingTLAB(current);
934+
// NOTE: During the transition period all isolates within an isolate group
935+
// share the thread registry, but have their own heap.
936+
// So we explicitly filter those threads which belong to the isolate of
937+
// interest (once we have a shared heap this needs to change).
938+
if (current->isolate() == isolate) {
939+
heap_->AbandonRemainingTLAB(current);
940+
}
929941
current = current->next();
930942
}
931943
Thread* mutator_thread = isolate->mutator_thread();

0 commit comments

Comments
 (0)