Skip to content

Commit fd5b87f

Browse files
committed
[Runtime] Don't write to rodata if values already match.
initClassFieldOffsetVector writes the instanceStart and size to the class's rodata. In some cases they already match, and this write will dirty memory unnecessarily, and prevent the compiler from emitting those rodatas into read-only memory. rdar://problem/71119533
1 parent 7dd6660 commit fd5b87f

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

stdlib/public/runtime/Metadata.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,7 +2721,12 @@ static void initClassFieldOffsetVector(ClassMetadata *self,
27212721
// situations where our entire superclass hierarchy is defined
27222722
// in Swift. (But note that ObjC might think we have a superclass
27232723
// even if Swift doesn't, because of SwiftObject.)
2724-
rodata->InstanceStart = size;
2724+
//
2725+
// The rodata may be in read-only memory if the compiler knows that the size
2726+
// it generates is already definitely correct. Don't write to this value
2727+
// unless it's necessary.
2728+
if (rodata->InstanceStart != size)
2729+
rodata->InstanceStart = size;
27252730
#endif
27262731

27272732
// Okay, now do layout.
@@ -2745,7 +2750,8 @@ static void initClassFieldOffsetVector(ClassMetadata *self,
27452750

27462751
#if SWIFT_OBJC_INTEROP
27472752
// Save the size into the Objective-C metadata as well.
2748-
rodata->InstanceSize = size;
2753+
if (rodata->InstanceSize != size)
2754+
rodata->InstanceSize = size;
27492755
#endif
27502756
}
27512757

0 commit comments

Comments
 (0)