vtable layout
Ian Carmichael
iancarm at cygnus.com
Tue Aug 31 20:22:11 UTC 1999
A couple of observations ...
=======
On the state of the art:
The Microsoft approach is worth mentioning. (I haven't seen it
discussed -- though perhaps that is because of the patent situation.)
It allows zero-adjusting (i.e. non-thunking) calls for (almost) every
virtual function call in a non-virtual, multiple inheritance hierarchy.
For those that are unfamiliar, the idea is that all calls go via the
base class vft and overriding functions expect a pointer to the base
class type. (That is, if D::f overrides B::f, it expects the first
parameter to be of type B*, not D*.) The callee does the necessary
static adjustment to get to the derived class 'this' pointer as needed.
It avoids requiring a thunk, and it's often the case that the cost is
zero in the callee because the this-adjustment can be folded into other
offset computations.
On the balance, it could well win over all the other approaches being
discussed here. [Though, it may lose in some specific cases vs.
Christophe's approach where one would create additional extra entries in
the derived class vft.]
=======
On when to make extra virtual function table entries for functions:
One of Cristophe's suggestions is sort-of separate from the rest of the
discussion: making extra entries in the derived class' vft for some
overridden virtual functions. It has the benefit of giving you a faster
calls if you happen to be in (or near) the derived class -- at the
expense of space in the vft.
Of course, you can always make the call through the introducing base
class, so these extra entries are a pure space/time performance trade
off (w/ some unpredictable D-cache effects) and the cost/benefit
analysis will depend a little on what the rest of the strategy looks
like.
The same idea is potentially applicable, no matter what strategy you
actually use for vft layout, and, different criteria for deciding what
extra entries to make are possible. For example, creating an extra
entry when overriding a function introduced in a virtual base has the
added benefit of avoiding a cast to a virtual base at the call site.
--
Ian Carmichael
Cygnus Solutions - Toronto Office
2323 Yonge Street, Suite #502, Toronto, Ontario, M4P 2C9
E-Mail: iancarm at cygnus.com Tel: 416-482-3946 Fax: 416-482-6299
More information about the cxx-abi-dev
mailing list