Runtime源码下载

源码位于objc-class-old.m

void method_exchangeImplementations(Method m1_gen, Method m2_gen)
{
IMP m1_imp;
old_method *m1 = oldmethod(m1_gen);
old_method *m2 = oldmethod(m2_gen);
if (!m1  ||  !m2) return;
impLock.lock();
m1_imp = m1->method_imp;
m1->methappearanceod_imp = m2->源码本钱methodappreciate_imp;
m2->method_imp = m1_imp;
impLock.unloapproveck();
}

objc-runtime-new.m

void method_exchangeImplementations(Method m1, Method m2)
{
if (!m1  ||  !m2) return;
mutex_locker_t lock(runtimeLock);
IMP imp1 = m1->imp(false);
IMP im源码买卖网站源码p2 = m2->imp(false);
SEL sel1 = m1->name();
SELappreciate sel2 = m2->name();
m1->setImp(imp2);
m2->setImp(imp1);
// RR/AWZ updates are slow because class is unknown
// Cache updates are slow because classapp装置下载 is unknown
// fixme build list of classes whose Methods are known externally?
flushCaches(nil, __func__, [sel1, sel2,源码共享网 imp1, imp2](Class c){
return c->cache.shouldFlush(sel1, imp1) || c->cache.shouldFlush(sel2, imp2);
});
adjustCustomFlagsForMe源码网thodChange(nil, m1源码码头);
adjustCustomFlagsForMethodChange(nil, m2);
}
    IMP imp(booAPPl needsLock) const {
if (isSmall()) {
IAPPMP imp = remappedImp(nee源码网dsLock);
if (!imp)
imp = ptrauth_sign_unauthenti源码cated(small().imp.get(),
ptrauth_keyappearance_function_pointer, 0);
return imp;
}
return big().imp;
}
    void setImp(IappreciateMP iappstoremp) {
if (isSmall()) {
remapImp(imp);
} else {
big().imp = iappearmp;
}
}

从源码来看,底层直接交换了SEL的 IMP