Skip to content

Commit 4949f61

Browse files
rmacnak-googleCommit Queue
authored and
Commit Queue
committed
[vm, gc] The GC cares about immediate-ness not Smi-ness.
TEST=ci Change-Id: Ib7bae6df6becf0ed696a4c00257cedaf46f750aa Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/311148 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent dc30f81 commit 4949f61

10 files changed

+56
-51
lines changed

runtime/vm/dart_api_state.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ class FinalizablePersistentHandle {
358358
// Returns the space to charge for the external size.
359359
Heap::Space SpaceForExternal() const {
360360
// Non-heap and VM-heap objects count as old space here.
361-
return ptr_->IsSmiOrOldObject() ? Heap::kOld : Heap::kNew;
361+
return ptr_->IsImmediateOrOldObject() ? Heap::kOld : Heap::kNew;
362362
}
363363

364364
ObjectPtr ptr_;

runtime/vm/heap/become.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,10 @@ void Become::Forward() {
288288
if (before == after) {
289289
InvalidForwarding(before, after, "Cannot self-forward");
290290
}
291-
if (!before->IsHeapObject()) {
291+
if (before->IsImmediateObject()) {
292292
InvalidForwarding(before, after, "Cannot forward immediates");
293293
}
294-
if (!after->IsHeapObject()) {
294+
if (after->IsImmediateObject()) {
295295
InvalidForwarding(before, after, "Cannot target immediates");
296296
}
297297
if (before->untag()->InVMIsolateHeap()) {

runtime/vm/heap/compactor.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ void GCCompactor::SetupImagePageBoundaries() {
642642
DART_FORCE_INLINE
643643
void GCCompactor::ForwardPointer(ObjectPtr* ptr) {
644644
ObjectPtr old_target = *ptr;
645-
if (old_target->IsSmiOrNewObject()) {
645+
if (old_target->IsImmediateOrNewObject()) {
646646
return; // Not moved.
647647
}
648648

@@ -670,15 +670,15 @@ void GCCompactor::ForwardPointer(ObjectPtr* ptr) {
670670

671671
ObjectPtr new_target =
672672
UntaggedObject::FromAddr(forwarding_page->Lookup(old_addr));
673-
ASSERT(!new_target->IsSmiOrNewObject());
673+
ASSERT(!new_target->IsImmediateOrNewObject());
674674
*ptr = new_target;
675675
}
676676

677677
DART_FORCE_INLINE
678678
void GCCompactor::ForwardCompressedPointer(uword heap_base,
679679
CompressedObjectPtr* ptr) {
680680
ObjectPtr old_target = ptr->Decompress(heap_base);
681-
if (old_target->IsSmiOrNewObject()) {
681+
if (old_target->IsImmediateOrNewObject()) {
682682
return; // Not moved.
683683
}
684684

@@ -706,7 +706,7 @@ void GCCompactor::ForwardCompressedPointer(uword heap_base,
706706

707707
ObjectPtr new_target =
708708
UntaggedObject::FromAddr(forwarding_page->Lookup(old_addr));
709-
ASSERT(!new_target->IsSmiOrNewObject());
709+
ASSERT(!new_target->IsImmediateOrNewObject());
710710
*ptr = new_target;
711711
}
712712

runtime/vm/heap/gc_shared.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ void GCLinkedLists::FlushInto(GCLinkedLists* to) {
3838

3939
Heap::Space SpaceForExternal(FinalizerEntryPtr raw_entry) {
4040
// As with WeakTables, Smis are "old".
41-
return raw_entry->untag()->value()->IsSmiOrOldObject() ? Heap::kOld
42-
: Heap::kNew;
41+
return raw_entry->untag()->value()->IsImmediateOrOldObject() ? Heap::kOld
42+
: Heap::kNew;
4343
}
4444

4545
} // namespace dart

runtime/vm/heap/heap.cc

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -909,38 +909,36 @@ void Heap::ResetObjectIdTable() {
909909
}
910910

911911
intptr_t Heap::GetWeakEntry(ObjectPtr raw_obj, WeakSelector sel) const {
912-
if (!raw_obj->IsSmiOrOldObject()) {
912+
if (raw_obj->IsImmediateOrOldObject()) {
913+
return old_weak_tables_[sel]->GetValue(raw_obj);
914+
} else {
913915
return new_weak_tables_[sel]->GetValue(raw_obj);
914916
}
915-
ASSERT(raw_obj->IsSmiOrOldObject());
916-
return old_weak_tables_[sel]->GetValue(raw_obj);
917917
}
918918

919919
void Heap::SetWeakEntry(ObjectPtr raw_obj, WeakSelector sel, intptr_t val) {
920-
if (!raw_obj->IsSmiOrOldObject()) {
921-
new_weak_tables_[sel]->SetValue(raw_obj, val);
922-
} else {
923-
ASSERT(raw_obj->IsSmiOrOldObject());
920+
if (raw_obj->IsImmediateOrOldObject()) {
924921
old_weak_tables_[sel]->SetValue(raw_obj, val);
922+
} else {
923+
new_weak_tables_[sel]->SetValue(raw_obj, val);
925924
}
926925
}
927926

928927
intptr_t Heap::SetWeakEntryIfNonExistent(ObjectPtr raw_obj,
929928
WeakSelector sel,
930929
intptr_t val) {
931-
if (!raw_obj->IsSmiOrOldObject()) {
932-
return new_weak_tables_[sel]->SetValueIfNonExistent(raw_obj, val);
933-
} else {
934-
ASSERT(raw_obj->IsSmiOrOldObject());
930+
if (raw_obj->IsImmediateOrOldObject()) {
935931
return old_weak_tables_[sel]->SetValueIfNonExistent(raw_obj, val);
932+
} else {
933+
return new_weak_tables_[sel]->SetValueIfNonExistent(raw_obj, val);
936934
}
937935
}
938936

939937
void Heap::ForwardWeakEntries(ObjectPtr before_object, ObjectPtr after_object) {
940938
const auto before_space =
941-
!before_object->IsSmiOrOldObject() ? Heap::kNew : Heap::kOld;
939+
before_object->IsImmediateOrOldObject() ? Heap::kOld : Heap::kNew;
942940
const auto after_space =
943-
!after_object->IsSmiOrOldObject() ? Heap::kNew : Heap::kOld;
941+
after_object->IsImmediateOrOldObject() ? Heap::kOld : Heap::kNew;
944942

945943
for (int sel = 0; sel < Heap::kNumWeakSelectors; sel++) {
946944
const auto selector = static_cast<Heap::WeakSelector>(sel);
@@ -954,15 +952,15 @@ void Heap::ForwardWeakEntries(ObjectPtr before_object, ObjectPtr after_object) {
954952

955953
isolate_group()->ForEachIsolate(
956954
[&](Isolate* isolate) {
957-
auto before_table = !before_object->IsSmiOrOldObject()
958-
? isolate->forward_table_new()
959-
: isolate->forward_table_old();
955+
auto before_table = before_object->IsImmediateOrOldObject()
956+
? isolate->forward_table_old()
957+
: isolate->forward_table_new();
960958
if (before_table != nullptr) {
961959
intptr_t entry = before_table->RemoveValueExclusive(before_object);
962960
if (entry != 0) {
963-
auto after_table = !after_object->IsSmiOrOldObject()
964-
? isolate->forward_table_new()
965-
: isolate->forward_table_old();
961+
auto after_table = after_object->IsImmediateOrOldObject()
962+
? isolate->forward_table_old()
963+
: isolate->forward_table_new();
966964
ASSERT(after_table != nullptr);
967965
after_table->SetValueExclusive(after_object, entry);
968966
}

runtime/vm/heap/marker.cc

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,10 @@ class MarkingVisitorBase : public ObjectPointerVisitor {
6262
ObjectPtr raw_key = cur_weak->untag()->key();
6363
// Reset the next pointer in the weak property.
6464
cur_weak->untag()->next_seen_by_gc_ = WeakProperty::null();
65-
if (raw_key->IsSmiOrNewObject() || raw_key->untag()->IsMarked()) {
65+
if (raw_key->IsImmediateOrNewObject() || raw_key->untag()->IsMarked()) {
6666
ObjectPtr raw_val = cur_weak->untag()->value();
67-
if (!raw_val->IsSmiOrNewObject() && !raw_val->untag()->IsMarked()) {
67+
if (!raw_val->IsImmediateOrNewObject() &&
68+
!raw_val->untag()->IsMarked()) {
6869
more_to_mark = true;
6970
}
7071

@@ -325,7 +326,7 @@ class MarkingVisitorBase : public ObjectPointerVisitor {
325326
static bool ForwardOrSetNullIfCollected(uword heap_base,
326327
CompressedObjectPtr* ptr_address) {
327328
ObjectPtr raw = ptr_address->Decompress(heap_base);
328-
if (raw->IsSmiOrNewObject()) {
329+
if (raw->IsImmediateOrNewObject()) {
329330
// Object not touched during this GC.
330331
return false;
331332
}
@@ -394,7 +395,7 @@ class MarkingVisitorBase : public ObjectPointerVisitor {
394395
void MarkObject(ObjectPtr raw_obj) {
395396
// Fast exit if the raw object is immediate or in new space. No memory
396397
// access.
397-
if (raw_obj->IsSmiOrNewObject()) {
398+
if (raw_obj->IsImmediateOrNewObject()) {
398399
return;
399400
}
400401

@@ -447,7 +448,7 @@ typedef MarkingVisitorBase<false> UnsyncMarkingVisitor;
447448
typedef MarkingVisitorBase<true> SyncMarkingVisitor;
448449

449450
static bool IsUnreachable(const ObjectPtr raw_obj) {
450-
if (raw_obj->IsSmiOrNewObject()) {
451+
if (raw_obj->IsImmediateOrNewObject()) {
451452
return false;
452453
}
453454
return !raw_obj->untag()->IsMarked();

runtime/vm/heap/scavenger.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ class ScavengerVisitorBase : public ObjectPointerVisitor {
352352
// ScavengePointer cannot be called recursively.
353353
ObjectPtr raw_obj = *p;
354354

355-
if (raw_obj->IsSmiOrOldObject()) {
355+
if (raw_obj->IsImmediateOrOldObject()) {
356356
return;
357357
}
358358

@@ -382,7 +382,8 @@ class ScavengerVisitorBase : public ObjectPointerVisitor {
382382
// ScavengePointer cannot be called recursively.
383383
ObjectPtr raw_obj = p->Decompress(heap_base);
384384

385-
if (raw_obj->IsSmiOrOldObject()) { // Could be tested without decompression
385+
// Could be tested without decompression.
386+
if (raw_obj->IsImmediateOrOldObject()) {
386387
return;
387388
}
388389

@@ -583,7 +584,7 @@ typedef ScavengerVisitorBase<true> ParallelScavengerVisitor;
583584

584585
static bool IsUnreachable(ObjectPtr* ptr) {
585586
ObjectPtr raw_obj = *ptr;
586-
if (raw_obj->IsSmiOrOldObject()) {
587+
if (raw_obj->IsImmediateOrOldObject()) {
587588
return false;
588589
}
589590
uword raw_addr = UntaggedObject::ToAddr(raw_obj);
@@ -1349,7 +1350,7 @@ intptr_t ScavengerVisitorBase<parallel>::ProcessCopied(ObjectPtr raw_obj) {
13491350
WeakPropertyPtr raw_weak = static_cast<WeakPropertyPtr>(raw_obj);
13501351
// The fate of the weak property is determined by its key.
13511352
ObjectPtr raw_key = raw_weak->untag()->key();
1352-
if (!raw_key->IsSmiOrOldObject()) {
1353+
if (!raw_key->IsImmediateOrOldObject()) {
13531354
uword header = ReadHeaderRelaxed(raw_key);
13541355
if (!IsForwarding(header)) {
13551356
// Key is white. Enqueue the weak property.
@@ -1363,7 +1364,7 @@ intptr_t ScavengerVisitorBase<parallel>::ProcessCopied(ObjectPtr raw_obj) {
13631364
WeakReferencePtr raw_weak = static_cast<WeakReferencePtr>(raw_obj);
13641365
// The fate of the weak reference target is determined by its target.
13651366
ObjectPtr raw_target = raw_weak->untag()->target();
1366-
if (!raw_target->IsSmiOrOldObject()) {
1367+
if (!raw_target->IsImmediateOrOldObject()) {
13671368
uword header = ReadHeaderRelaxed(raw_target);
13681369
if (!IsForwarding(header)) {
13691370
// Target is white. Enqueue the weak reference. Always visit type
@@ -1579,7 +1580,7 @@ bool ScavengerVisitorBase<parallel>::ForwardOrSetNullIfCollected(
15791580
uword heap_base,
15801581
CompressedObjectPtr* ptr_address) {
15811582
ObjectPtr raw = ptr_address->Decompress(heap_base);
1582-
if (raw->IsSmiOrOldObject()) {
1583+
if (raw->IsImmediateOrOldObject()) {
15831584
// Object already null (which is old) or not touched during this GC.
15841585
return false;
15851586
}

runtime/vm/message_snapshot.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -209,31 +209,31 @@ class MessageSerializer : public BaseSerializer {
209209
bool MarkObjectId(ObjectPtr object, intptr_t id) {
210210
ASSERT(id != WeakTable::kNoValue);
211211
WeakTable* table;
212-
if (!object->IsSmiOrOldObject()) {
213-
table = isolate()->forward_table_new();
214-
} else {
212+
if (object->IsImmediateOrOldObject()) {
215213
table = isolate()->forward_table_old();
214+
} else {
215+
table = isolate()->forward_table_new();
216216
}
217217
return table->MarkValueExclusive(object, id);
218218
}
219219

220220
void SetObjectId(ObjectPtr object, intptr_t id) {
221221
ASSERT(id != WeakTable::kNoValue);
222222
WeakTable* table;
223-
if (!object->IsSmiOrOldObject()) {
224-
table = isolate()->forward_table_new();
225-
} else {
223+
if (object->IsImmediateOrOldObject()) {
226224
table = isolate()->forward_table_old();
225+
} else {
226+
table = isolate()->forward_table_new();
227227
}
228228
table->SetValueExclusive(object, id);
229229
}
230230

231231
intptr_t GetObjectId(ObjectPtr object) const {
232232
const WeakTable* table;
233-
if (!object->IsSmiOrOldObject()) {
234-
table = isolate()->forward_table_new();
235-
} else {
233+
if (object->IsImmediateOrOldObject()) {
236234
table = isolate()->forward_table_old();
235+
} else {
236+
table = isolate()->forward_table_new();
237237
}
238238
return table->GetValueExclusive(object);
239239
}

runtime/vm/tagged_pointer.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ class UntaggedObject;
2929
return (value & kSmiTagMask) == 0 || \
3030
Utils::IsAligned(value - kHeapObjectTag, kWordSize); \
3131
} \
32+
bool IsImmediateObject() const { \
33+
ASSERT(IsWellFormed()); \
34+
const uword value = ptr; \
35+
return (value & kSmiTagMask) != kHeapObjectTag; \
36+
} \
3237
bool IsHeapObject() const { \
3338
ASSERT(IsWellFormed()); \
3439
const uword value = ptr; \
@@ -53,15 +58,15 @@ class UntaggedObject;
5358
} \
5459
\
5560
/* Like !IsHeapObject() || IsOldObject() but compiles to a single branch. */ \
56-
bool IsSmiOrOldObject() const { \
61+
bool IsImmediateOrOldObject() const { \
5762
ASSERT(IsWellFormed()); \
5863
const uword kNewObjectBits = (kNewObjectAlignmentOffset | kHeapObjectTag); \
5964
const uword addr = ptr; \
6065
return (addr & kObjectAlignmentMask) != kNewObjectBits; \
6166
} \
6267
\
6368
/* Like !IsHeapObject() || IsNewObject() but compiles to a single branch. */ \
64-
bool IsSmiOrNewObject() const { \
69+
bool IsImmediateOrNewObject() const { \
6570
ASSERT(IsWellFormed()); \
6671
const uword kOldObjectBits = (kOldObjectAlignmentOffset | kHeapObjectTag); \
6772
const uword addr = ptr; \

runtime/vm/thread.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ class RestoreWriteBarrierInvariantVisitor : public ObjectPointerVisitor {
935935
for (; first != last + 1; first++) {
936936
ObjectPtr obj = *first;
937937
// Stores into new-space objects don't need a write barrier.
938-
if (obj->IsSmiOrNewObject()) continue;
938+
if (obj->IsImmediateOrNewObject()) continue;
939939

940940
// To avoid adding too much work into the remembered set, skip large
941941
// arrays. Write barrier elimination will not remove the barrier

0 commit comments

Comments
 (0)