OC对象的本质7--- struct object_class的

2020-04-09  本文已影响0人  大鹅ne

基础结构体

struct bucket_t {
    cache_key_t _key;
    IMP _imp;
};

struct cache_t {
    bucket_t *_buckets;
    mask_t _mask;
    mask_t _occupied;
};

/* OC对象 */
struct objc_object {
    void *isa;  
};

struct entsize_list_tt {
    uint32_t entsizeAndFlags;
    uint32_t count;
};

struct method_t {
    SEL name;
    const char *types;
    IMP imp;
};

object_class结构


/* 类对象 */
struct objc_class : objc_object {
    Class superclass;
    cache_t cache;//方法的缓存
    class_data_bits_t bits;//用于获取具体的类信息  ➡️➡️➡️🍎class_data_bits_t
public:
    class_rw_t* data() {
        return bits.data();
    }
    
    mj_objc_class* metaClass() {
        return (mj_objc_class *)((long long)isa & ISA_MASK);
    }
};

#define FAST_DATA_MASK          0x00007ffffffffff8UL
struct class_data_bits_t {//🍎
    uintptr_t bits;
public:
    class_rw_t* data() {
        return (class_rw_t *)(bits & FAST_DATA_MASK);//  ➡️➡️➡️🍐class_rw_t
    }
};


struct class_rw_t {//🍐
    uint32_t flags;
    uint32_t version;
    const class_ro_t *ro;// ➡️➡️➡️🍌 class_ro_t
    method_list_t * methods;    // 方法列表   ➡️➡️➡️🥝 method_list_t
    property_list_t *properties;    // 属性列表➡️➡️➡️🍒 property_list_t
    const protocol_list_t * protocols;  // 协议列表➡️➡️➡️🍇 protocol_list_t
    Class firstSubclass;
    Class nextSiblingClass;
    char *demangledName;
};

struct class_ro_t {//🍌
    uint32_t flags;
    uint32_t instanceStart;
    uint32_t instanceSize;  // instance对象占用的内存空间
#ifdef __LP64__
    uint32_t reserved;
#endif
    const uint8_t * ivarLayout;
    const char * name;  // 类名
    method_list_t * baseMethodList;
    protocol_list_t * baseProtocols;
    const ivar_list_t * ivars;  // 成员变量列表➡️➡️➡️🍓 ivar_list_t
    const uint8_t * weakIvarLayout;
    property_list_t *baseProperties;
};


struct method_list_t : entsize_list_tt {//🥝
    method_t first;
};
struct property_list_t : entsize_list_tt {//🍒
    property_t first;
};
struct protocol_list_t {//🍇
    uintptr_t count;
    protocol_ref_t list[0];
};
struct ivar_list_t : entsize_list_tt {//🍓
    ivar_t first;//➡️➡️➡️🍍ivar_t
};
struct ivar_t {//🍍
    int32_t *offset;
    const char *name;
    const char *type;
    uint32_t alignment_raw;
    uint32_t size;
};



上一篇下一篇

猜你喜欢

热点阅读