Skip to content

Commit c77eec3

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[vm] Remove assumption from Instance cluster than the Class cluster comes earlier.
Clusters should not read information produced by any other cluster until PostLoad. Bug: #41974 Change-Id: I39ec580d9011604f7041615cefaa907aa99a3ff8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/164280 Reviewed-by: Régis Crelier <[email protected]>
1 parent 52b0285 commit c77eec3

File tree

1 file changed

+37
-36
lines changed

1 file changed

+37
-36
lines changed

runtime/vm/clustered_snapshot.cc

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,40 @@ void SerializationCluster::WriteAndMeasureFill(Serializer* serializer) {
144144
size_ += (stop - start);
145145
}
146146

147+
static UnboxedFieldBitmap CalculateTargetUnboxedFieldsBitmap(
148+
Serializer* s,
149+
intptr_t class_id) {
150+
const auto unboxed_fields_bitmap_host =
151+
s->isolate()->group()->shared_class_table()->GetUnboxedFieldsMapAt(
152+
class_id);
153+
154+
UnboxedFieldBitmap unboxed_fields_bitmap;
155+
if (unboxed_fields_bitmap_host.IsEmpty() ||
156+
kWordSize == compiler::target::kWordSize) {
157+
unboxed_fields_bitmap = unboxed_fields_bitmap_host;
158+
} else {
159+
ASSERT(kWordSize == 8 && compiler::target::kWordSize == 4);
160+
// A new bitmap is built if the word sizes in the target and
161+
// host are different
162+
unboxed_fields_bitmap.Reset();
163+
intptr_t target_i = 0, host_i = 0;
164+
165+
while (host_i < UnboxedFieldBitmap::Length()) {
166+
// Each unboxed field has constant length, therefore the number of
167+
// words used by it should double when compiling from 64-bit to 32-bit.
168+
if (unboxed_fields_bitmap_host.Get(host_i++)) {
169+
unboxed_fields_bitmap.Set(target_i++);
170+
unboxed_fields_bitmap.Set(target_i++);
171+
} else {
172+
// For object pointers, the field is always one word length
173+
target_i++;
174+
}
175+
}
176+
}
177+
178+
return unboxed_fields_bitmap;
179+
}
180+
147181
class ClassSerializationCluster : public SerializationCluster {
148182
public:
149183
explicit ClassSerializationCluster(intptr_t num_cids)
@@ -236,39 +270,6 @@ class ClassSerializationCluster : public SerializationCluster {
236270
GrowableArray<ClassPtr> predefined_;
237271
GrowableArray<ClassPtr> objects_;
238272

239-
UnboxedFieldBitmap CalculateTargetUnboxedFieldsBitmap(Serializer* s,
240-
intptr_t class_id) {
241-
const auto unboxed_fields_bitmap_host =
242-
s->isolate()->group()->shared_class_table()->GetUnboxedFieldsMapAt(
243-
class_id);
244-
245-
UnboxedFieldBitmap unboxed_fields_bitmap;
246-
if (unboxed_fields_bitmap_host.IsEmpty() ||
247-
kWordSize == compiler::target::kWordSize) {
248-
unboxed_fields_bitmap = unboxed_fields_bitmap_host;
249-
} else {
250-
ASSERT(kWordSize == 8 && compiler::target::kWordSize == 4);
251-
// A new bitmap is built if the word sizes in the target and
252-
// host are different
253-
unboxed_fields_bitmap.Reset();
254-
intptr_t target_i = 0, host_i = 0;
255-
256-
while (host_i < UnboxedFieldBitmap::Length()) {
257-
// Each unboxed field has constant length, therefore the number of
258-
// words used by it should double when compiling from 64-bit to 32-bit.
259-
if (unboxed_fields_bitmap_host.Get(host_i++)) {
260-
unboxed_fields_bitmap.Set(target_i++);
261-
unboxed_fields_bitmap.Set(target_i++);
262-
} else {
263-
// For object pointers, the field is always one word length
264-
target_i++;
265-
}
266-
}
267-
}
268-
269-
return unboxed_fields_bitmap;
270-
}
271-
272273
bool RequireLegacyErasureOfConstants(ClassPtr cls) {
273274
// Do not generate a core snapshot containing constants that would require
274275
// a legacy erasure of their types if loaded in an isolate running in weak
@@ -3349,9 +3350,11 @@ class InstanceSerializationCluster : public SerializationCluster {
33493350
intptr_t next_field_offset = host_next_field_offset_in_words_
33503351
<< kWordSizeLog2;
33513352
const intptr_t count = objects_.length();
3353+
s->WriteUnsigned64(CalculateTargetUnboxedFieldsBitmap(s, cid_).Value());
33523354
const auto unboxed_fields_bitmap =
33533355
s->isolate()->group()->shared_class_table()->GetUnboxedFieldsMapAt(
33543356
cid_);
3357+
33553358
for (intptr_t i = 0; i < count; i++) {
33563359
InstancePtr instance = objects_[i];
33573360
AutoTraceObject(instance);
@@ -3407,10 +3410,8 @@ class InstanceDeserializationCluster : public DeserializationCluster {
34073410
intptr_t next_field_offset = next_field_offset_in_words_ << kWordSizeLog2;
34083411
intptr_t instance_size =
34093412
Object::RoundedAllocationSize(instance_size_in_words_ * kWordSize);
3413+
const UnboxedFieldBitmap unboxed_fields_bitmap(d->ReadUnsigned64());
34103414

3411-
const auto unboxed_fields_bitmap =
3412-
d->isolate()->group()->shared_class_table()->GetUnboxedFieldsMapAt(
3413-
cid_);
34143415
for (intptr_t id = start_index_; id < stop_index_; id++) {
34153416
InstancePtr instance = static_cast<InstancePtr>(d->Ref(id));
34163417
bool is_canonical = d->Read<bool>();

0 commit comments

Comments
 (0)