isa

arm64 架构之前,isa 是一个普通的指针,存储 class、metal-class 对象的内存地址。
arm64 架构开始,对 isa 进行了优化,变成了 union 共用体结构,使用位域来存储更多信息。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
union isa_t {
isa_t() { }
isa_t(uintptr_t value) : bits(value) { }

Class cls;
uintptr_t bits;
#if defined(ISA_BITFIELD)
struct {
ISA_BITFIELD; // defined in isa.h
};
#endif
};

#define ISA_BITFIELD \
uintptr_t nonpointer : 1; \
uintptr_t has_assoc : 1; \
uintptr_t has_cxx_dtor : 1; \
uintptr_t shiftcls : 33; /*MACH_VM_MAX_ADDRESS 0x1000000000*/ \
uintptr_t magic : 6; \
uintptr_t weakly_referenced : 1; \
uintptr_t deallocating : 1; \
uintptr_t has_sidetable_rc : 1; \
uintptr_t extra_rc : 19

关于其中位域存储的信息的一些详解

  • nonpointer

    • 0 代表普通的指针,存储着 class meta-class 对象的内存地址
    • 1 代表优化过,使用位域存储更多信息
  • has_assoc
    是否设置过关联对象,如果没有释放会更快

  • has_cxx_dtor
    是否有 C++ 的析构函数,如果没有释放会更快

  • shiftcls
    存储着 class meta-class 对象的内存地址信息

  • magic
    用于在调试时判断对象是否未完成初始化

  • weakly_referenced
    是否被弱引用指向过,如果没有释放会更快

  • deallocating
    对象是否正在释放

  • has_sidetable_rc

    • 引用计数器是否过大无法存储在 isa 中
    • 如果为 1,引用计数器会存储在一个叫 SideTable 的类属性中
  • extra_rc
    里面存储的值是引用计数器减 1

Class