Full support for C++'s object model, including virtual and repeated inheritance

Exception free (e.g., important for embedded systems)

Extensible mechanism that can cope with dynamic loading and linking

Zero-overhead for orthogonal language features

Example

The following figure shows a part of a realistic hierarchy of image formats:

A host of concrete image formats such as RGB24, JPEG, and planar YUY2 will be represented by further derivations. The
optimal conversion algorithm must be chosen based on a source-target pair of formats.
The following table lists the algorithm that best handle specific source-target pairs.

Now the conversion can be simply defined by using the source and destination formats.

Without open-methods (or multi-methods), the programmer would be required
to use the visitor pattern (double dispatch), pre-processors, or multi-method
library solutions.

The object model

In order to achieve dispatch time that only depends on the number of
virtual arguments, we extended the Itanium object model for C++.
The following graph shows the modifications (grey entries) to the runtime data
structure. The class hierarchy in the example uses repeated
inheritance (D derives from A twice).

Implementation

The C++ open method compiler extends the EDG C++ compiler's lowering pass
that generates C code. In addition, the compiler extracts data on class
hierarchies and open-method declarations from each translation unit and
stores them in separate files. A pre-linker synthesizes this data
from all translation units, checks for dispatch ambiguities, and
generates the dispatch table layout.

Performance Results

In our test setting, we randomly intersect two objects out of a pool
of 20 different classes. This gives 400 possible dispatch combination,
for which we implemented 40 (empty) overriders.

The following table compares the generated code with alternative
implementations in terms of executable size and execution speed.
The results were obtained by compiling the C++/lowered C code
with g++ 4.1 (Linux, Pentium-D) and gcc 4.0.1 (OSX, Core2Duo)
with optimization level set to -O3.
The results for the C++ open method compiler are shown with
yellow background.

Single virtual dispatch measures the performance of a single isolated
virtual function call to one of the 20 objects. The multi-method
(multi-methods have to be declared in class)
and open-method prototype are hand crafted implementations that
approximate automatic lowering of C++ code. We initially developed them
to assess performance trade-offs of different design decisions.