cache_t流程分析图
2021-06-30 01:01:51 0 举报
iOS 类的结构之cache_t流程分析图
作者其他创作
大纲/内容
b[i].sel() == sel,需要插入的sel是否已经缓存了
cache_t::reallocate:开辟新的缓存区,设置buckets和mask,释放旧的缓存区(非第一次),第一次开辟存储容量arm64为2个,非arm64为4个
log_and_fill_cache
cache_fill_ratio(capacity)当前缓存量未超过3/4或7/8(arm64),无需扩容
cache_t
__objc_msgSend_uncached
arm64
do{} while()循环,判断是否能插入,不能就再哈希,直到把所有位置遍历一遍
YES
非arm64,正常存储bucket和mask
NO
Atomic
bucket_t
explicit_atomic<SEL> _sel;explicit_atomic<uintptr_t> _imp;
NotAtomic
cache_t::allocateBuckets:开辟新的缓存区,CACHE_END_MARKER = 1(非arm64)设置endMarker
非arm64
lookUpImpOrForward
cache_t::collect_free:回收清空就的缓存区
CONFIG_USE_PREOPT_CACHES = 1
CACHE_MASK_STORAGE_HIGH_16(真机)arm64 && iOS && !simulator
uintptr_t maskShift = 48;uintptr_t maskZeroBits = 4;uintptr_t maxMask = ((uintptr_t)1 << (64 - maskShift)) - 1;uintptr_t bucketsMask = ((uintptr_t)1 << (maskShift - maskZeroBits)) - 1;uintptr_t preoptBucketsMarker = 1ul;uintptr_t preoptBucketsMask;uintptr_t preoptBucketsHashParams(const preopt_cache_t *cache);preopt_cache_t *preopt_cache();Class preoptFallbackClass();void maybeConvertToPreoptimized();
_bucketsAndMaybeMask解读:为了节省内存,buckets和mask存在一起,maybeMask没使用,低48位为bucket_t指针,高16位为mask
CACHE_MASK_STORAGE_HIGH_16_BIG_ADDRS(M1版iMac)arm64
uintptr_t maskShift = 48;uintptr_t maxMask = ((uintptr_t)1 << (64 - maskShift)) - 1;uintptr_t bucketsMask = ((uintptr_t)1 << maskShift) - 1;
isConstantEmptyCache,表示第一次插入缓存
公用部分
font color=\"#ff0000\
b[i].sel() == 0,想要插入的位置是否为空
CACHE_MASK_STORAGE_OUTLINED非M1版iMac
uintptr_t bucketsMask = ~0ul;
CACHE_MASK_STORAGE
i != begin,重新进入循环
i == begin
直接return
atomicity
capacity = capacity ? capacity * 2 : INIT_CACHE_SIZE,当前缓存空间不足,两倍扩容
CACHE_MASK_STORAGE_LOW_4
uintptr_t maskBits = 4;uintptr_t maskMask = (1 << maskBits) - 1;uintptr_t bucketsMask = ~maskMask;
@温暖
cache.insert
cache_t结构分析流程图
objc_class
Class ISA;Class superclass;cache_t cache;class_data_bits_t bits;
incrementOccupied(),对占用计数++;
cache_t::bad_cache,遍历了一遍,没有地方可以插入,跳出循环,错误处理
cache_t::setBucketsAndMask:根据不同的架构策略设置buckets和mask(Capacity - 1)
explicit_atomic<uintptr_t> _imp;explicit_atomic<SEL> _sel;
0 条评论
下一页