Closed guoyiteng closed 5 years ago
This isn't a perfect fix, since we don't actually know how far away the FieldObj pointer and the static field pointer will be from each other in memory. However, its a reasonable hotfix and can't make anything MORE broken.
Previously we used the absolute address to access field offset. However, the address was larger than 32bit and the method sun.misc.Unsafe.fieldOffset(field) truncated it to 32 bit. When a static variable had address larger than 32 bit, it would lead to a segfault.
Now, we use the relative address instead, and the base pointer is the fieldObj. We compute the offset in
Java_sun_misc_Unsafe_objectFieldOffset
and returnfieldObj
inJava_sun_misc_Unsafe_staticFieldBase
. We make an assumption that the static variable is within 32bit range of the fieldObj. It should be safe since fieldObj is allocated on the heap and static variable is on the .bss section.