Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Quick lookup process:

  • Class object address, memory translation16 bytes, get the address, getcacheThe first address, namely:_bucketsAndMaybeMask
  • _bucketsAndMaybeMask & bucketsMaskTo obtainbucketsThe first address
  • judge_bucketsAndMaybeMaskthe0Position number0And into theLLookupPreoptProcess to find the shared cache
  • Otherwise, pass_bucketsAndMaybeMask >> 48,mask
  • (_cmd ^ (_cmd >> 7)) & mask, get the subscripti. In the sourcecache_hashfunction
  • throughi * 16Get the offset,The first address of buckets + offset value, gets the specified subscriptbucket
  • Process 1:
    • readbucket_tIn theimpandsel
    • throughBucket_t - 16 bytes, read the previous onebucket
  • Flow 2:
    • ifselExists and is equal to_cmdAnd into theCacheHitCache hitting Process

    – CacheHitProcess: Useimp = imp ^ clsdecoding

    • Jump to the specifiedimpFunction addresses
  • The process of 3:
    • ifselNot present. Enter__objc_msgSend_uncachedprocess
    • On abucketThe address andbucketsFirst address comparison, if> =And into theProcess 1
    • Otherwise,<First address, getmaskThe subscriptbucketAnd into theThe process of 4
  • The process of 4:
    • readbucket_tIn theimpandsel
    • throughBucket_t - 16 bytes, read the previous onebucket
    • ifselIs equal to the_cmdAnd into theFlow 2
    • ifselExists, and the previous onebucketaddress>Specify the subscriptbucketAddress, enterThe process of 4
    • Otherwise, enter__objc_msgSend_uncachedprocess

In the message quick lookup process, if the cache is not hit, enter the MissLabelDynamic process. MissLabelDynamic is the __objc_msgSend_uncached process that was passed in when CacheLookup was called:

  • Core process:__objc_msgSend_uncachedMethodTableLookup_lookUpImpOrForward
  • lookUpImpOrForwardFunction, and is not implemented in assembly code, butC/C++function
  • Assembly and C/C++ intercalls:
    • C/C++The method name is preceded by an underscore when looking in assembly code
    • Call in assemblyC/C++Function,C/C++When looking up in code, remove the first underscore of the method name