Daniel Keep wrote:

Jason House wrote:
Dynamic casts are pure. They don't use global state, and have the same output 
for the same reference as input. Interestingly, dynamic cast results are 
independent of intervening mutable calls... So there's even greater opportunity 
for optimization.

What if the GC just happens to re-use that address for a different object?

I don't know about druntime's GC but I used to have this issue with my own GC. I would cast an object to an interface type which would make its only reference point to a different 16bytes block, remember that bit fields in the GC are aligned to 16bytes, and the allocation had therefore no more reachable pointers, or so the GC thought.

What fixed it was to adjust the scan phase and align found pointers to the block size of its corresponding allocation. That way the GC won't reuse the address of reachable objects no matter what interface or subclass they are casted to.

Reply via email to