Skip to content

Commit 3fac7c5

Browse files
aamCommit Queue
authored andcommitted
[vm] Ensure immutable bit is preserved in aot snapshot serialization/deserialization.
Before this cl, in AOT, the immutable bit was not set on objects like Strings, so use of Strings in shared fields resulted in exception thrown due to use of non-trivially shareable values in shared fields. TEST=run_isolate_group_run_test on aot Change-Id: Ib3c79852a6c7c0cfa477039096b73892dd8b2ea7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/443440 Commit-Queue: Alexander Aprelev <[email protected]> Reviewed-by: Daco Harkes <[email protected]>
1 parent 5750b2c commit 3fac7c5

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

runtime/vm/image_snapshot.cc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,8 @@ static constexpr uword kReadOnlyGCBits =
656656

657657
uword ImageWriter::GetMarkedTags(classid_t cid,
658658
intptr_t size,
659-
bool is_canonical /* = false */) {
659+
bool is_canonical /* = false */,
660+
bool is_immutable /* = false */) {
660661
// UntaggedObject::SizeTag expects a size divisible by kObjectAlignment and
661662
// checks this in debug mode, but the size on the target machine may not be
662663
// divisible by the host machine's object alignment if they differ.
@@ -676,12 +677,14 @@ uword ImageWriter::GetMarkedTags(classid_t cid,
676677

677678
return kReadOnlyGCBits | UntaggedObject::ClassIdTag::encode(cid) |
678679
UntaggedObject::SizeTag::encode(adjusted_size) |
679-
UntaggedObject::CanonicalBit::encode(is_canonical);
680+
UntaggedObject::CanonicalBit::encode(is_canonical) |
681+
UntaggedObject::ImmutableBit::encode(is_immutable);
680682
}
681683

682684
uword ImageWriter::GetMarkedTags(const Object& obj) {
683-
uword tags = GetMarkedTags(obj.ptr()->untag()->GetClassId(),
684-
SizeInSnapshot(obj), obj.IsCanonical());
685+
uword tags =
686+
GetMarkedTags(obj.ptr()->untag()->GetClassId(), SizeInSnapshot(obj),
687+
obj.IsCanonical(), obj.IsImmutable());
685688
#if defined(HASH_IN_OBJECT_HEADER)
686689
tags = UntaggedObject::HashTag::update(obj.ptr()->untag()->GetHeaderHash(),
687690
tags);

runtime/vm/image_snapshot.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ class ImageWriter : public ValueObject {
502502

503503
static uword GetMarkedTags(classid_t cid,
504504
intptr_t size,
505-
bool is_canonical = false);
505+
bool is_canonical = false,
506+
bool is_immutable = false);
506507
static uword GetMarkedTags(const Object& obj);
507508

508509
void DumpInstructionStats();

tests/ffi/run_isolate_group_run_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ bar() {
4747
@pragma('vm:shared')
4848
var list_length = 0;
4949

50+
@pragma('vm:shared')
51+
String string_foo = "";
52+
5053
main() {
5154
IsolateGroup.runSync(() {
5255
final l = <int>[];
@@ -144,5 +147,10 @@ main() {
144147
Expect.equals(42, Baz.foo);
145148
}
146149

150+
IsolateGroup.runSync(() {
151+
string_foo = "foo bar";
152+
});
153+
Expect.equals("foo bar", string_foo);
154+
147155
print("All tests completed :)");
148156
}

0 commit comments

Comments
 (0)