美文网首页
runtime-cache

runtime-cache

作者: Berning | 来源:发表于2021-09-07 09:14 被阅读0次
    #if __LP64__
    typedef uint32_t mask_t;  // x86_64 & arm64 asm are less efficient with 16-bits
    #else
    typedef uint16_t mask_t;
    #endif
    

    bucket_t数据结构

    struct bucket_t {
      //sel作为key
        inline SEL sel() const { return _sel.load(memory_order::memory_order_relaxed); }
    
    //imp作为value
        inline IMP imp(Class cls) const {
            uintptr_t imp = _imp.load(memory_order::memory_order_relaxed);
            if (!imp) return nil;
    #if CACHE_IMP_ENCODING == CACHE_IMP_ENCODING_PTRAUTH
            SEL sel = _sel.load(memory_order::memory_order_relaxed);
            return (IMP)
                ptrauth_auth_and_resign((const void *)imp,
                                        ptrauth_key_process_dependent_code,
                                        modifierForSEL(sel, cls),
                                        ptrauth_key_function_pointer, 0);
    #elif CACHE_IMP_ENCODING == CACHE_IMP_ENCODING_ISA_XOR
            return (IMP)(imp ^ (uintptr_t)cls);
    #elif CACHE_IMP_ENCODING == CACHE_IMP_ENCODING_NONE
            return (IMP)imp;
    #else
    #error Unknown method cache IMP encoding.
    #endif
        }
    };
    

    cache_t数据结构

    struct cache_t {
          struct bucket_t *buckets();  //
          mask_t mask();        //数组(buckets)长度 - 1
          mask_t occupied();  //已缓存方法数
    };
    

    相关文章

      网友评论

          本文标题:runtime-cache

          本文链接:https://www.haomeiwen.com/subject/ofjjrktx.html