isa 等价于 is kind of

    • 实例对象 isa 指向类对象
    • 类对象指 isa 向元类对象
    • 元类对象的 isa 指向元类的基类

    isa 有两种类型

    • 纯指针,指向内存地址
    • NON_POINTER_ISA,除了内存地址,还存有一些其他信息
    1. union isa_t
    2. {
    3. Class cls;
    4. uintptr_t bits;
    5. # if __arm64__ // arm64架构
    6. # define ISA_MASK 0x0000000ffffffff8ULL //用来取出33位内存地址使用(&)操作
    7. # define ISA_MAGIC_MASK 0x000003f000000001ULL
    8. # define ISA_MAGIC_VALUE 0x000001a000000001ULL
    9. struct {
    10. uintptr_t nonpointer : 1; //0:代表普通指针,1:表示优化过的,可以存储更多信息。
    11. uintptr_t has_assoc : 1; //是否设置过关联对象。如果没设置过,释放会更快
    12. uintptr_t has_cxx_dtor : 1; //是否有C++的析构函数
    13. uintptr_t shiftcls : 33; // MACH_VM_MAX_ADDRESS 0x1000000000 内存地址值
    14. uintptr_t magic : 6; //用于在调试时分辨对象是否未完成初始化
    15. uintptr_t weakly_referenced : 1; //是否有被弱引用指向过
    16. uintptr_t deallocating : 1; //是否正在释放
    17. uintptr_t has_sidetable_rc : 1; //引用计数器是否过大无法存储在ISA中。如果为1,那么引用计数会存储在一个叫做SideTable的类的属性中
    18. uintptr_t extra_rc : 19; //里面存储的值是引用计数器减1
    19. # define RC_ONE (1ULL<<45)
    20. # define RC_HALF (1ULL<<18)
    21. };
    22. # elif __x86_64__ // arm86架构,模拟器是arm86
    23. # define ISA_MASK 0x00007ffffffffff8ULL
    24. # define ISA_MAGIC_MASK 0x001f800000000001ULL
    25. # define ISA_MAGIC_VALUE 0x001d800000000001ULL
    26. struct {
    27. uintptr_t nonpointer : 1;
    28. uintptr_t has_assoc : 1;
    29. uintptr_t has_cxx_dtor : 1;
    30. uintptr_t shiftcls : 44; // MACH_VM_MAX_ADDRESS 0x7fffffe00000
    31. uintptr_t magic : 6;
    32. uintptr_t weakly_referenced : 1;
    33. uintptr_t deallocating : 1;
    34. uintptr_t has_sidetable_rc : 1;
    35. uintptr_t extra_rc : 8;
    36. # define RC_ONE (1ULL<<56)
    37. # define RC_HALF (1ULL<<7)
    38. };
    39. # else
    40. # error unknown architecture for packed isa
    41. # endif
    42. }