Hacker News new | past | comments | ask | show | jobs | submit login

They stuff the reference count in the unused bits of the 64-bit pointers.



How would that work? The refcount need to be on the pointee, not on the pointer.


It’s stored in the isa pointer inside the object.


thanks, it makes sense now.

For what I understand, the isa pointer is sorta-kinda similar to a vtable pointer in C++.


Yep. It’s actually a pointer to the class instance for the object, which is a full object that contains more information than a typical vtable might, but it serves as a “type ID” that the runtime can use to dispatch on.


So just tagged pointers essentially? That's possible on x86 isn't it (unless it's an endian-thing)?


x86-64 was designed to prevent (or at least discourage) efficient use of tagged pointers, with the higher half/lower half split in the virtual address space. All the excess high-order bits you don't need for actual addressing are required to have the same value, so you effectively only get at most one tag bit.


They’re required to have the same value upon dereference; there is no restrictions prior to this as assembly doesn’t care what a register is. The bits are appropriately masked off when necessary prior to using the pointer.


It is and both both platforms use tagged pointers.


yes, but they have hardware acceleration for that specific tagged pointer type.


Yikes. That's the same shenanigans that got them into trouble with the 68000. Everyone stuffed data into the top 8 bits of pointers because even though the 68000 had 32-bit addressing registers, it only had a 24-bit address bus and the top 8 bits were dontcare's. Then, the 6802x came out with more address lines and...

...and that's basically why x86_64 was specified to require a particular bit pattern in high-order bits - it was to stop applications and OS programmers from writing a bunch of software with tagged pointers which would tie Intel's and AMD's hands when adding address lines. I guess Apple is ok with tying their own hands.


Tagged pointers are an officially accepted thing in ARM -- the relevant feature is called top-byte ignore (TBI). It only applies to the upper 8 bits of a pointer, leaving 56 bits for addressing.


72PB ought to be enough for anyone...


I believe Apple leaves this off.


Today I Learned - thanks!


Eh, the jump from 16-bit addressing to 32-bit was a factor of 65,536. The jump from 32-bit to 64-bit is 4,294,967,296x. Throwing away the top 8 bits drops it to an address space "only" 16,777,216 times bigger than 4GB. It seems like there's some headroom for growth in there.


Doesn't this become less and less of an issue the more bits you add to your pointers? Like with 32 bits, you can't have one memory address per person on the planet earth, at 64 bits, you can have 1 pointer per atom that makes up the planet earth, and at 128 bits we're talking 1 address per atom in the known universe (or something like that, I haven't crunched the numbers exactly, this is more to give a flavor for the order of magnitude we're talking).

So if you cut off the top 8 bytes of a 32bit register and leave yourself with 24 bits, you can't even give a pointer to each person in Tokyo, but you cut off the top 8 bits of a 64 bit pointer you can still give a pointer to each atom of every human being on earth?


The bits Apple uses are not “don’t cares” this time; they’re masked off before the pointer is used.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: