Tuesday, September 24, 2013

iOS on arm64 Has Inline Retain Count in the isa

Greg Parker:

Some of the bits still encode the pointer to the object’s class. But neither OS X nor iOS actually uses all 64 bits of virtual address space. The Objective-C runtime may use these extra bits to store per-object data like its retain count or whether it has been weakly referenced.

This is along the lines of what Marcel Weiher recently suggested except that the class objects are grouped so that the class pointer only needs 30 bits. This leaves 19 bits for the extra retain count, plus more for flags such as whether there are weak references or associated objects.

This should be great for reducing memory use and increasing speed. On the Mac, accessing isa directly has been discouraged for a long time, so hopefully this optimization will eventually show up there as well.

3 Comments RSS · Twitter


> the class objects are grouped so that the class pointer only needs 30 bits

I am not sure this is what I got from his tweet. He says: "iOS 7 currently uses only a 33-bit virtual address space, and the isa spans it all". This seems to imply **all** the pointers fit in 33 bit, not just the class pointers. BUt this seems very limiting, and not much better than 32 bits, so I am not sure what this all means, and if you have more info. Maybe that just means at the moment, all pointers use 33 bit anyway, while in the future they will use more, but the isa pointers will be kept in that range.


@charles Yes, my understanding is that on iOS currently all allocations are grouped into just 33 bits of the address space. So they’re not doing anything special with classes right now. Even if iOS devices eventually have more RAM and thus need more of the address space, Apple should be able to arrange that class objects (at least those created by the system) are grouped. In fact, it seems like it would be possible to fit them into considerably fewer than 30 bits.


@Charles: Don't forget this is purely runtime wizardry. You need more than 33bit address space, just update the runtime library and you are done. No need to recompile the code.

Leave a Comment