Skip to content

Commit 487c595

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm] Handle non-Smi lengths during heap snapshot writing.
This applies to List/Map/Set, which have logical lengths that are initialized by Dart constructors. It does not apply to Array/String/TypedData, which have physical lengths that must always be initialized before the next safepoint. TEST=ci Bug: #55689 Change-Id: If132405249e4e49920b0f4f63f85ebeb49e23671 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/400020 Reviewed-by: Alexander Aprelev <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent 2d7bb5d commit 487c595

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

runtime/vm/object_graph.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,6 +1120,13 @@ class Pass2Visitor : public ObjectVisitor,
11201120
writer_(writer),
11211121
object_slots_(object_slots) {}
11221122

1123+
// A safepoint might occur between the allocation stub creating an object and
1124+
// filling it with nulls and the instance initializer running and populating a
1125+
// length field.
1126+
static intptr_t SmiValueOrZero(SmiPtr smi) {
1127+
return smi->IsSmi() ? Smi::Value(smi) : 0;
1128+
}
1129+
11231130
void VisitObject(ObjectPtr obj) override {
11241131
if (obj->IsPseudoObject()) return;
11251132

@@ -1171,16 +1178,16 @@ class Pass2Visitor : public ObjectVisitor,
11711178
Smi::Value(static_cast<ArrayPtr>(obj)->untag()->length()));
11721179
} else if (cid == kGrowableObjectArrayCid) {
11731180
writer_->WriteUnsigned(kLengthData);
1174-
writer_->WriteUnsigned(Smi::Value(
1181+
writer_->WriteUnsigned(SmiValueOrZero(
11751182
static_cast<GrowableObjectArrayPtr>(obj)->untag()->length()));
11761183
} else if (cid == kMapCid || cid == kConstMapCid) {
11771184
writer_->WriteUnsigned(kLengthData);
11781185
writer_->WriteUnsigned(
1179-
Smi::Value(static_cast<MapPtr>(obj)->untag()->used_data()));
1186+
SmiValueOrZero(static_cast<MapPtr>(obj)->untag()->used_data()));
11801187
} else if (cid == kSetCid || cid == kConstSetCid) {
11811188
writer_->WriteUnsigned(kLengthData);
11821189
writer_->WriteUnsigned(
1183-
Smi::Value(static_cast<SetPtr>(obj)->untag()->used_data()));
1190+
SmiValueOrZero(static_cast<SetPtr>(obj)->untag()->used_data()));
11841191
} else if (cid == kObjectPoolCid) {
11851192
writer_->WriteUnsigned(kLengthData);
11861193
writer_->WriteUnsigned(static_cast<ObjectPoolPtr>(obj)->untag()->length_);

0 commit comments

Comments
 (0)