当前位置:网站首页>isa指针使用详情
isa指针使用详情
2022-08-02 02:23:00 【~废弃回忆 �༄】
isa指针详解
在arm64架构之前,isa就是一个普通的指针,存储着Class、Meta-Class对象的内存地址,从arm64架构开始,对isa进行了优化,变成了一个联合体(union)结构,还使用位域来存储更多的信息。
isa结构如下图:
union isa_t {
isa_t() {
}
isa_t(uintptr_t value) : bits(value) {
}
uintptr_t bits;
private:
// Accessing the class requires custom ptrauth operations, so
// force clients to go through setClass/getClass by making this
// private.
Class cls;
public:
#if defined(ISA_BITFIELD)
struct {
ISA_BITFIELD; // defined in isa.h
};
bool isDeallocating() {
return extra_rc == 0 && has_sidetable_rc == 0;
}
void setDeallocating() {
extra_rc = 0;
has_sidetable_rc = 0;
}
#endif
void setClass(Class cls, objc_object *obj);
Class getClass(bool authenticated);
Class getDecodedClass(bool authenticated);
};
看结构体:
struct {
ISA_BITFIELD; // defined in isa.h
};
这个结构体用宏定义的方式表示,具体定义是根据结构模式和真机模拟器类型划分,详情见 isa.h文件。接下来以arm64为例:
# if __arm64__
// ARM64 simulators have a larger address space, so use the ARM64e
// scheme even when simulators build for ARM64-not-e.
# if __has_feature(ptrauth_calls) || TARGET_OS_SIMULATOR
# define ISA_MASK 0x007ffffffffffff8ULL
# define ISA_MAGIC_MASK 0x0000000000000001ULL
# define ISA_MAGIC_VALUE 0x0000000000000001ULL
# define ISA_HAS_CXX_DTOR_BIT 0
# define ISA_BITFIELD \ uintptr_t nonpointer : 1; \ uintptr_t has_assoc : 1; \ uintptr_t weakly_referenced : 1; \ uintptr_t shiftcls_and_sig : 52; \ uintptr_t has_sidetable_rc : 1; \ uintptr_t extra_rc : 8
# define RC_ONE (1ULL<<56)
# define RC_HALF (1ULL<<7)
- nonpointer:是否是优化过的isa指针
苹果之前所有的结构都是32位的,在32位的时候isa指针只有指向对应类对象/元类对象的功能。而到了64位后,isa指针里面的信息更多,为了适配兼容,这一位用作区分。 - has_assoc:是否存在关联对象
记录对象是否动态添加(使用runtime API),关联对象。如果有则为1,否则为0。在对向释放的时候要检
查这个信息。 - has_cxx_dtor:是否存在c++析构函数
一般有属性的时候就会有析构函数,析构函数是用来释放成员变量的。 - shiftcls :class对象或者meta-class对象地址
存放class对象或者meta-class对象地址,在消息发送(objc_msgSend)的时候去找对应方法时候使用。 - magic:调试信息
用于在调试时分辨对象是否未完成初始化 - weakly_referenced:是否有被弱指针指向
如果有被弱指针指向,会在释放的时候去操作。如果没有则释放得更快 - unused:是否使用过
- has_sidetable_rc:引用计数是否存在sidetable中
如果为1,那么引用计数会存储在一个叫sidetable的类的属性中 - extra_rc:引用计数
如果引用计数大于19位(arm64 & 真机)的最大值(2的19次方-1),则把has_sidetable_rc置位1,把引用计数去存到sidetable中。
边栏推荐
- swift project, sqlcipher3 -> 4, cannot open legacy database is there a way to fix it
- mysql 查看死锁
- Handwriting a blogging platform ~ Day 3
- CodeTon Round 2 D. Magical Array
- How to adjust the cross cursor too small, CAD dream drawing calculation skills
- AWR分析报告问题求助:SQL如何可以从哪几个方面优化?
- AOF rewrite
- BioVendor人俱乐部细胞蛋白(CC16)Elisa试剂盒研究领域
- 菜刀webshell特征分析
- Nanoprobes免疫测定丨FluoroNanogold试剂免疫染色方案
猜你喜欢

Software testing Interface automation testing Pytest framework encapsulates requests library Encapsulates unified request and multiple base path processing Interface association encapsulation Test cas

字符串常用方法

Analysis of the status quo of digital transformation of manufacturing enterprises

永磁同步电机36问(三)——SVPWM代码实现
![[ORB_SLAM2] void Frame::ComputeImageBounds(const cv::Mat & imLeft)](/img/ed/ffced88c9d23c20ccf380494051381.jpg)
[ORB_SLAM2] void Frame::ComputeImageBounds(const cv::Mat & imLeft)

Check if IP or port is blocked

Good News | AR opens a new model for the textile industry, and ALVA Systems wins another award!

The principle and code implementation of intelligent follower robot in the actual combat of innovative projects

Project Background Technology Express

面对职场“毕业”,PM&PMO应该如何从容的应对?如何跳槽能够大幅度升职加薪?
随机推荐
"NetEase Internship" Weekly Diary (3)
BI-SQL丨WHILE
swift项目,sqlcipher3 -&gt; 4,无法打开旧版数据库有办法解决吗
Rasa 3 x learning series - Rasa - 4873 dispatcher Issues. Utter_message study notes
BI - SQL 丨 WHILE
NAS和私有云盘的区别?1篇文章说清楚
工程师如何对待开源
Nanoprobes多组氨酸 (His-) 标签标记:重组蛋白检测方案
2022-08-01 Reflection
"NetEase Internship" Weekly Diary (1)
FOFAHUB使用测试
ALCCIKERS Shane 20191114
项目后台技术Express
A good book for newcomers to the workplace
PHP live source code to achieve simple barrage effect related code
用位运算为你的程序加速
51. 数字排列
nacos startup error, the database has been configured, stand-alone startup
messy website
2022 Henan Youth Training League Game (3)