@@ -711,12 +711,51 @@ Objective-C ``Protocol`` objects. The layout is as follows:
711
711
Heap Objects
712
712
------------
713
713
714
- Heap Metadata
715
- ~~~~~~~~~~~~~
714
+ Swift heap objects share a common header for reference counting by the
715
+ runtime and are used for the following:
716
+
717
+ - Swift class instances
718
+ - Boxes, e.g. for closure captures or indirect enum cases
719
+ - Thick function contexts
720
+ - Blocks
721
+ - Metatype instances
722
+ - Opaque value buffers, e.g. for values that are too large to fit into
723
+ existential containers
716
724
717
725
Heap Object Header
718
726
~~~~~~~~~~~~~~~~~~
719
727
728
+ **Objective-C Heap Objects **
729
+
730
+ Objective-C objects start with just the following:
731
+
732
+ * The so-called "isa", for use in finding the Class object.
733
+ This may not necesarily be a pointer.
734
+
735
+ **Swift Heap Objects **
736
+
737
+ Swift Heap Objects start with the following items:
738
+
739
+ * The pointer to the metadata for this object.
740
+ * The 32-bit *strong reference count * for this object.
741
+
742
+ The strong reference count uses the two least significant bits as
743
+ flags:
744
+
745
+ Bit 0: The *pinned * marker. This is used by the Swift runtime to
746
+ prevent changes in the reference count.
747
+
748
+ Bit 1: The *deallocating * marker. This is used by the Swift runtime to
749
+ indicate that the object is being deallocated.
750
+
751
+ * The 32-bit *weak reference count * for this object.
752
+
753
+ As you can see, a Swift heap object is offset-compatible with an
754
+ Objective-C object, although the reference counts for Swift objects are
755
+ stored inline as fields instead of packed into the isa or in a side
756
+ table.
757
+
758
+
720
759
Mangling
721
760
--------
722
761
::
0 commit comments