Tuesday September 24, 2013

Modifying The isa Pointer on 64-bit ARM, or, I Didn't Have Enough Headaches This Morning

Greg Parker of Sealie Software explains what Apple is up to with the extra bits of the object isa pointer:

If it’s not a pointer anymore, what is it?

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 reminds me of a conversation I had on Twitter with Graham Lee about what the “_” prefix on ivars means to an Objective-C developer. It doesn’t mean anything to me, other than Apple says we should do it—and so we should. Apple’s been telling us not to modify the isa pointer on objects directy for a long time. If you thought, “Surey, I’m able. This is just C!”, then you’re in for a world of pain on 64-bit ARM.

Apple’s style and usage guidelines may seem capricious, but they are often subtle hints about where the language and platforms are going1. I’m all for being clever, but a long lived iOS or OS X project have much less friction over time if it avoids mucking with unofficial parts of the Objective-C runtime.

I’m looking at you, JSON Kit. :/

  1. For another data point, consider Apple’s strong encouragement toward certain method naming conventions. At the time, they were just conventions. Now, these conventions (like starting a method with the name “new”) have actual runtime meaning to ARC!