Skip to content

Commit 65d0d85

Browse files
aamCommit Queue
authored andcommitted
[vm/shared] Move forward_table from Isolate to Thread.
Having forwarding tables on the Thread allows for those tables to be used in dart mutator thread running in IsolateGroup-shared context. On 32-bit platforms(arm) the forwarding tables are used during [SendPort.send] message verification. Fixes #60817 TEST=isolate_group_shared_send_test Change-Id: I58b33c14026584330b594776e812fe1d48bc2fd5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/431942 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent df12659 commit 65d0d85

File tree

12 files changed

+161
-137
lines changed

12 files changed

+161
-137
lines changed

runtime/lib/isolate.cc

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -260,15 +260,15 @@ class WorkSet {
260260
class WorkSet {
261261
public:
262262
explicit WorkSet(Thread* thread)
263-
: isolate_(thread->isolate()), list_(GrowableObjectArray::Handle()) {
264-
isolate_->set_forward_table_new(new WeakTable());
265-
isolate_->set_forward_table_old(new WeakTable());
263+
: thread_(thread), list_(GrowableObjectArray::Handle()) {
264+
thread_->set_forward_table_new(new WeakTable());
265+
thread_->set_forward_table_old(new WeakTable());
266266
list_ = GrowableObjectArray::New(256);
267267
cursor_ = 0;
268268
}
269269
~WorkSet() {
270-
isolate_->set_forward_table_new(nullptr);
271-
isolate_->set_forward_table_old(nullptr);
270+
thread_->set_forward_table_new(nullptr);
271+
thread_->set_forward_table_old(nullptr);
272272
}
273273

274274
void Push(const Object& obj) {
@@ -292,22 +292,22 @@ class WorkSet {
292292
DART_FORCE_INLINE
293293
intptr_t GetObjectId(ObjectPtr object) {
294294
if (object->IsNewObject()) {
295-
return isolate_->forward_table_new()->GetValueExclusive(object);
295+
return thread_->forward_table_new()->GetValueExclusive(object);
296296
} else {
297-
return isolate_->forward_table_old()->GetValueExclusive(object);
297+
return thread_->forward_table_old()->GetValueExclusive(object);
298298
}
299299
}
300300

301301
DART_FORCE_INLINE
302302
void SetObjectId(ObjectPtr object, intptr_t id) {
303303
if (object->IsNewObject()) {
304-
isolate_->forward_table_new()->SetValueExclusive(object, id);
304+
thread_->forward_table_new()->SetValueExclusive(object, id);
305305
} else {
306-
isolate_->forward_table_old()->SetValueExclusive(object, id);
306+
thread_->forward_table_old()->SetValueExclusive(object, id);
307307
}
308308
}
309309

310-
Isolate* isolate_;
310+
Thread* thread_;
311311
GrowableObjectArray& list_;
312312
intptr_t cursor_;
313313
};
@@ -475,15 +475,14 @@ class MessageValidator : private WorkSet {
475475
const char* exception_message,
476476
const Object& root) {
477477
Thread* thread = Thread::Current();
478-
Isolate* isolate = thread->isolate();
479478
Zone* zone = thread->zone();
480479
const Array& args = Array::Handle(zone, Array::New(3));
481480
args.SetAt(0, illegal_object);
482481
args.SetAt(2, String::Handle(
483482
zone, String::NewFormatted(
484483
"%s%s",
485484
FindRetainingPath(
486-
zone, isolate, root, illegal_object,
485+
zone, thread, root, illegal_object,
487486
TraversalRules::kInternalToIsolateGroup),
488487
exception_message)));
489488
const Object& exception = Object::Handle(

runtime/vm/heap/become_test.cc

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,34 +95,33 @@ ISOLATE_UNIT_TEST_CASE(BecomeForwardObjectId) {
9595
}
9696

9797
ISOLATE_UNIT_TEST_CASE(BecomeForwardMessageId) {
98-
Isolate* isolate = Isolate::Current();
99-
isolate->set_forward_table_new(new WeakTable());
100-
isolate->set_forward_table_old(new WeakTable());
98+
thread->set_forward_table_new(new WeakTable());
99+
thread->set_forward_table_old(new WeakTable());
101100

102101
const Array& before_obj = Array::Handle(Array::New(0, Heap::kOld));
103102
const Array& after_obj = Array::Handle(Array::New(0, Heap::kOld));
104103
EXPECT(before_obj.ptr() != after_obj.ptr());
105104

106105
intptr_t id = 42;
107106
intptr_t no_id = 0;
108-
isolate->forward_table_old()->SetValueExclusive(before_obj.ptr(), id);
107+
thread->forward_table_old()->SetValueExclusive(before_obj.ptr(), id);
109108
EXPECT_EQ(id,
110-
isolate->forward_table_old()->GetValueExclusive(before_obj.ptr()));
109+
thread->forward_table_old()->GetValueExclusive(before_obj.ptr()));
111110
EXPECT_EQ(no_id,
112-
isolate->forward_table_old()->GetValueExclusive(after_obj.ptr()));
111+
thread->forward_table_old()->GetValueExclusive(after_obj.ptr()));
113112

114113
Become become;
115114
become.Add(before_obj, after_obj);
116115
become.Forward();
117116

118117
EXPECT(before_obj.ptr() == after_obj.ptr());
119118
EXPECT_EQ(id,
120-
isolate->forward_table_old()->GetValueExclusive(before_obj.ptr()));
119+
thread->forward_table_old()->GetValueExclusive(before_obj.ptr()));
121120
EXPECT_EQ(id,
122-
isolate->forward_table_old()->GetValueExclusive(after_obj.ptr()));
121+
thread->forward_table_old()->GetValueExclusive(after_obj.ptr()));
123122

124-
isolate->set_forward_table_new(nullptr);
125-
isolate->set_forward_table_old(nullptr);
123+
thread->set_forward_table_new(nullptr);
124+
thread->set_forward_table_old(nullptr);
126125
}
127126

128127
ISOLATE_UNIT_TEST_CASE(BecomeForwardRememberedObject) {

runtime/vm/heap/heap.cc

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -943,23 +943,21 @@ void Heap::ForwardWeakEntries(ObjectPtr before_object, ObjectPtr after_object) {
943943
}
944944
}
945945

946-
isolate_group()->ForEachIsolate(
947-
[&](Isolate* isolate) {
948-
auto before_table = before_object->IsImmediateOrOldObject()
949-
? isolate->forward_table_old()
950-
: isolate->forward_table_new();
951-
if (before_table != nullptr) {
952-
intptr_t entry = before_table->RemoveValueExclusive(before_object);
953-
if (entry != 0) {
954-
auto after_table = after_object->IsImmediateOrOldObject()
955-
? isolate->forward_table_old()
956-
: isolate->forward_table_new();
957-
ASSERT(after_table != nullptr);
958-
after_table->SetValueExclusive(after_object, entry);
959-
}
960-
}
961-
},
962-
/*at_safepoint=*/true);
946+
isolate_group()->thread_registry()->ForEachThread([&](Thread* thread) {
947+
auto before_table = before_object->IsImmediateOrOldObject()
948+
? thread->forward_table_old()
949+
: thread->forward_table_new();
950+
if (before_table != nullptr) {
951+
intptr_t entry = before_table->RemoveValueExclusive(before_object);
952+
if (entry != 0) {
953+
auto after_table = after_object->IsImmediateOrOldObject()
954+
? thread->forward_table_old()
955+
: thread->forward_table_new();
956+
ASSERT(after_table != nullptr);
957+
after_table->SetValueExclusive(after_object, entry);
958+
}
959+
}
960+
});
963961
}
964962

965963
void Heap::ForwardWeakTables(ObjectPointerVisitor* visitor) {
@@ -972,12 +970,10 @@ void Heap::ForwardWeakTables(ObjectPointerVisitor* visitor) {
972970

973971
// Isolates might have forwarding tables (used for during snapshotting in
974972
// isolate communication).
975-
isolate_group()->ForEachIsolate(
976-
[&](Isolate* isolate) {
977-
auto table_old = isolate->forward_table_old();
978-
if (table_old != nullptr) table_old->Forward(visitor);
979-
},
980-
/*at_safepoint=*/true);
973+
isolate_group()->thread_registry()->ForEachThread([&](Thread* thread) {
974+
auto table_old = thread->forward_table_old();
975+
if (table_old != nullptr) table_old->Forward(visitor);
976+
});
981977
}
982978

983979
#ifndef PRODUCT

runtime/vm/heap/scavenger.cc

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,19 +1459,17 @@ void Scavenger::MournWeakTables() {
14591459
delete table;
14601460
}
14611461

1462-
// Each isolate might have a weak table used for fast snapshot writing (i.e.
1462+
// Each thread might have a weak table used for fast snapshot writing (i.e.
14631463
// isolate communication). Rehash those tables if need be.
1464-
heap_->isolate_group()->ForEachIsolate(
1465-
[&](Isolate* isolate) {
1466-
auto table = isolate->forward_table_new();
1467-
if (table != nullptr) {
1468-
auto replacement = WeakTable::NewFrom(table);
1469-
rehash_weak_table(table, replacement, isolate->forward_table_old(),
1470-
nullptr);
1471-
isolate->set_forward_table_new(replacement);
1472-
}
1473-
},
1474-
/*at_safepoint=*/true);
1464+
heap_->isolate_group()->thread_registry()->ForEachThread([&](Thread* thread) {
1465+
auto table = thread->forward_table_new();
1466+
if (table != nullptr) {
1467+
auto replacement = WeakTable::NewFrom(table);
1468+
rehash_weak_table(table, replacement, thread->forward_table_old(),
1469+
nullptr);
1470+
thread->set_forward_table_new(replacement);
1471+
}
1472+
});
14751473
}
14761474

14771475
void Scavenger::Forward(MarkingStackBlock* reading) {

runtime/vm/isolate.cc

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2595,15 +2595,6 @@ void IsolateGroup::MaybeIncreaseReloadEveryNStackOverflowChecks() {
25952595
}
25962596
#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
25972597

2598-
void Isolate::set_forward_table_new(WeakTable* table) {
2599-
std::unique_ptr<WeakTable> value(table);
2600-
forward_table_new_ = std::move(value);
2601-
}
2602-
void Isolate::set_forward_table_old(WeakTable* table) {
2603-
std::unique_ptr<WeakTable> value(table);
2604-
forward_table_old_ = std::move(value);
2605-
}
2606-
26072598
void Isolate::Shutdown() {
26082599
Thread* thread = Thread::Current();
26092600
ASSERT(this == thread->isolate());
@@ -2799,11 +2790,6 @@ void Isolate::VisitObjectPointers(ObjectPointerVisitor* visitor,
27992790

28002791
visitor->VisitPointer(
28012792
reinterpret_cast<ObjectPtr*>(&loaded_prefixes_set_storage_));
2802-
2803-
if (pointers_to_verify_at_exit_.length() != 0) {
2804-
visitor->VisitPointers(&pointers_to_verify_at_exit_[0],
2805-
pointers_to_verify_at_exit_.length());
2806-
}
28072793
}
28082794

28092795
void Isolate::VisitStackPointers(ObjectPointerVisitor* visitor,

runtime/vm/isolate.h

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ class StoreBuffer;
8585
class StubCode;
8686
class ThreadRegistry;
8787
class UserTag;
88-
class WeakTable;
8988

9089
class IsolateVisitor {
9190
public:
@@ -1461,14 +1460,6 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
14611460
}
14621461
static bool IsVMInternalIsolate(const Isolate* isolate);
14631462

1464-
// The weak table used in the snapshot writer for the purpose of fast message
1465-
// sending.
1466-
WeakTable* forward_table_new() { return forward_table_new_.get(); }
1467-
void set_forward_table_new(WeakTable* table);
1468-
1469-
WeakTable* forward_table_old() { return forward_table_old_.get(); }
1470-
void set_forward_table_old(WeakTable* table);
1471-
14721463
void RememberLiveTemporaries();
14731464
void DeferredMarkLiveTemporaries();
14741465

@@ -1484,10 +1475,6 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
14841475
bool IsPrefixLoaded(const LibraryPrefix& prefix) const;
14851476
void SetPrefixIsLoaded(const LibraryPrefix& prefix);
14861477

1487-
MallocGrowableArray<ObjectPtr>* pointers_to_verify_at_exit() {
1488-
return &pointers_to_verify_at_exit_;
1489-
}
1490-
14911478
bool SetOwnerThread(ThreadId expected_old_owner, ThreadId new_owner);
14921479

14931480
// Must be invoked with a valid PortMap::Locker, or while this isolate is the
@@ -1689,10 +1676,6 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
16891676
Monitor spawn_count_monitor_;
16901677
intptr_t spawn_count_ = 0;
16911678

1692-
// Used during message sending of messages between isolates.
1693-
std::unique_ptr<WeakTable> forward_table_new_;
1694-
std::unique_ptr<WeakTable> forward_table_old_;
1695-
16961679
// Signals whether the isolate can receive messages (e.g. KillAllIsolates can
16971680
// send a kill message).
16981681
// This is protected by [isolate_creation_monitor_].
@@ -1734,8 +1717,6 @@ class Isolate : public IntrusiveDListEntry<Isolate> {
17341717

17351718
ArrayPtr loaded_prefixes_set_storage_;
17361719

1737-
MallocGrowableArray<ObjectPtr> pointers_to_verify_at_exit_;
1738-
17391720
bool is_system_isolate_ = false;
17401721

17411722
#define REUSABLE_FRIEND_DECLARATION(name) \

runtime/vm/message_snapshot.cc

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ class MessageSerializer : public BaseSerializer {
208208
ASSERT(id != WeakTable::kNoValue);
209209
WeakTable* table;
210210
if (object->IsImmediateOrOldObject()) {
211-
table = isolate()->forward_table_old();
211+
table = thread()->forward_table_old();
212212
} else {
213-
table = isolate()->forward_table_new();
213+
table = thread()->forward_table_new();
214214
}
215215
return table->MarkValueExclusive(object, id);
216216
}
@@ -219,19 +219,19 @@ class MessageSerializer : public BaseSerializer {
219219
ASSERT(id != WeakTable::kNoValue);
220220
WeakTable* table;
221221
if (object->IsImmediateOrOldObject()) {
222-
table = isolate()->forward_table_old();
222+
table = thread()->forward_table_old();
223223
} else {
224-
table = isolate()->forward_table_new();
224+
table = thread()->forward_table_new();
225225
}
226226
table->SetValueExclusive(object, id);
227227
}
228228

229229
intptr_t GetObjectId(ObjectPtr object) const {
230230
const WeakTable* table;
231231
if (object->IsImmediateOrOldObject()) {
232-
table = isolate()->forward_table_old();
232+
table = thread()->forward_table_old();
233233
} else {
234-
table = isolate()->forward_table_new();
234+
table = thread()->forward_table_new();
235235
}
236236
return table->GetValueExclusive(object);
237237
}
@@ -264,14 +264,14 @@ class MessageSerializer : public BaseSerializer {
264264
Thread* thread() const {
265265
return static_cast<Thread*>(StackResource::thread());
266266
}
267-
Isolate* isolate() const { return thread()->isolate(); }
268267
IsolateGroup* isolate_group() const { return thread()->isolate_group(); }
269268

270269
bool HasRef(ObjectPtr object) const {
271270
return GetObjectId(object) != WeakTable::kNoValue;
272271
}
273272

274273
private:
274+
Thread* thread_;
275275
WeakTable* forward_table_new_;
276276
WeakTable* forward_table_old_;
277277
GrowableArray<Object*> stack_;
@@ -2705,13 +2705,13 @@ MessageSerializer::MessageSerializer(Thread* thread)
27052705
forward_table_new_(),
27062706
forward_table_old_(),
27072707
stack_(thread->zone(), 0) {
2708-
isolate()->set_forward_table_new(new WeakTable());
2709-
isolate()->set_forward_table_old(new WeakTable());
2708+
thread->set_forward_table_new(new WeakTable());
2709+
thread->set_forward_table_old(new WeakTable());
27102710
}
27112711

27122712
MessageSerializer::~MessageSerializer() {
2713-
isolate()->set_forward_table_new(nullptr);
2714-
isolate()->set_forward_table_old(nullptr);
2713+
thread()->set_forward_table_new(nullptr);
2714+
thread()->set_forward_table_old(nullptr);
27152715
}
27162716

27172717
ApiMessageSerializer::ApiMessageSerializer(Zone* zone)
@@ -2757,7 +2757,7 @@ void MessageSerializer::Trace(const Object& root, Object* object) {
27572757
// as they are not going to be used again here.
27582758
const char* message = OS::SCreate(
27592759
zone_, "is a regular instance reachable via %s",
2760-
FindRetainingPath(zone_, isolate(), root, *object,
2760+
FindRetainingPath(zone_, thread(), root, *object,
27612761
TraversalRules::kExternalBetweenIsolateGroups));
27622762
IllegalObject(*object, message);
27632763
}
@@ -2802,7 +2802,7 @@ void MessageSerializer::Trace(const Object& root, Object* object) {
28022802
// as they are not going to be used again here.
28032803
const char* message = OS::SCreate(
28042804
zone_, "is a %s reachable via %s", illegal_cid_string,
2805-
FindRetainingPath(zone_, isolate(), root, *object,
2805+
FindRetainingPath(zone_, thread(), root, *object,
28062806
TraversalRules::kExternalBetweenIsolateGroups));
28072807
IllegalObject(*object, message);
28082808
}

0 commit comments

Comments
 (0)