Skip to content

Commit 859f6b3

Browse files
sstricklCommit Queue
authored andcommitted
[vm] Mark closure objects as shallowly immutable.
TEST=ci Issue: #55136 Change-Id: Icb39fc386439da449845eac4d0fd0df9d776aec7 Cq-Include-Trybots: luci.dart.try:vm-linux-debug-x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-simarm_x64-try Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/435126 Commit-Queue: Alexander Markov <[email protected]> Auto-Submit: Tess Strickland <[email protected]> Reviewed-by: Alexander Markov <[email protected]>
1 parent 1fd04e5 commit 859f6b3

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

runtime/vm/class_id.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -595,8 +595,8 @@ inline bool IsDeeplyImmutableCid(intptr_t predefined_cid) {
595595

596596
inline bool IsShallowlyImmutableCid(intptr_t predefined_cid) {
597597
ASSERT(predefined_cid < kNumPredefinedCids);
598-
// TODO(https://dartbug.com/55136): Mark kClosureCid as shallowly imutable.
599-
return IsUnmodifiableTypedDataViewClassId(predefined_cid);
598+
return predefined_cid == kClosureCid ||
599+
IsUnmodifiableTypedDataViewClassId(predefined_cid);
600600
}
601601

602602
// See documentation on ImmutableBit in raw_object.h

runtime/vm/object_graph_copy.cc

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,15 @@ static bool CanShareObject(ObjectPtr obj, uword tags) {
162162
->IsImmutable();
163163
}
164164

165+
if (cid == kClosureCid) {
166+
// We can share a closure iff it doesn't close over any state.
167+
return Closure::RawCast(obj)->untag()->context() == Object::null();
168+
}
169+
165170
// All other objects that have immutability bit set are deeply immutable.
166171
return true;
167172
}
168173

169-
// TODO(https://dartbug.com/55136): Mark Closures as shallowly imutable.
170-
// And move this into the if above.
171-
if (cid == kClosureCid) {
172-
// We can share a closure iff it doesn't close over any state.
173-
return Closure::RawCast(obj)->untag()->context() == Object::null();
174-
}
175-
176174
return false;
177175
}
178176

@@ -238,7 +236,7 @@ void SetNewSpaceTaggingWord(ObjectPtr to, classid_t cid, uint32_t size) {
238236
tags = UntaggedObject::CanonicalBit::update(false, tags);
239237
tags = UntaggedObject::NewOrEvacuationCandidateBit::update(true, tags);
240238
tags = UntaggedObject::ImmutableBit::update(
241-
IsUnmodifiableTypedDataViewClassId(cid), tags);
239+
Object::ShouldHaveImmutabilityBitSet(cid), tags);
242240
#if defined(HASH_IN_OBJECT_HEADER)
243241
tags = UntaggedObject::HashTag::update(0, tags);
244242
#endif

0 commit comments

Comments
 (0)