type
Post
status
Published
date
Nov 3, 2025
slug
summary
tags
安卓
category
心情随笔
icon
password
引言
在分析ART虚拟机的中对象模型时,发现Mirror Object类中引用的其他object指针/对象头的指向Class的指针,都使用了HeapReference来包装,都是HeapReference类型,而
HeapReference类只是对uint32_t类型的值进行包装,在64位系统是8字节的指针,4字节怎么装得下去的,然后发现他对指针进行了压缩:这个类型保存的
reference_ 的是通过PtrCompression 进行的压缩这个32位无符号数,可以通过
Decompress()函数强制转换为Java对象的指针,代码如下:ArtMethod的成员变量declaring_class_是一个uint32_t,这块为什么要用uint32_t的代替,而且后面用reinterpret_cast把这个uint32_转为了一个指针,但是这里面指针的大小不应该是8字节64位的吗 它又是怎么转的?
不会, 它只要保证ObjectReference引用的东西在4gb空间内就行, 其它的不受影响.
参考http://androidxref.com/7.1.1_r6/xref/art/runtime/runtime.h#728
Special low 4gb pool for compiler linear alloc. We need ArtFields to be in low 4gb if we are compiling using a 32 bit image on a 64 bit compiler in case we resolve things in the image since the field arrays are int arrays in this case.
参考文章
- https://juejin.cn/post/7270871863160733752
- https://www.pqpo.me/2017/07/07/hotfix-method-hook/#comment-265
