next up previous
Next: Dynamic Field Offsets Up: Multiple Inheritance Previous: Multiple Inheritance



If the language allows only the instance variables of self to be accessed, multiple inheritance is easily implemented for a class. One of the superclasses is designated as the primary superclass; code is shared only with this class. The primary superclass is handled exactly as described earlier for the superclass. The secondary superclasses are treated essentially as if they were secondary supertypes, except that their fields are appended to the object layout along with the fields of the class.

Since the secondary superclass fields do not begin after the class dispatch vector, the offset to them is different than in the superclass. A new version of secondary superclass methods is compiled or linked to use the correct offset for this class.

Recompilation is easy, and produces compact objects with fast dispatching. However, it does not work if instance variables of objects other than self can be accessed, because the code accessing the variable cannot determine the proper field offset. Also, this solution causes some code duplication, since a class is recompiled for each distinct field offset used.

Andrew C. Myers. Bidirectional Object Layout for Separate Compilation. Proceedings of OOPSLA '95, pp. 124-139.
Copyright © 1995 Association for Computing Machinery